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
7#pragma once
8
17namespace flecs
18{
19
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_, 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
47protected:
48 void* data_;
49 size_t size_;
50 size_t count_;
51 bool is_shared_;
52};
53
60template <typename T>
61struct 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
82
89 T& operator[](size_t index) const;
90
96 T& operator*() const;
97
103 T* operator->() const;
104
105protected:
106 T* data_;
107 size_t count_;
108 bool is_shared_;
109};
110
111} // namespace flecs
112
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
Wrapper class around a field.
Definition field.hpp:61
T * operator->() const
Return first element of component array.
Definition field.hpp:49
field(iter &iter, int field)
Create field from iterator.
T & operator*() const
Return first element of component array.
Definition field.hpp:36
field(T *array, size_t count, bool is_shared=false)
Create field from component array.
Definition field.hpp:71
T & operator[](size_t index) const
Return element in component array.
Definition field.hpp:17
Class for iterating over query results.
Definition iter.hpp:68
Unsafe wrapper class around a field.
Definition field.hpp:26
void * operator[](size_t index) const
Return element in component array.
Definition field.hpp:39