2#include "Engine/Attribute/Attribute.h"
4#include "tbb/concurrent_vector.h"
42template <
typename T>
class AttributeHandle
45 attr::AttributeType type_;
55 if (attribute ==
nullptr)
56 throw std::runtime_error(
"Cannot pass empty pointer to AttributeHandle constructor");
57 type_ = attribute->getType();
58 name_ = attribute->getName();
59 data_ = std::get<std::shared_ptr<StoreContainer<T>>>(attribute->store_);
71 data_->push_back(value);
109 void resize(std::size_t newSize) { data_->resize(newSize); }
120 std::vector<T>
getAllValues()
const {
return {data_->begin(), data_->end()}; }
125 size_t getSize()
const {
return data_->size(); }
134 T
getValue(
size_t offset)
const {
return (*data_)[offset]; }
144 requires(!std::is_same_v<T, boolT>)
146 return (*data_)[offset];
153 std::span<const T>
getSpan()
const {
return {data_->data(), data_->size()}; }
161 void setValue(
size_t offset,
const T& value) { (*data_)[offset] = value; }
171 bool private_ =
false;
174 bool hidden_ =
false;
176 bool readOnly_ =
false;
180 std::shared_ptr<StoreContainer<T>> data_;
185using AttributeHandleInt = AttributeHandle<intT>;
186using AttributeHandleFloat = AttributeHandle<floatT>;
187using AttributeHandleVector3 = AttributeHandle<enzo::Vector3>;
188using AttributeHandleBool = AttributeHandle<enzo::boolT>;
189using AttributeHandleMatrix4 = AttributeHandle<enzo::Matrix4>;
204 type_ = attribute->getType();
205 name_ = attribute->getName();
206 data_ = std::get<std::shared_ptr<StoreContainer<T>>>(attribute->store_);
210 std::vector<T>
getAllValues()
const {
return {data_->begin(), data_->end()}; }
213 size_t getSize()
const {
return data_->size(); }
221 if (offset >= data_->size())
222 throw std::out_of_range(
223 "Cannot get offset: " + std::to_string(offset) +
224 " from size: " + std::to_string(data_->size()) +
" for attribute: " + name_
226 return (*data_)[offset];
231 requires(!std::is_same_v<T, boolT>)
233 return (*data_)[offset];
242 bool private_ =
false;
245 bool hidden_ =
false;
247 bool readOnly_ =
false;
251 std::shared_ptr<StoreContainer<T>> data_;
256using AttributeHandleInt = AttributeHandle<intT>;
257using AttributeHandleFloat = AttributeHandle<floatT>;
258using AttributeHandleVector3 = AttributeHandle<enzo::Vector3>;
259using AttributeHandleBool = AttributeHandle<enzo::boolT>;
260using AttributeHandleMatrix4 = AttributeHandle<enzo::Matrix4>;
Basic attribute, parameter, and node types for Enzo.
AttributeType
Data types available to store attribute values in.
Definition Types.h:32
Read only accessor for enzo::attr::Attribute.
Definition AttributeHandle.h:197
AttributeHandleRO(std::shared_ptr< const Attribute > attribute)
Construct a new typed handle linked to a target attribute.
Definition AttributeHandle.h:202
T getValue(size_t offset) const
Gets the value at a given offset.
Definition AttributeHandle.h:216
const T & operator[](size_t offset) const
Zero copy element access. Prefer in hot loops over getValue.
Definition AttributeHandle.h:230
size_t getSize() const
Gets the number of element stored in the attribute.
Definition AttributeHandle.h:213
std::string getName() const
Returs the attribute name as a string.
Definition AttributeHandle.h:237
std::vector< T > getAllValues() const
Gets a vector containing all the values stored in this attribute.
Definition AttributeHandle.h:210
void addValue(T value)
Adds an element to the end of the attribute.
Definition AttributeHandle.h:68
void resize(std::size_t newSize)
Resizes more space in the attribute to add new elements.
Definition AttributeHandle.h:109
std::span< const T > getSpan() const
Contiguous read only view over all stored values.
Definition AttributeHandle.h:153
std::vector< T > getAllValues() const
Gets a vector containing all the values stored in this attribute.
Definition AttributeHandle.h:120
T getValue(size_t offset) const
Gets the value at a given offset.
Definition AttributeHandle.h:134
void setValue(size_t offset, const T &value)
Sets the value at a given offset.
Definition AttributeHandle.h:161
AttributeHandle(std::shared_ptr< Attribute > attribute)
Construct a new typed handle linked to a target attribute.
Definition AttributeHandle.h:53
size_t getSize() const
Gets the number of element stored in the attribute.
Definition AttributeHandle.h:125
std::string getName() const
Returs the attribute name as a string.
Definition AttributeHandle.h:166
const T & operator[](size_t offset) const
Zero copy element access. Prefer in hot loops over getValue.
Definition AttributeHandle.h:143