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

| Flecs v4.0 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
11template <typename T>
12inline field<T>::field(iter &iter, int32_t index) {
13 *this = iter.field<T>(index);
14}
15
16template <typename T>
17T& field<T>::operator[](size_t index) const {
18 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
19 "invalid nullptr dereference of component type %s",
20 _::type_name<T>());
21 ecs_assert(index < count_, ECS_COLUMN_INDEX_OUT_OF_RANGE,
22 "index %d out of range for array of component type %s",
23 index, _::type_name<T>());
24 ecs_assert(!index || !is_shared_, ECS_INVALID_PARAMETER,
25 "non-zero index invalid for shared field of component type %s",
26 _::type_name<T>());
27 return data_[index];
28}
29
35template <typename T>
36T& field<T>::operator*() const {
37 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
38 "invalid nullptr dereference of component type %s",
39 _::type_name<T>());
40 return *data_;
41}
42
48template <typename T>
49T* field<T>::operator->() const {
50 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
51 "invalid nullptr dereference of component type %s",
52 _::type_name<T>());
53 ecs_assert(data_ != nullptr, ECS_INVALID_OPERATION,
54 "-> operator invalid for array with >1 element of "
55 "component type %s, use [row] instead",
56 _::type_name<T>());
57 return data_;
58}
59
60}
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
flecs::field::operator->
T * operator->() const
Return first element of component array.
Definition field.hpp:49
flecs::field::operator*
T & operator*() const
Return first element of component array.
Definition field.hpp:36
flecs::field::field
field(T *array, size_t count, bool is_shared=false)
Create field from component array.
Definition field.hpp:71
flecs::field::operator[]
T & operator[](size_t index) const
Return element in component array.
Definition field.hpp:17