Flecs
v4.1
A fast entity component system (ECS) for C & C++
Toggle main menu visibility
Loading...
Searching...
No Matches
field.hpp
Go to the documentation of this file.
1
6
7
#pragma once
8
16
17
namespace
flecs
18
{
19
26
struct
untyped_field {
27
untyped_field(
void
*
array
,
size_t
size,
size_t
count,
bool
is_shared =
false
)
28
: data_(
array
)
29
, size_(size)
30
, count_(count)
31
, is_shared_(is_shared) {}
32
39
void
*
operator[]
(
size_t
index)
const
{
40
ecs_assert
(!is_shared_ || !index,
ECS_INVALID_PARAMETER
,
41
"invalid usage of [] operator for shared component field"
);
42
ecs_assert
(index < count_,
ECS_COLUMN_INDEX_OUT_OF_RANGE
,
43
"index %d out of range for field"
, index);
44
return
ECS_OFFSET(data_, size_ * index);
45
}
46
47
protected
:
48
void
* data_;
49
size_t
size_;
50
size_t
count_;
51
bool
is_shared_;
52
};
53
60
template
<
typename
T>
61
struct
field
{
62
static_assert
(std::is_empty<T>::value ==
false
,
63
"invalid type for field, cannot iterate empty type"
);
64
71
field
(T*
array
,
size_t
count,
bool
is_shared =
false
)
72
: data_(
array
)
73
, count_(count)
74
, is_shared_(is_shared) {}
75
81
field
(
iter
&
iter
,
int
field
);
82
89
T&
operator[]
(
size_t
index)
const
;
90
96
T&
operator*
()
const
;
97
103
T*
operator->
()
const
;
104
105
protected
:
106
T* data_;
107
size_t
count_;
108
bool
is_shared_;
109
};
110
111
}
// namespace flecs
112
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition
log.h:473
ECS_INVALID_PARAMETER
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition
log.h:671
ECS_COLUMN_INDEX_OUT_OF_RANGE
#define ECS_COLUMN_INDEX_OUT_OF_RANGE
Column index out of range error code.
Definition
log.h:721
flecs::array
Array class (primary template, disabled).
Definition
array.hpp:47
flecs::field::operator->
T * operator->() const
Return the first element of the component array.
Definition
field.hpp:59
flecs::field::field
field(iter &iter, int field)
Create a field from an iterator.
flecs::field::operator*
T & operator*() const
Return the first element of the component array.
Definition
field.hpp:46
flecs::field::field
field(T *array, size_t count, bool is_shared=false)
Create a field from a component array.
Definition
field.hpp:71
flecs::field::operator[]
T & operator[](size_t index) const
Return an element in the component array.
Definition
field.hpp:27
flecs::iter
Class for iterating over query results.
Definition
iter.hpp:68
flecs::untyped_field::operator[]
void * operator[](size_t index) const
Return an element in the component array.
Definition
field.hpp:39