Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
field.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs
9{
10
16template <typename T>
17inline field<T>::field(iter &iter, int32_t index) {
18 *this = iter.field<T>(index);
19}
20
26template <typename T>
27T& field<T>::operator[](size_t index) const {
28 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
29 "invalid nullptr dereference of component type %s",
30 _::type_name<T>());
32 "index %d out of range for array of component type %s",
33 index, _::type_name<T>());
34 ecs_assert(!index || !is_shared_, ECS_INVALID_PARAMETER,
35 "non-zero index invalid for shared field of component type %s",
36 _::type_name<T>());
37 return data_[index];
38}
39
45template <typename T>
47 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
48 "invalid nullptr dereference of component type %s",
49 _::type_name<T>());
50 return *data_;
51}
52
58template <typename T>
60 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
61 "invalid nullptr dereference of component type %s",
62 _::type_name<T>());
63 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
64 "-> operator invalid for an array with >1 element of "
65 "component type %s, use [row] instead",
66 _::type_name<T>());
67 return data_;
68}
69
70}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
#define ECS_INVALID_OPERATION
Invalid operation error code.
Definition log.h:659
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:661
#define ECS_COLUMN_INDEX_OUT_OF_RANGE
Column index out of range error code.
Definition log.h:711
T * operator->() const
Return the first element of the component array.
Definition field.hpp:59
T & operator*() const
Return the first element of the component array.
Definition field.hpp:46
field(T *array, size_t count, bool is_shared=false)
Create a field from a component array.
Definition field.hpp:71
T & operator[](size_t index) const
Return an element in the component array.
Definition field.hpp:27