8template <
typename ... Components>
11template <
typename ... Components>
14template <
typename ... Components>
15struct worker_iterable;
17template <
typename ... Components>
29 template <
typename Func>
30 void each(Func&& func)
const {
31 each(
nullptr, FLECS_FWD(func));
34 template <
typename Func>
35 void each(flecs::world_t *
world, Func&& func)
const {
36 iterate<_::each_invoker>(
world, FLECS_FWD(func),
37 this->next_each_action());
40 template <
typename Func>
42 iterate<_::each_invoker>(it.world(), FLECS_FWD(func),
43 this->next_each_action());
46 template <
typename Func>
48 iterate<_::each_invoker>(e.world(), FLECS_FWD(func),
49 this->next_each_action());
63 template <
typename Func>
64 void iter(Func&& func)
const {
65 iterate<_::iter_invoker>(
nullptr, FLECS_FWD(func),
69 template <
typename Func>
70 void iter(flecs::world_t *
world, Func&& func)
const {
71 iterate<_::iter_invoker>(
world, FLECS_FWD(func),
75 template <
typename Func>
77 iterate<_::iter_invoker>(it.world(), FLECS_FWD(func),
81 template <
typename Func>
83 iterate<_::iter_invoker>(e.world(), FLECS_FWD(func),
113 return this->
iter().count();
118 return this->
iter().is_true();
123 return this->
iter().first();
128 friend iter_iterable<Components...>;
129 friend page_iterable<Components...>;
130 friend worker_iterable<Components...>;
132 virtual ecs_iter_t get_iter(flecs::world_t *stage)
const = 0;
136 template <
template<
typename Func,
typename ... Comps>
class Invoker, typename Func, typename NextFunc, typename ... Args>
137 void iterate(flecs::world_t *stage, Func&& func, NextFunc next, Args &&... args) const {
138 ecs_iter_t it = this->get_iter(stage);
139 if (Invoker<Func, Components...>::instanced()) {
140 ECS_BIT_SET(it.flags, EcsIterIsInstanced);
143 while (next(&it, FLECS_FWD(args)...)) {
144 Invoker<Func, Components...>(func).invoke(&it);
149template <
typename ... Components>
151 template <
typename Iterable>
154 m_it = it->get_iter(
world);
155 m_next = it->next_action();
156 m_next_each = it->next_action();
159 iter_iterable<Components...>& set_var(
int var_id, flecs::entity_t value) {
160 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, 0);
166# include "../mixins/rule/iterable.inl"
169# include "../mixins/json/iterable.inl"
175 while (m_next_each(&m_it)) {
176 result += m_it.count;
183 bool result = m_next_each(&m_it);
193 if (m_next_each(&m_it) && m_it.count) {
207 template <
typename Group>
214 ecs_iter_t get_iter(flecs::world_t *
world)
const {
216 ecs_iter_t result = m_it;
217 result.world =
world;
237template <
typename ... Components>
243template <
typename ... Components>
245 template <
typename Iterable>
250 m_chain_it = it->get_iter(
nullptr);
254 ecs_iter_t get_iter(flecs::world_t*)
const {
267 ecs_iter_t m_chain_it;
272template <
typename ... Components>
280template <
typename ... Components>
286 m_chain_it = it->get_iter(
nullptr);
290 ecs_iter_t get_iter(flecs::world_t*)
const {
303 ecs_iter_t m_chain_it;
308template <
typename ... Components>
#define ecs_assert(condition, error_code,...)
Assert.
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)
Cleanup 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 value for iterator variable.
bool ecs_worker_next(ecs_iter_t *it)
Progress a worker iterator.
bool ecs_page_next(ecs_iter_t *it)
Progress a paged iterator.
void ecs_query_set_group(ecs_iter_t *it, uint64_t group_id)
Set group to iterate for query iterator.
Class for iterating over query results.
bool is_true() const
Return whether iterable has any matches.
flecs::entity first() const
Return first entity matched by iterable.
void each(Func &&func) const
Each iterator.
int32_t count() const
Return number of entities matched by iterable.
void iter(Func &&func) const
Iter iterator.
page_iterable< Components... > page(int32_t offset, int32_t limit)
Page iterator.
worker_iterable< Components... > worker(int32_t index, int32_t count)
Worker iterator.
iter_iterable< Components... > iter(flecs::world_t *world=nullptr) const
Create iterator.