17template<
typename Base,
typename ... Components>
20 : term_index_(term_index)
24 Base& query_flags(ecs_flags32_t flags) {
25 desc_->
flags |= flags;
29 Base& cache_kind(query_cache_kind_t kind) {
35 return cache_kind(flecs::QueryCacheAuto);
38 Base& expr(
const char *expr) {
39 ecs_check(expr_count_ == 0, ECS_INVALID_OPERATION,
40 "query_builder::expr() called more than once");
55 _::type_to_inout<T>());
71 Base& with(
const char *name) {
80 Base& with(
const char *first,
const char *second) {
82 *this->term_ =
flecs::term().first(first).second(second);
89 Base& with(entity_t r, entity_t o) {
98 Base& with(entity_t r,
const char *o) {
107 Base& with(
const char *r, entity_t o) {
116 template<
typename First>
121 template<
typename First>
122 Base& with(
const char *second) {
126 template<
typename First,
typename Second>
131 template <typename E, if_t< is_enum<E>::value > = 0>
132 Base& with(E value) {
134 auto o = enum_type<E>(this->world_v()).entity(value);
135 return this->with(r, o);
152 template <
typename ... Args>
153 Base& without(Args&&... args) {
154 return this->with(FLECS_FWD(args)...).not_();
157 template <
typename T,
typename ... Args>
158 Base& without(Args&&... args) {
159 return this->with<T>(FLECS_FWD(args)...).not_();
162 template <
typename First,
typename Second>
164 return this->with<First, Second>().not_();
174 template <
typename ... Args>
175 Base& write(Args&&... args) {
176 return this->with(FLECS_FWD(args)...).write();
179 template <
typename T,
typename ... Args>
180 Base& write(Args&&... args) {
181 return this->with<T>(FLECS_FWD(args)...).write();
184 template <
typename First,
typename Second>
186 return this->with<First, Second>().write();
194 template <
typename ... Args>
195 Base& read(Args&&... args) {
196 return this->with(FLECS_FWD(args)...).read();
199 template <
typename T,
typename ... Args>
200 Base& read(Args&&... args) {
201 return this->with<T>(FLECS_FWD(args)...).read();
204 template <
typename First,
typename Second>
206 return this->with<First, Second>().read();
211 return this->with(flecs::ScopeOpen).entity(0);
214 Base& scope_close() {
215 return this->with(flecs::ScopeClose).entity(0);
223 ECS_INVALID_OPERATION,
224 "query_builder::term() called without initializing term");
228 ECS_INVALID_PARAMETER,
"maximum number of terms exceeded");
230 this->set_term(&desc_->
terms[term_index_]);
238 Base& term_at(int32_t term_index) {
239 ecs_assert(term_index >= 0, ECS_INVALID_PARAMETER, NULL);
240 int32_t prev_index = term_index_;
241 term_index_ = term_index;
243 term_index_ = prev_index;
245 ECS_INVALID_PARAMETER, NULL);
267 template <
typename T>
268 Base&
order_by(
int(*compare)(flecs::entity_t,
const T*, flecs::entity_t,
const T*)) {
279 Base&
order_by(flecs::entity_t
component,
int(*compare)(flecs::entity_t,
const void*, flecs::entity_t,
const void*)) {
302 template <
typename T>
303 Base&
group_by(uint64_t(*group_by_action)(flecs::world_t*, flecs::table_t *
table, flecs::id_t
id,
void* ctx)) {
314 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)) {
325 template <
typename T>
336 return this->
group_by(component,
nullptr);
365 virtual flecs::world_t* world_v()
override = 0;
371 return *
static_cast<Base*
>(
this);
#define ecs_assert(condition, error_code,...)
Assert.
#define ecs_check(condition, error_code,...)
Check.
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 cleanup 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.
#define FLECS_TERM_COUNT_MAX
Maximum number of terms in queries.
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.
@ EcsInOutDefault
InOut for regular terms, In for shared terms.
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 query.
const char * expr
Query DSL expression (optional)
int16_t inout
Access to contents matched by term.
Base & group_by()
Group and sort matched tables.
Base & on_group_delete(ecs_group_delete_action_t action)
Specify on_group_delete action.
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 & on_group_create(ecs_group_create_action_t action)
Specify on_group_create action.
Base & group_by(flecs::entity_t component)
Group and sort matched tables.
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 & 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 group_by function.
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 & read()
Short for inout_stage(flecs::In).
Base & inout_none()
Short for inout(flecs::In)
Base & write()
Short for inout_stage(flecs::Out).
Class that describes a term.