Skip to content

Commit

Permalink
Correct test cases, cleanup each_term implementations for queries/rules
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 15, 2023
1 parent 49478e7 commit ca73ed2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
14 changes: 6 additions & 8 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27996,14 +27996,7 @@ struct query_base {

template <typename Func>
void each_term(const Func& func) const {
const ecs_filter_t *f = ecs_query_get_filter(m_query);
ecs_assert(f != NULL, ECS_INVALID_PARAMETER, NULL);

for (int i = 0; i < f->term_count; i ++) {
flecs::term t(m_world, f->terms[i]);
func(t);
t.reset(); // prevent freeing resources
}
this->filter().each_term(func);
}

filter_base filter() const {
Expand Down Expand Up @@ -29341,6 +29334,11 @@ struct rule_base {
}
}

template <typename Func>
void each_term(const Func& func) const {
this->filter().each_term(func);
}

/** Move the rule. */
void move(flecs::rule_base&& obj) {
this->destruct();
Expand Down
9 changes: 1 addition & 8 deletions include/flecs/addons/cpp/mixins/query/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ struct query_base {

template <typename Func>
void each_term(const Func& func) const {
const ecs_filter_t *f = ecs_query_get_filter(m_query);
ecs_assert(f != NULL, ECS_INVALID_PARAMETER, NULL);

for (int i = 0; i < f->term_count; i ++) {
flecs::term t(m_world, f->terms[i]);
func(t);
t.reset(); // prevent freeing resources
}
this->filter().each_term(func);
}

filter_base filter() const {
Expand Down
5 changes: 5 additions & 0 deletions include/flecs/addons/cpp/mixins/rule/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ struct rule_base {
}
}

template <typename Func>
void each_term(const Func& func) const {
this->filter().each_term(func);
}

/** Move the rule. */
void move(flecs::rule_base&& obj) {
this->destruct();
Expand Down
2 changes: 1 addition & 1 deletion test/cpp_api/src/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ void Query_inspect_terms_w_each(void) {
void Query_inspect_terms_w_expr(void) {
flecs::world ecs;

flecs::filter<> f = ecs.filter_builder()
flecs::query<> f = ecs.query_builder()
.expr("(ChildOf,0)")
.build();

Expand Down
4 changes: 3 additions & 1 deletion test/cpp_api/src/RuleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ void RuleBuilder_iter_w_stage(void) {
void RuleBuilder_inspect_terms_w_expr(void) {
flecs::world ecs;

flecs::filter<> f = ecs.filter_builder()
flecs::rule<> f = ecs.rule_builder()
.expr("(ChildOf,0)")
.build();

Expand All @@ -812,4 +812,6 @@ void RuleBuilder_inspect_terms_w_expr(void) {
});

test_int(count, 1);

f.destruct();
}

0 comments on commit ca73ed2

Please sign in to comment.