9template <
typename ... Components>
14 struct chained_iterable;
17template <
typename... Components>
20template <
typename... Components>
24template <
typename ... Components>
36 template <
typename Func>
37 void each(Func&& func)
const {
52 template <
typename Func>
53 void run(Func&& func)
const {
64 template <
typename Func>
70 while (!result && next(&it)) {
103 page_iterable<Components...>
page(int32_t offset, int32_t limit);
113 worker_iterable<Components...>
worker(int32_t index, int32_t
count);
117 return this->
iter().count();
122 return this->
iter().is_true();
130 template <
typename Var,
typename Value>
131 iter_iterable<Components...> set_var(Var var, Value value)
const {
132 return this->
iter().set_var(var, value);
135#ifdef FLECS_CACHED_QUERIES
138 return this->
iter().set_group(group_id);
142 template <
typename Group>
152 friend page_iterable<Components...>;
153 friend worker_iterable<Components...>;
160template <
typename ... Components>
163 template <
typename Iterable>
166 it_ = it->get_iter(
world);
167 next_ = it->next_action();
171 template <
typename Var,
typename Value>
174#ifdef FLECS_QUERY_PLANS
175 if constexpr (std::is_convertible_v<Var, const char*>) {
183 if constexpr (std::is_convertible_v<Value, flecs::entity_t>) {
185 }
else if constexpr (std::is_convertible_v<Value, flecs::table_t*> &&
186 !std::is_base_of_v<flecs::table_range, Value>)
190 ecs_table_range_t range;
191 if constexpr (std::is_same_v<Value, ecs_table_range_t>) {
194 range = {value.get_table(), value.offset(), value.count()};
208 while (next_(&it_)) {
216 bool result = next_(&it_);
225 while (next_(&it_)) {
235#ifdef FLECS_CACHED_QUERIES
243 template <
typename Group>
254 result.stage =
world;
269template <
typename ... Components>
275template <
typename ... Components>
281template <
typename ... Components>
290struct chained_iterable final :
iterable<Components...> {
292 : chain_it_(source->get_iter(
nullptr)), args_{
first, second} { }
296 return Create(&chain_it_, args_[0], args_[1]);
310template <
typename... Components>
312 return page_iterable<Components...>(offset, limit,
this);
315template <
typename... Components>
317 return worker_iterable<Components...>(index,
count,
this);
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
#define ECS_INTERNAL_ERROR
Internal error code.
struct ecs_iter_t ecs_iter_t
Type used for iterating iterable objects.
ecs_world_t world_t
World type.
bool(*) ecs_iter_next_action_t(ecs_iter_t *it)
Function prototype for iterating an iterator.
ecs_iter_t ecs_worker_iter(const ecs_iter_t *it, int32_t index, int32_t count)
Create a worker iterator.
void ecs_iter_fini(ecs_iter_t *it)
Clean up iterator resources.
ecs_iter_t ecs_page_iter(const ecs_iter_t *it, int32_t offset, int32_t limit)
Create a paged iterator.
void ecs_iter_set_var(ecs_iter_t *it, int32_t var_id, ecs_entity_t entity)
Set the value for an iterator variable.
bool ecs_worker_next(ecs_iter_t *it)
Progress a worker iterator.
void ecs_iter_set_var_as_table(ecs_iter_t *it, int32_t var_id, const ecs_table_t *table)
Same as ecs_iter_set_var(), but for a table.
bool ecs_page_next(ecs_iter_t *it)
Progress a paged iterator.
void ecs_iter_set_var_as_range(ecs_iter_t *it, int32_t var_id, const ecs_table_range_t *range)
Same as ecs_iter_set_var(), but for a range of entities.
void ecs_iter_set_group(ecs_iter_t *it, uint64_t group_id)
Set the group to iterate for a query iterator.
int32_t ecs_query_find_var(const ecs_query_t *query, const char *name)
Find a variable index.
const ecs_query_t * query
Query being evaluated.
flecs::world world() const
Get the world.
flecs::entity first() const
Get first element from a pair.
Forward declaration of iter_iterable.
iter_iterable< Components... > & set_group()
Limit results to tables with the specified group type (grouped queries only).
iter_iterable< Components... > & set_group(uint64_t group_id)
Limit results to tables with the specified group ID (grouped queries only).
flecs::entity first()
Return the first matching entity.
iter_iterable(Iterable *it, flecs::world_t *world)
Construct iter_iterable from an iterable and a world.
bool is_true()
Return whether the iterator yields at least one result.
int32_t count()
Return the total number of entities in the result.
Class for iterating over query results.
iter(ecs_iter_t *it)
Construct iterator from C iterator object.
Base class for iterable query objects.
bool is_true() const
Return whether the iterable has any matches.
iter_iterable< Components... > set_group() const
Limit results to tables with the specified group type (grouped queries only).
void run(Func &&func) const
Run the iterator.
flecs::entity first() const
Return the first entity matched by the iterable.
void each(Func &&func) const
Each iterator.
virtual ~iterable()
Virtual destructor.
page_iterable< Components... > page(int32_t offset, int32_t limit)
Page iterator.
flecs::entity find(Func &&func) const
Find the first entity matching a condition.
worker_iterable< Components... > worker(int32_t index, int32_t count)
Worker iterator.
iter_iterable< Components... > iter(flecs::world_t *world=nullptr) const
Create an iterator.
iter_iterable< Components... > set_group(uint64_t group_id) const
Limit results to tables with the specified group ID (grouped queries only).