8template <
typename ... Components>
11template <
typename ... Components>
14template <
typename ... Components>
15struct worker_iterable;
17template <
typename ... Components>
27 template <
typename Func>
28 void each(Func&& func)
const {
41 template <
typename Func>
42 void run(Func&& func)
const {
47 template <
typename Func>
53 while (!result && next(&it)) {
100 return this->
iter().count();
105 return this->
iter().is_true();
113 iter_iterable<Components...> set_var(
int var_id, flecs::entity_t value)
const {
114 return this->
iter().set_var(var_id, value);
117 iter_iterable<Components...> set_var(
const char *name, flecs::entity_t value)
const {
118 return this->
iter().set_var(name, value);
121 iter_iterable<Components...> set_var(
const char *name, flecs::table_t *value)
const {
122 return this->
iter().set_var(name, value);
125 iter_iterable<Components...> set_var(
const char *name, ecs_table_range_t value)
const {
126 return this->
iter().set_var(name, value);
129 iter_iterable<Components...> set_var(
const char *name,
flecs::table_range value)
const {
130 return this->
iter().set_var(name, value);
134 iter_iterable<Components...> set_group(uint64_t group_id)
const {
135 return this->
iter().set_group(group_id);
139 template <
typename Group>
140 iter_iterable<Components...> set_group()
const {
141 return this->
iter().template set_group<Group>();
144 virtual ~iterable() { }
146 friend iter_iterable<Components...>;
147 friend page_iterable<Components...>;
148 friend worker_iterable<Components...>;
150 virtual ecs_iter_t get_iter(flecs::world_t *stage)
const = 0;
154template <
typename ... Components>
156 template <
typename Iterable>
159 it_ = it->get_iter(
world);
160 next_ = it->next_action();
161 next_each_ = it->next_action();
162 ecs_assert(next_ !=
nullptr, ECS_INTERNAL_ERROR, NULL);
163 ecs_assert(next_each_ !=
nullptr, ECS_INTERNAL_ERROR, NULL);
166 iter_iterable<Components...>& set_var(
int var_id, flecs::entity_t value) {
167 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, 0);
172 iter_iterable<Components...>& set_var(
const char *name, flecs::entity_t value) {
173 ecs_query_iter_t *qit = &it_.
priv_.iter.query;
175 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, name);
180 iter_iterable<Components...>& set_var(
const char *name, flecs::table_t *value) {
181 ecs_query_iter_t *qit = &it_.
priv_.iter.query;
183 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, name);
188 iter_iterable<Components...>& set_var(
const char *name, ecs_table_range_t value) {
189 ecs_query_iter_t *qit = &it_.
priv_.iter.query;
191 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, name);
197 ecs_table_range_t range;
199 range.offset = value.offset();
200 range.count = value.count();
201 return set_var(name, range);
211 while (next_each_(&it_)) {
219 bool result = next_each_(&it_);
229 if (next_each_(&it_) && it_.
count) {
243 template <
typename Group>
269template <
typename ... Components>
275template <
typename ... Components>
281template <
typename ... Components>
287template <
typename ... Components>
289 template <
typename Iterable>
294 chain_it_ = it->get_iter(
nullptr);
312template <
typename ... Components>
320template <
typename ... Components>
326 chain_it_ = it->get_iter(
nullptr);
344template <
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.
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 This constrains the variable to a range of en...
void ecs_iter_set_group(ecs_iter_t *it, uint64_t group_id)
Set group to iterate for query iterator.
int32_t ecs_query_find_var(const ecs_query_t *query, const char *name)
Find variable index.
ecs_world_t * real_world
Actual world.
ecs_iter_private_t priv_
Private data.
ecs_world_t * world
The world.
int32_t count
Number of entities to iterate.
const ecs_entity_t * entities
Entity identifiers.
flecs::entity first() const
Get first element from a pair.
Class for iterating over query results.
bool is_true() const
Return whether iterable has any matches.
void run(Func &&func) const
Run iterator.
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.
iter_iterable< Components... > iter(flecs::entity e) const
Create iterator.
page_iterable< Components... > page(int32_t offset, int32_t limit)
Page iterator.
iter_iterable< Components... > iter(flecs::iter &iter) const
Create 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.
table_t * get_table() const
Get table.