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_;
44 flecs_poly_claim(this->query_);
48 query_base& operator=(
const query_base& obj) {
50 this->query_ = obj.query_;
53 flecs_poly_claim(this->query_);
58 query_base(query_base&& obj)
noexcept {
59 this->query_ = obj.query_;
63 query_base& operator=(query_base&& obj)
noexcept {
64 this->query_ = obj.query_;
73 const flecs::query_t* c_ptr()
const {
77 operator const flecs::query_t*()
const {
81 operator bool()
const {
82 return query_ !=
nullptr;
91 ecs_assert(query_->entity != 0, ECS_INVALID_OPERATION,
"destruct() "
92 "should only be called on queries associated with entities");
102 if (query_ && !query_->
entity) {
103 if (!flecs_poly_release(query_)) {
128 const flecs::query_group_info_t*
group_info(uint64_t group_id)
const {
138 const flecs::query_group_info_t *gi =
group_info(group_id);
146 template <
typename Func>
147 void each_term(
const Func& func) {
148 for (
int i = 0; i < query_->
term_count; i ++) {
156 return flecs::term(query_->world, query_->terms[index]);
159 int32_t term_count() {
160 return query_->term_count;
163 int32_t field_count() {
164 return query_->field_count;
167 int32_t find_var(
const char *name) {
171 flecs::string str() {
173 return flecs::string(result);
188# include "../json/query.inl"
192 query_t *query_ =
nullptr;
195template<
typename ... Components>
196struct query : query_base,
iterable<Components...> {
201 using query_base::query_base;
203 query() : query_base() { }
205 query(
const query& obj) : query_base(obj) { }
207 query& operator=(
const query& obj) {
208 query_base::operator=(obj);
212 query(query&& obj) noexcept : query_base(FLECS_MOV(obj)) { }
214 query& operator=(query&& obj)
noexcept {
215 query_base::operator=(FLECS_FWD(obj));
226 ecs_assert(query_ !=
nullptr, ECS_INVALID_PARAMETER,
227 "cannot iterate invalid query");
240template <
typename... Comps,
typename... Args>
248 desc.
entity = query_entity;
252template <
typename... Comps,
typename... Args>
261template<
typename Func,
typename ... Args>
264template<
typename Func,
typename E,
typename ... Args>
265struct query_delegate_w_ent<Func,
arg_list<E, Args ...> >
269 f.each(FLECS_MOV(func));
274template<
typename Func,
typename ... Args>
277template<
typename Func,
typename ... Args>
278struct query_delegate_no_ent<Func,
arg_list<Args ...> >
282 f.each(FLECS_MOV(func));
287template<
typename Func,
typename T =
int>
290template <
typename Func>
291struct query_delegate<Func, if_t<
is_same<first_arg_t<Func>, flecs::
entity>::value> > {
297template <
typename Func>
298struct query_delegate<Func, if_not_t<
is_same<first_arg_t<Func>, flecs::
entity>::value> > {
306template <
typename Func>
311template <
typename T,
typename Func>
320template <
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.
const ecs_query_t * ecs_query_get_cache_query(const ecs_query_t *query)
Get query used to populate cache.
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_world_t * world
World or stage query was created with.
ecs_entity_t entity
Entity associated with query (optional)
ecs_term_t * terms
Query terms.
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.