Skip to content

Commit

Permalink
Fix incorrect return type of flecs::iter::id
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 15, 2023
1 parent b685d16 commit 7f9d203
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
6 changes: 3 additions & 3 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21336,7 +21336,7 @@ struct iter {
*
* @param index The field index.
*/
flecs::entity id(int32_t index) const;
flecs::id id(int32_t index) const;

/** Obtain pair id matched for field.
* This operation will fail if the id is not a pair.
Expand Down Expand Up @@ -30221,8 +30221,8 @@ inline flecs::entity iter::src(int32_t index) const {
return flecs::entity(m_iter->world, ecs_field_src(m_iter, index));
}

inline flecs::entity iter::id(int32_t index) const {
return flecs::entity(m_iter->world, ecs_field_id(m_iter, index));
inline flecs::id iter::id(int32_t index) const {
return flecs::id(m_iter->world, ecs_field_id(m_iter, index));
}

inline flecs::id iter::pair(int32_t index) const {
Expand Down
4 changes: 2 additions & 2 deletions include/flecs/addons/cpp/impl/iter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ inline flecs::entity iter::src(int32_t index) const {
return flecs::entity(m_iter->world, ecs_field_src(m_iter, index));
}

inline flecs::entity iter::id(int32_t index) const {
return flecs::entity(m_iter->world, ecs_field_id(m_iter, index));
inline flecs::id iter::id(int32_t index) const {
return flecs::id(m_iter->world, ecs_field_id(m_iter, index));
}

inline flecs::id iter::pair(int32_t index) const {
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/addons/cpp/iter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ struct iter {
*
* @param index The field index.
*/
flecs::entity id(int32_t index) const;
flecs::id id(int32_t index) const;

/** Obtain pair id matched for field.
* This operation will fail if the id is not a pair.
Expand Down
3 changes: 2 additions & 1 deletion test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@
"captured_query",
"page_iter_captured_query",
"worker_iter_captured_query",
"iter_entities"
"iter_entities",
"iter_get_pair_w_id"
]
}, {
"id": "QueryBuilder",
Expand Down
24 changes: 24 additions & 0 deletions test/cpp_api/src/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,3 +2247,27 @@ void Query_iter_entities(void) {
test_assert(entities[2] == e3);
});
}

void Query_iter_get_pair_w_id(void) {
flecs::world ecs;

flecs::entity Rel = ecs.entity();
flecs::entity Tgt = ecs.entity();
flecs::entity e = ecs.entity().add(Rel, Tgt);

flecs::query<> q = ecs.query_builder()
.with(Rel, flecs::Wildcard)
.build();

int32_t count = 0;

q.each([&](flecs::iter& it, size_t i) {
test_bool(true, it.id(1).is_pair());
test_assert(it.id(1).first() == Rel);
test_assert(it.id(1).second() == Tgt);
test_assert(e == it.entity(i));
count ++;
});

test_int(count, 1);
}
7 changes: 6 additions & 1 deletion test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ void Query_captured_query(void);
void Query_page_iter_captured_query(void);
void Query_worker_iter_captured_query(void);
void Query_iter_entities(void);
void Query_iter_get_pair_w_id(void);

// Testsuite 'QueryBuilder'
void QueryBuilder_builder_assign_same_type(void);
Expand Down Expand Up @@ -3455,6 +3456,10 @@ bake_test_case Query_testcases[] = {
{
"iter_entities",
Query_iter_entities
},
{
"iter_get_pair_w_id",
Query_iter_get_pair_w_id
}
};

Expand Down Expand Up @@ -6272,7 +6277,7 @@ static bake_test_suite suites[] = {
"Query",
NULL,
NULL,
79,
80,
Query_testcases
},
{
Expand Down

0 comments on commit 7f9d203

Please sign in to comment.