16 query_base(query_t *q)
21 query_base(
const query_t *q)
22 : query_(ECS_CONST_CAST(query_t*, q)) {
28 const flecs::Poly *query_poly = ecs_get_pair(
31 query_ =
static_cast<flecs::query_t*
>(query_poly->
poly);
32 flecs_poly_claim(query_);
40 query_base(
const query_base& obj) {
41 this->query_ = obj.query_;
42 flecs_poly_claim(this->query_);
45 query_base& operator=(
const query_base& obj) {
46 this->query_ = obj.query_;
47 flecs_poly_claim(this->query_);
51 query_base(query_base&& obj)
noexcept {
52 this->query_ = obj.query_;
56 query_base& operator=(query_base&& obj)
noexcept {
57 this->query_ = obj.query_;
66 const flecs::query_t* c_ptr()
const {
70 operator const flecs::query_t*()
const {
74 operator bool()
const {
75 return query_ !=
nullptr;
84 ecs_assert(query_->entity != 0, ECS_INVALID_OPERATION,
"destruct() "
85 "should only be called on queries associated with entities");
95 if (query_ && !query_->
entity) {
96 if (!flecs_poly_release(query_)) {
121 const flecs::query_group_info_t*
group_info(uint64_t group_id)
const {
131 const flecs::query_group_info_t *gi =
group_info(group_id);
139 template <
typename Func>
140 void each_term(
const Func& func) {
141 for (
int i = 0; i < query_->
term_count; i ++) {
149 return flecs::term(query_->world, query_->terms[index]);
152 int32_t term_count() {
153 return query_->term_count;
156 int32_t field_count() {
157 return query_->field_count;
160 int32_t find_var(
const char *name) {
164 flecs::string str() {
166 return flecs::string(result);
181# include "../json/query.inl"
185 query_t *query_ =
nullptr;
188template<
typename ... Components>
189struct query : query_base,
iterable<Components...> {
194 using query_base::query_base;
196 query() : query_base() { }
198 query(
const query& obj) : query_base(obj) { }
200 query& operator=(
const query& obj) {
201 query_base::operator=(obj);
205 query(query&& obj) noexcept : query_base(FLECS_MOV(obj)) { }
207 query& operator=(query&& obj)
noexcept {
208 query_base::operator=(FLECS_FWD(obj));
214 ecs_assert(query_ !=
nullptr, ECS_INVALID_PARAMETER,
215 "cannot iterate invalid query");
228template <
typename... Comps,
typename... Args>
236 desc.
entity = query_entity;
240template <
typename... Comps,
typename... Args>
249template<
typename Func,
typename ... Args>
252template<
typename Func,
typename E,
typename ... Args>
253struct query_delegate_w_ent<Func,
arg_list<E, Args ...> >
257 f.each(FLECS_MOV(func));
262template<
typename Func,
typename ... Args>
265template<
typename Func,
typename ... Args>
266struct query_delegate_no_ent<Func,
arg_list<Args ...> >
270 f.each(FLECS_MOV(func));
275template<
typename Func,
typename T =
int>
278template <
typename Func>
279struct query_delegate<Func, if_t<is_same<first_arg_t<Func>, flecs::
entity>::value> > {
285template <
typename Func>
286struct query_delegate<Func, if_not_t<is_same<first_arg_t<Func>, flecs::
entity>::value> > {
294template <
typename Func>
299template <
typename T,
typename Func>
308template <
typename Func>
#define ecs_assert(condition, error_code,...)
Assert.
flecs::query< Comps... > query(Args &&... args) const
Create a query.
flecs::query_builder< Comps... > query_builder(Args &&... args) const
Create a query builder.
void each(Func &&func) const
Iterate over all entities with components in argument list of function.
bool ecs_each_next(ecs_iter_t *it)
Progress an iterator created with ecs_each_id().
ecs_iter_t ecs_each_id(const ecs_world_t *world, ecs_id_t id)
Iterate all entities with specified (component id).
bool(* ecs_iter_next_action_t)(ecs_iter_t *it)
Function prototype for iterating an iterator.
bool ecs_query_next(ecs_iter_t *it)
Progress query iterator.
const ecs_query_group_info_t * ecs_query_get_group_info(const ecs_query_t *query, uint64_t group_id)
Get information about query group.
int32_t ecs_query_find_var(const ecs_query_t *query, const char *name)
Find variable index.
void ecs_query_fini(ecs_query_t *query)
Delete a query.
char * ecs_query_plan(const ecs_query_t *query)
Convert query to a string.
ecs_iter_t ecs_query_iter(const ecs_world_t *world, const ecs_query_t *query)
Create a query iterator.
char * ecs_query_str(const ecs_query_t *query)
Convert query to string expression.
ecs_query_t * ecs_query_init(ecs_world_t *world, const ecs_query_desc_t *desc)
Create a query.
bool ecs_query_changed(ecs_query_t *query)
Returns whether the query data changed since the last iteration.
Component for storing a poly object.
ecs_poly_t * poly
Pointer to poly object.
Used with ecs_query_init().
ecs_term_t terms[32]
Query terms.
ecs_entity_t entity
Entity associated with query (optional)
void * ctx
Group context, returned by on_group_create.
ecs_term_t terms[32]
Query terms.
ecs_world_t * world
World or stage query was created with.
ecs_entity_t entity
Entity associated with query (optional)
int8_t term_count
Number of query terms.
ecs_id_t id
Component id to be matched by term.
bool changed() const
Returns whether the query data changed since the last iteration.
void * group_ctx(uint64_t group_id) const
Get context for group.
flecs::string plan() const
Returns a string representing the query plan.
const flecs::query_group_info_t * group_info(uint64_t group_id) const
Get info for group.
void destruct()
Free persistent query.
Class that describes a term.
flecs::term term(Args &&... args) const
Create a term.