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();
160# include "../mixins/rule/iterable.inl"
163# include "../mixins/json/iterable.inl"
169 while (m_next_each(&m_it)) {
170 result += m_it.count;
177 bool result = m_next_each(&m_it);
187 if (m_next_each(&m_it) && m_it.count) {
201 template <
typename Group>
208 ecs_iter_t get_iter(flecs::world_t *
world)
const {
210 ecs_iter_t result = m_it;
211 result.world =
world;
231template <
typename ... Components>
237template <
typename ... Components>
239 template <
typename Iterable>
244 m_chain_it = it->get_iter(
nullptr);
248 ecs_iter_t get_iter(flecs::world_t*)
const {
261 ecs_iter_t m_chain_it;
266template <
typename ... Components>
274template <
typename ... Components>
280 m_chain_it = it->get_iter(
nullptr);
284 ecs_iter_t get_iter(flecs::world_t*)
const {
297 ecs_iter_t m_chain_it;
302template <
typename ... Components>
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.
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.