Flecs v3.2
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 : m_data(array)
29 , m_size(size)
30 , m_count(count)
31 , m_is_shared(is_shared) {}
32
39 void* operator[](size_t index) const {
40 ecs_assert(!m_is_shared, ECS_INVALID_PARAMETER,
41 "invalid usage of [] operator for shared component field");
42 ecs_assert(index < m_count, ECS_COLUMN_INDEX_OUT_OF_RANGE,
43 "index %d out of range for field", index);
44 return ECS_OFFSET(m_data, m_size * index);
45 }
46
47protected:
48 void* m_data;
49 size_t m_size;
50 size_t m_count;
51 bool m_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 : m_data(array)
73 , m_count(count)
74 , m_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* m_data;
107 size_t m_count;
108 bool m_is_shared;
109};
110
111}
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:351
T * operator->() const
Return first element of component array.
Definition field.hpp:49
field(iter &iter, int field)
Create field from iterator.
void * operator[](size_t index) const
Return element in component array.
Definition field.hpp:39
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
Wrapper class around a field.
Definition field.hpp:61
Class for iterating over query results.
Definition iter.hpp:68
Unsafe wrapper class around a field.
Definition field.hpp:26