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 {
53 template <
typename Func>
54 void run(Func&& func)
const {
65 template <
typename Func>
72 while (!result && next(&it)) {
105 page_iterable<Components...>
page(int32_t offset, int32_t limit);
115 worker_iterable<Components...>
worker(int32_t index, int32_t
count);
119 return this->
iter().count();
124 return this->
iter().is_true();
132 template <
typename Var,
typename Value>
133 iter_iterable<Components...> set_var(Var var, Value value)
const {
134 return this->
iter().set_var(var, value);
137#ifdef FLECS_CACHED_QUERIES
140 return this->
iter().set_group(group_id);
144 template <
typename Group>
154 friend page_iterable<Components...>;
155 friend worker_iterable<Components...>;
162template <
typename ... Components>
165 template <
typename Iterable>
168 it_ = it->get_iter(
world);
169 next_ = it->next_action();
173 template <
typename Var,
typename Value>
176#ifdef FLECS_QUERY_PLANS
177 if constexpr (std::is_convertible_v<Var, const char*>) {
185 if constexpr (std::is_convertible_v<Value, flecs::entity_t>) {
187 }
else if constexpr (std::is_convertible_v<Value, flecs::table_t*> &&
188 !std::is_base_of_v<flecs::table_range, Value>)
192 ecs_table_range_t range;
193 if constexpr (std::is_same_v<Value, ecs_table_range_t>) {
196 range = {value.get_table(), value.offset(), value.count()};
210 while (next_(&it_)) {
218 bool result = next_(&it_);
227 while (next_(&it_)) {
237#ifdef FLECS_CACHED_QUERIES
245 template <
typename Group>
256 result.stage =
world;
271template <
typename ... Components>
277template <
typename ... Components>
283template <
typename ... Components>
292struct chained_iterable final :
iterable<Components...> {
294 : chain_it_(source->get_iter(
nullptr)), args_{
first, second} { }
298 return Create(&chain_it_, args_[0], args_[1]);
312template <
typename... Components>
314 return page_iterable<Components...>(offset, limit,
this);
317template <
typename... Components>
319 return worker_iterable<Components...>(index,
count,
this);
_::each_delegate< typename std::decay< Func >::type, Args... > delegate
Delegate type for each callbacks.
#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).