Flecs: include/flecs/addons/cpp/impl/field.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| 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
5
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>());
31 ecs_assert(index < count_, ECS_COLUMN_INDEX_OUT_OF_RANGE,
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>
46T& field<T>::operator*() const {
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>
59T* field<T>::operator->() const {
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}
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
ECS_INVALID_OPERATION
#define ECS_INVALID_OPERATION
Invalid operation error code.
Definition log.h:659
ECS_INVALID_PARAMETER
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:661
ECS_COLUMN_INDEX_OUT_OF_RANGE
#define ECS_COLUMN_INDEX_OUT_OF_RANGE
Column index out of range error code.
Definition log.h:711
flecs::field::operator->
T * operator->() const
Return the first element of the component array.
Definition field.hpp:59
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::iter::field
flecs::field< A > field(int8_t index) const
Get read-only access to field data.
Definition iter.hpp:80