Flecs v3.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
iter.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs
9{
10
11inline flecs::entity iter::system() const {
12 return flecs::entity(m_iter->world, m_iter->system);
13}
14
15inline flecs::entity iter::event() const {
16 return flecs::entity(m_iter->world, m_iter->event);
17}
18
19inline flecs::id iter::event_id() const {
20 return flecs::id(m_iter->world, m_iter->event_id);
21}
22
23inline flecs::world iter::world() const {
24 return flecs::world(m_iter->world);
25}
26
27inline flecs::entity iter::entity(size_t row) const {
28 ecs_assert(row < static_cast<size_t>(m_iter->count),
29 ECS_COLUMN_INDEX_OUT_OF_RANGE, NULL);
30 return flecs::entity(m_iter->world, m_iter->entities[row]);
31}
32
33template <typename T>
34inline column<T>::column(iter &iter, int32_t index) {
35 *this = iter.field<T>(index);
36}
37
38inline flecs::entity iter::src(int32_t index) const {
39 return flecs::entity(m_iter->world, ecs_field_src(m_iter, index));
40}
41
42inline flecs::entity iter::id(int32_t index) const {
43 return flecs::entity(m_iter->world, ecs_field_id(m_iter, index));
44}
45
46inline flecs::id iter::pair(int32_t index) const {
47 flecs::id_t id = ecs_field_id(m_iter, index);
48 ecs_check(ECS_HAS_ID_FLAG(id, PAIR), ECS_INVALID_PARAMETER, NULL);
49 return flecs::id(m_iter->world, id);
50error:
51 return flecs::id();
52}
53
54inline flecs::type iter::type() const {
55 return flecs::type(m_iter->world, ecs_table_get_type(m_iter->table));
56}
57
58inline flecs::table iter::table() const {
59 return flecs::table(m_iter->world, m_iter->table);
60}
61
62inline flecs::table_range iter::range() const {
63 return flecs::table_range(m_iter->world, m_iter->table,
64 m_iter->offset, m_iter->count);
65}
66
67#ifdef FLECS_RULES
68inline flecs::entity iter::get_var(int var_id) const {
69 ecs_assert(m_iter->next == ecs_rule_next, ECS_INVALID_OPERATION, NULL);
70 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, 0);
71 return flecs::entity(m_iter->world, ecs_iter_get_var(m_iter, var_id));
72}
73
77inline flecs::entity iter::get_var(const char *name) const {
78 ecs_assert(m_iter->next == ecs_rule_next, ECS_INVALID_OPERATION, NULL);
79 ecs_rule_iter_t *rit = &m_iter->priv.iter.rule;
80 const flecs::rule_t *r = rit->rule;
81 int var_id = ecs_rule_find_var(r, name);
82 ecs_assert(var_id != -1, ECS_INVALID_PARAMETER, name);
83 return flecs::entity(m_iter->world, ecs_iter_get_var(m_iter, var_id));
84}
85#endif
86
87} // namespace flecs
#define ecs_assert(condition, error_code,...)
Assert.
Definition: log.h:352
#define ecs_check(condition, error_code,...)
Check.
Definition: log.h:388
FLECS_API bool ecs_rule_next(ecs_iter_t *it)
Progress rule iterator.
FLECS_API int32_t ecs_rule_find_var(const ecs_rule_t *rule, const char *name)
Find variable index.
ecs_id_t ecs_field_id(const ecs_iter_t *it, int32_t index)
Return id matched for field.
ecs_entity_t ecs_iter_get_var(ecs_iter_t *it, int32_t var_id)
Get value of iterator variable as entity.
ecs_entity_t ecs_field_src(const ecs_iter_t *it, int32_t index)
Return field source.
const ecs_type_t * ecs_table_get_type(const ecs_table_t *table)
Get type for table.
column(T *array, size_t count, bool is_shared=false)
Create column from component array.
Definition: iter.hpp:68
Entity.
Definition: entity.hpp:30
Class that wraps around a flecs::id_t.
Definition: decl.hpp:27
Class for iterating over query results.
Definition: iter.hpp:169
flecs::entity src(int32_t index) const
Obtain field source (0 if This).
Definition: iter.hpp:38
flecs::entity entity(size_t row) const
Obtain mutable handle to entity being iterated over.
Definition: iter.hpp:27
flecs::id pair(int32_t index) const
Obtain pair id matched for field.
Definition: iter.hpp:46
flecs::entity get_var(int var_id) const
Get value of variable by id.
Definition: iter.hpp:68
flecs::column< A > field(int32_t index) const
Get readonly access to field data.
Definition: iter.hpp:338
flecs::entity id(int32_t index) const
Obtain id matched for field.
Definition: iter.hpp:42
Type class.
Definition: type.hpp:21
The world.
Definition: world.hpp:113