17template<
typename Base,
typename ... Components>
21 : term_index_(term_index)
51 "query_builder::expr() called more than once");
69 _::type_to_inout<T>());
81 Base&
with(
const char *component_name) {
116 template<
typename First>
122 template<
typename First>
128 template<
typename First,
typename Second>
134 template <typename E, if_t< is_enum<E>::value > = 0>
137 auto o = enum_type<E>(this->world_v()).entity(value);
138 return this->
with(r, o);
162 template <
typename ... Args>
164 return this->
with(FLECS_FWD(args)...).not_();
168 template <
typename T,
typename ... Args>
170 return this->with<T>(FLECS_FWD(args)...).not_();
174 template <
typename First,
typename Second>
176 return this->with<First, Second>().not_();
191 template <
typename ... Args>
193 return this->
with(FLECS_FWD(args)...).write();
197 template <
typename T,
typename ... Args>
199 return this->with<T>(FLECS_FWD(args)...).write();
203 template <
typename First,
typename Second>
205 return this->with<First, Second>().write();
215 template <
typename ... Args>
217 return this->
with(FLECS_FWD(args)...).read();
221 template <
typename T,
typename ... Args>
223 return this->with<T>(FLECS_FWD(args)...).read();
227 template <
typename First,
typename Second>
229 return this->with<First, Second>().read();
236 return this->
with(flecs::ScopeOpen).entity(0);
241 return this->
with(flecs::ScopeClose).entity(0);
249 "query_builder::term() called without initializing term");
267 template <
typename T>
270 for (
int i = 0; i < term_index_; i ++) {
275 if ((term_id == cur_term_id || (cur_term_id != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_id))) ||
276 (term_id == cur_term_pair || (cur_term_pair != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_pair)))) {
288 int32_t prev_index = term_index_;
289 term_index_ = term_index;
291 term_index_ = prev_index;
299 template <
typename T>
302#if !defined(FLECS_NDEBUG) || defined(FLECS_KEEP_ASSERT)
308 ecs_assert((term_id == cur_term_id || (cur_term_id != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_id))) ||
309 (term_id == cur_term_pair || (cur_term_pair != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_pair))),
333 template <
typename T>
368 template <
typename T>
391 template <
typename T>
402 return this->
group_by(component,
nullptr);
435 return *
static_cast<Base*
>(
this);
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INVALID_OPERATION
Invalid operation error code.
#define ecs_err(...)
Error macro.
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
#define ecs_check(condition, error_code,...)
Check.
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
ecs_table_t table_t
Table type.
ecs_entity_t entity_t
Entity type.
query_cache_kind_t
Query cache kind.
ecs_world_t world_t
World type.
@ QueryCacheAuto
Auto query cache.
uint64_t(* ecs_group_by_action_t)(ecs_world_t *world, ecs_table_t *table, ecs_id_t group_id, void *ctx)
Callback used for grouping tables in a query.
void(* ecs_group_delete_action_t)(ecs_world_t *world, uint64_t group_id, void *group_ctx, void *group_by_ctx)
Callback invoked when a query deletes an existing group.
void *(* ecs_group_create_action_t)(ecs_world_t *world, uint64_t group_id, void *group_by_ctx)
Callback invoked when a query creates a new group.
void(* ecs_ctx_free_t)(void *ctx)
Function to clean up context data.
int(* ecs_order_by_action_t)(ecs_entity_t e1, const void *ptr1, ecs_entity_t e2, const void *ptr2)
Callback used for comparing components.
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t component)
Get the type for a component.
#define FLECS_TERM_COUNT_MAX
Maximum number of terms in queries.
#define EcsQueryDetectChanges
Enable change detection for a query.
bool ecs_term_is_initialized(const ecs_term_t *term)
Test whether a term is set.
ecs_query_cache_kind_t
Specify cache policy for query.
ecs_inout_kind_t
Specify read/write access for term.
Used with ecs_query_init().
ecs_id_t group_by
Component ID to be used for grouping.
ecs_term_t terms[32]
Query terms.
ecs_ctx_free_t group_by_ctx_free
Function to free group_by_ctx.
void * group_by_ctx
Context to pass to group_by.
ecs_entity_t order_by
Component to sort on, used together with order_by_callback or order_by_table_callback.
ecs_order_by_action_t order_by_callback
Callback used for ordering query results.
ecs_group_create_action_t on_group_create
Callback that is invoked when a new group is created.
ecs_group_by_action_t group_by_callback
Callback used for grouping results.
ecs_group_delete_action_t on_group_delete
Callback that is invoked when an existing group is deleted.
ecs_flags32_t flags
Flags for enabling query features.
ecs_query_cache_kind_t cache_kind
Caching policy of the query.
const char * expr
Query DSL expression (optional).
ecs_entity_t id
Entity ID.
Type that describes a term (single element in a query).
ecs_id_t id
Component ID to be matched by term.
ecs_term_ref_t second
Second element of pair.
int16_t inout
Access to contents matched by term.
ecs_term_ref_t first
Component or first element of pair.
Base & with(id_t component_id)
Add a term for the specified component ID.
Base & with(E value)
Add a term for an enum value.
Base & term_at(int32_t term_index)
Set the current term to the one at the provided index and assert that the type matches.
Base & group_by()
Group and sort matched tables.
Base & scope_close()
Close a query scope.
Base & on_group_delete(ecs_group_delete_action_t action)
Specify the on_group_delete() action.
Base & write()
Short for inout_stage(flecs::Out).
Base & write(Args &&... args)
Add a write term for the specified type.
Base & scope_open()
Open a query scope.
Base & read(Args &&... args)
Add a read term for the specified type.
Base & read()
Add a read term for a pair of types.
Base & without()
Add a negated term for a pair of types.
Base & with(flecs::term &&term)
Add a term from an existing term (move).
Base & group_by(flecs::entity_t component, uint64_t(*group_by_action)(flecs::world_t *, flecs::table_t *table, flecs::id_t id, void *ctx))
Group and sort matched tables.
Base & cache_kind(query_cache_kind_t kind)
Set the cache kind for the query.
Base & with()
Add a term for the specified type.
Base & expr(const char *expr)
Set the query expression string.
Base & on_group_create(ecs_group_create_action_t action)
Specify the on_group_create() action.
Base & detect_changes()
Enable change detection for the query.
Base & with(const char *first, const char *second)
Add a term for a pair specified by name.
Base & with()
Add a term for a pair with types First and Second.
Base & write()
Add a write term for a pair of types.
Base & with(const char *component_name)
Add a term for the specified component name.
Base & query_flags(ecs_flags32_t flags)
Set the query flags.
Base & group_by(flecs::entity_t component)
Group and sort matched tables.
Base & read(Args &&... args)
Add a read term with the specified arguments.
Base & group_by(uint64_t(*group_by_action)(flecs::world_t *, flecs::table_t *table, flecs::id_t id, void *ctx))
Group and sort matched tables.
Base & term_at(int32_t term_index)
Set the current term to the one at the provided index.
Base & term()
Set the current term to the next one in the term list.
Base & with(entity_t first, entity_t second)
Add a term for a pair specified by entity IDs.
Base & write(Args &&... args)
Add a write term with the specified arguments.
Base & with(entity_t second)
Add a term for a pair with type First and an entity ID second.
Base & without(Args &&... args)
Add a negated term.
Base & without(Args &&... args)
Add a negated term for the specified type.
Base & read()
Short for inout_stage(flecs::In).
Base & with(entity_t first, const char *second)
Add a term for a pair with an entity ID first and a name second.
Base & order_by(int(*compare)(flecs::entity_t, const T *, flecs::entity_t, const T *))
Sort the output of a query.
Base & group_by_ctx(void *ctx, ecs_ctx_free_t ctx_free=nullptr)
Specify context to be passed to the group_by() function.
query_builder_i(ecs_query_desc_t *desc, int32_t term_index=0)
Construct from a query descriptor.
Base & cached()
Enable auto-caching for the query.
Base & with(const char *second)
Add a term for a pair with type First and name second.
Base & term_at()
Set the current term to the one with the provided type.
Base & with(flecs::term &term)
Add a term from an existing term reference.
Base & order_by(flecs::entity_t component, int(*compare)(flecs::entity_t, const void *, flecs::entity_t, const void *))
Sort the output of a query.
Base & with(const char *first, entity_t second)
Add a term for a pair with a name first and an entity ID second.
void set_term(ecs_term_t *term)
Set the current term pointer.
Base & desc()
Use with cascade() to iterate results in descending (bottom-to-top) order.
ecs_term_t * term_
Pointer to the current term.
Base & second()
Call prior to setting values for the second identifier.
Base & read()
Short for inout_stage(flecs::In).
Base & write()
Short for inout_stage(flecs::Out).
Base & first()
Call prior to setting values for the first identifier.
Base & flags(flecs::flags64_t flags)
Override the term ID flags.
Class that describes a term.