7#include "Engine/Operator/Attribute.h"
9#include "tbb/concurrent_vector.h"
45 ga::AttributeType type_;
55 if(attribute ==
nullptr)
throw std::runtime_error(
"Cannot pass empty pointer to AttributeHandle constructor");
56 type_ = attribute->getType();
57 name_ = attribute->getName();
63 if constexpr (std::is_same<bt::intT, T>::value)
65 data_=attribute->intStore_;
69 else if constexpr (std::is_same<bt::floatT, T>::value)
71 data_=attribute->floatStore_;
75 else if constexpr (std::is_same<enzo::bt::Vector3, T>::value)
77 data_=attribute->vector3Store_;
79 else if constexpr (std::is_same<enzo::bt::boolT, T>::value)
81 data_=attribute->boolStore_;
83 else if constexpr (std::is_same<enzo::bt::Matrix4, T>::value)
85 data_=attribute->matrix4Store_;
89 throw std::runtime_error(
"Type " + std::to_string(
static_cast<int>(type_)) +
" was not properly accounted for in AttributeHandle constructor");
102 data_->push_back(value);
138 data_->resize(newSize);
153 return {data_->begin(), data_->end()};
161 return data_->size();
172 if(offset >= data_->size())
throw std::out_of_range(
"Cannot get offset: " + std::to_string(offset) +
" from size: " + std::to_string(data_->size()) +
" for attribute: " + name_);
173 return (*data_)[offset];
183 (*data_)[offset] = value;
204 bool readOnly_=
false;
208 std::shared_ptr<StoreContainer<T>> data_;
214using AttributeHandleInt = AttributeHandle<bt::intT>;
215using AttributeHandleFloat = AttributeHandle<bt::floatT>;
216using AttributeHandleVector3 = AttributeHandle<enzo::bt::Vector3>;
217using AttributeHandleBool = AttributeHandle<enzo::bt::boolT>;
218using AttributeHandleMatrix4 = AttributeHandle<enzo::bt::Matrix4>;
233 type_ = attribute->getType();
234 name_ = attribute->getName();
240 if constexpr (std::is_same<bt::intT, T>::value)
242 data_=attribute->intStore_;
246 else if constexpr (std::is_same<bt::floatT, T>::value)
248 data_=attribute->floatStore_;
252 else if constexpr (std::is_same<enzo::bt::Vector3, T>::value)
254 data_=attribute->vector3Store_;
256 else if constexpr (std::is_same<enzo::bt::boolT, T>::value)
258 data_=attribute->boolStore_;
260 else if constexpr (std::is_same<enzo::bt::Matrix4, T>::value)
262 data_=attribute->matrix4Store_;
266 throw std::runtime_error(
"Type " + std::to_string(
static_cast<int>(type_)) +
" was not properly accounted for in AttributeHandle constructor");
274 return {data_->begin(), data_->end()};
280 return data_->size();
289 if(offset >= data_->size())
throw std::out_of_range(
"Cannot get offset: " + std::to_string(offset) +
" from size: " + std::to_string(data_->size()) +
" for attribute: " + name_);
290 return (*data_)[offset];
309 bool readOnly_=
false;
313 std::shared_ptr<StoreContainer<T>> data_;
319using AttributeHandleInt = AttributeHandle<bt::intT>;
320using AttributeHandleFloat = AttributeHandle<bt::floatT>;
321using AttributeHandleVector3 = AttributeHandle<enzo::bt::Vector3>;
322using AttributeHandleBool = AttributeHandle<enzo::bt::boolT>;
323using AttributeHandleMatrix4 = AttributeHandle<enzo::bt::Matrix4>;
Basic attribute, parameter, and node types for Enzo.
AttributeType
Data types available to store attribute values in.
Definition Types.h:25
Read only accessor for enzo::ga::Attribute.
Definition AttributeHandle.h:226
AttributeHandleRO(std::shared_ptr< const Attribute > attribute)
Construct a new typed handle linked to a target attribute.
Definition AttributeHandle.h:231
std::string getName() const
Returs the attribute name as a string.
Definition AttributeHandle.h:294
size_t getSize() const
Gets the number of element stored in the attribute.
Definition AttributeHandle.h:278
T getValue(size_t offset) const
Gets the value at a given offset.
Definition AttributeHandle.h:284
std::vector< T > getAllValues() const
Gets a vector containing all the values stored in this attribute.
Definition AttributeHandle.h:272
void setValue(size_t offset, const T &value)
Sets the value at a given offset.
Definition AttributeHandle.h:181
std::string getName() const
Returs the attribute name as a string.
Definition AttributeHandle.h:189
std::vector< T > getAllValues() const
Gets a vector containing all the values stored in this attribute.
Definition AttributeHandle.h:151
void addValue(T value)
Adds an element to the end of the attribute.
Definition AttributeHandle.h:99
size_t getSize() const
Gets the number of element stored in the attribute.
Definition AttributeHandle.h:159
T getValue(size_t offset) const
Gets the value at a given offset.
Definition AttributeHandle.h:170
void resize(std::size_t newSize)
Reserves more space in the attribute to add new elements.
Definition AttributeHandle.h:136
AttributeHandle(std::shared_ptr< Attribute > attribute)
Construct a new typed handle linked to a target attribute.
Definition AttributeHandle.h:53