17template<
typename Base,
typename ... Components>
20 : term_index_(term_index)
29 Base& query_flags(ecs_flags32_t flags) {
30 desc_->
flags |= flags;
34 Base& cache_kind(query_cache_kind_t kind) {
40 return cache_kind(flecs::QueryCacheAuto);
43 Base& expr(
const char *expr) {
44 ecs_check(expr_count_ == 0, ECS_INVALID_OPERATION,
45 "query_builder::expr() called more than once");
60 _::type_to_inout<T>());
76 Base& with(
const char *name) {
85 Base& with(
const char *first,
const char *second) {
87 *this->term_ =
flecs::term().first(first).second(second);
94 Base& with(entity_t r, entity_t o) {
103 Base& with(entity_t r,
const char *o) {
112 template<
typename First>
117 template<
typename First>
118 Base& with(
const char *second) {
122 template<
typename First,
typename Second>
127 template <typename E, if_t< is_enum<E>::value > = 0>
128 Base& with(E value) {
130 auto o = enum_type<E>(this->world_v()).entity(value);
131 return this->with(r, o);
148 template <
typename ... Args>
149 Base& without(Args&&... args) {
150 return this->with(FLECS_FWD(args)...).not_();
153 template <
typename T,
typename ... Args>
154 Base& without(Args&&... args) {
155 return this->with<T>(FLECS_FWD(args)...).not_();
158 template <
typename First,
typename Second>
160 return this->with<First, Second>().not_();
170 template <
typename ... Args>
171 Base& write(Args&&... args) {
172 return this->with(FLECS_FWD(args)...).write();
175 template <
typename T,
typename ... Args>
176 Base& write(Args&&... args) {
177 return this->with<T>(FLECS_FWD(args)...).write();
180 template <
typename First,
typename Second>
182 return this->with<First, Second>().write();
190 template <
typename ... Args>
191 Base& read(Args&&... args) {
192 return this->with(FLECS_FWD(args)...).read();
195 template <
typename T,
typename ... Args>
196 Base& read(Args&&... args) {
197 return this->with<T>(FLECS_FWD(args)...).read();
200 template <
typename First,
typename Second>
202 return this->with<First, Second>().read();
207 return this->with(flecs::ScopeOpen).entity(0);
210 Base& scope_close() {
211 return this->with(flecs::ScopeClose).entity(0);
219 ECS_INVALID_OPERATION,
220 "query_builder::term() called without initializing term");
224 ECS_INVALID_PARAMETER,
"maximum number of terms exceeded");
226 this->set_term(&desc_->
terms[term_index_]);
234 Base& term_at(int32_t term_index) {
235 ecs_assert(term_index >= 0, ECS_INVALID_PARAMETER, NULL);
236 int32_t prev_index = term_index_;
237 term_index_ = term_index;
239 term_index_ = prev_index;
241 ECS_INVALID_PARAMETER, NULL);
263 template <
typename T>
264 Base&
order_by(
int(*compare)(flecs::entity_t,
const T*, flecs::entity_t,
const T*)) {
275 Base&
order_by(flecs::entity_t
component,
int(*compare)(flecs::entity_t,
const void*, flecs::entity_t,
const void*)) {
298 template <
typename T>
299 Base&
group_by(uint64_t(*group_by_action)(flecs::world_t*, flecs::table_t *
table, flecs::id_t
id,
void* ctx)) {
310 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)) {
321 template <
typename T>
332 return this->
group_by(component,
nullptr);
361 virtual flecs::world_t* world_v()
override = 0;
367 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.
#define EcsQueryIsInstanced
Query iteration is always instanced.
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.