17template<
typename Base,
typename ... Components>
21 : term_index_(term_index)
27 desc_->flags |=
flags;
51 "query_builder::expr() called more than once");
61 return with(
_::type<T>::id(this->world_v())).inout(_::type_to_inout<T>());
64 template <
typename First,
typename Second>
66 return with(_::type<First>::id(this->world_v()), _::type<Second>::id(this->world_v()));
69 template <
typename First,
typename Second>
70 Base& with(Second second) {
71 return with(_::type<First>::id(this->world_v()), second);
74 template <
typename Arg>
75 Base& with(Arg&& arg) {
76 using T = decay_t<Arg>;
77 if constexpr (is_enum_v<T>) {
78 return with(_::type<T>::id(this->world_v()), _::entity_id(this->world_v(), arg));
81 if constexpr (std::is_same_v<T, flecs::term>) {
83 }
else if constexpr (std::is_convertible_v<T, const char*>) {
92 template <
typename First,
typename Second>
93 Base& with(First first, Second second) {
99 template <
typename... T,
typename... Args>
100 Base& without(Args&&... args) {
101 return this->
template with<T...>(FLECS_FWD(args)...).
not_();
108 template <
typename... T,
typename... Args>
109 Base& write(Args&&... args) {
110 return this->
template with<T...>(FLECS_FWD(args)...).write();
117 template <
typename... T,
typename... Args>
118 Base& read(Args&&... args) {
119 return this->
template with<T...>(FLECS_FWD(args)...).read();
124 return this->with(flecs::ScopeOpen).entity(0);
129 return this->with(flecs::ScopeClose).entity(0);
137 "query_builder::term() called without initializing term");
143 this->
set_term(&desc_->terms[term_index_]);
155 template <
typename T>
158 for (
int i = 0; i < term_index_; i ++) {
163 if ((term_id == cur_term_id || (cur_term_id != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_id))) ||
164 (term_id == cur_term_pair || (cur_term_pair != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_pair)))) {
176 int32_t prev_index = term_index_;
177 term_index_ = term_index;
179 term_index_ = prev_index;
187 template <
typename T>
190#if !defined(FLECS_NDEBUG) || defined(FLECS_KEEP_ASSERT)
196 ecs_assert((term_id == cur_term_id || (cur_term_id != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_id))) ||
197 (term_id == cur_term_pair || (cur_term_pair != 0 && term_id ==
ecs_get_typeid(this->world_v(), cur_term_pair))),
221 template <
typename T>
256 template <
typename T>
279 template <
typename T>
299 desc_->group_by_ctx = ctx;
300 desc_->group_by_ctx_free = ctx_free;
306 desc_->on_group_create = action;
312 desc_->on_group_delete = action;
323 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.
void(*) ecs_ctx_free_t(void *ctx)
Function to clean up context data.
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.
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.
Used with ecs_query_init().
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.
ecs_term_ref_t first
Component or first element of pair.
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 & scope_open()
Open a query scope.
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 & 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 & query_flags(ecs_flags32_t flags)
Set the query flags.
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 & 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 & 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 & term_at()
Set the current term to the one with the provided type.
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.
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 & read()
Short for inout_stage(flecs::In).
term_builder_i()
Default constructor.
Base & not_()
Short for oper(flecs::Not).
Base & write()
Short for inout_stage(flecs::Out).
Base & flags(flecs::flags64_t flags)
Override the term ID flags.
flecs::term term(Args &&... args) const
Create a term.