Enzo
Loading...
Searching...
No Matches
enzo::attr::AttributeHandle< T > Class Template Reference

Read write accessor for enzo::attr::Attribute. More...

#include <AttributeHandle.h>

Public Member Functions

 AttributeHandle (std::shared_ptr< Attribute > attribute)
 Construct a new typed handle linked to a target attribute.
 
void addValue (T value)
 Adds an element to the end of the attribute.
 
void resize (std::size_t newSize)
 Resizes more space in the attribute to add new elements.
 
std::vector< T > getAllValues () const
 Gets a vector containing all the values stored in this attribute.
 
size_t getSize () const
 Gets the number of element stored in the attribute.
 
getValue (size_t offset) const
 Gets the value at a given offset.
 
const T & operator[] (size_t offset) const
 Zero copy element access. Prefer in hot loops over getValue.
 
std::span< const T > getSpan () const
 Contiguous read only view over all stored values.
 
void setValue (size_t offset, const T &value)
 Sets the value at a given offset.
 
std::string getName () const
 Returs the attribute name as a string.
 

Public Attributes

attr::AttributeType type_
 

Detailed Description

template<typename T>
class enzo::attr::AttributeHandle< T >

Read write accessor for enzo::attr::Attribute.

Template Parameters
TC++ value type matching the Attribute’s logical type (e.g., intT, floatT, Vector3, boolT).

An Attribute Handle is a typed view into an attribute’s storage. It binds at construction to a concrete type and exposes operations like reserving capacity, appending values, and reading/writing by index. Because the handle uses templating, most misuse is caught at compile time, and runtime guards raise errors if an attribute/handle type combination isn’t accounted for. In the future implicit casting can be added for convenience. Handles don’t own data, they just reference the attribute’s storage.

There is also a read-only handle variant that provides the same typed accessors without mutation. This is useful when an operator needs to inspect data but must not modify it, when the engine exposes attributes to user code with limited permissions, or when implementing const member functions that require attribute access.

Together, attributes define the schema and storage, while handles provide the typed access that nodes and tools use to operate on data directly.

Constructor & Destructor Documentation

◆ AttributeHandle()

template<typename T >
enzo::attr::AttributeHandle< T >::AttributeHandle ( std::shared_ptr< Attribute > attribute)
inline

Construct a new typed handle linked to a target attribute.

Parameters
attributeThe target attribute this handle will modify

Member Function Documentation

◆ addValue()

template<typename T >
void enzo::attr::AttributeHandle< T >::addValue ( T value)
inline

Adds an element to the end of the attribute.

Parameters
Theelement value the value to add to the attribute.

◆ getAllValues()

template<typename T >
std::vector< T > enzo::attr::AttributeHandle< T >::getAllValues ( ) const
inline

Gets a vector containing all the values stored in this attribute.

Todo
Replace with an iterator for accessing many values.
Returns
A vector containing all the values stored in this attribute.

◆ getSpan()

template<typename T >
std::span< const T > enzo::attr::AttributeHandle< T >::getSpan ( ) const
inline

Contiguous read only view over all stored values.

Returns
Span over the storage. Invalid after a mutation that grows storage.

◆ getValue()

template<typename T >
T enzo::attr::AttributeHandle< T >::getValue ( size_t offset) const
inline

Gets the value at a given offset.

Returns
The value stored at the offset.
Todo

protect against invalid positions

Add implicit casting between types (eg. if T is int but the parameter's attr::AttributeType is floatT 5.3 return 5)

◆ operator[]()

template<typename T >
const T & enzo::attr::AttributeHandle< T >::operator[] ( size_t offset) const
inline

Zero copy element access. Prefer in hot loops over getValue.

Returns
Reference to the value at the offset. Invalid after a mutation that grows storage.

Not available for bool handles since std::vector<bool> is bit packed and has no real reference.

◆ resize()

template<typename T >
void enzo::attr::AttributeHandle< T >::resize ( std::size_t newSize)
inline

Resizes more space in the attribute to add new elements.

     @brief Reserves more space in the attribute to add new elements

     This is important when adding many elements to the attribute as automatic resizing is

expensive.

     @param newCap The new maximum number of elements the attribute can hold before needing to

automatically allocate more.

Resizes the container to contain count elements, does nothing if count == size().

If the current size is greater than count, the container is reduced to its first count elements.

If the current size is less than count, then:

1) Additional default-inserted elements are appended. 2) Additional copies of value are appended.

Important
This is important when adding many elements to the attribute as automatic resizing is expensive.
Parameters
newCapThe new maximum number of elements the attribute can hold before needing to automatically allocate more.

◆ setValue()

template<typename T >
void enzo::attr::AttributeHandle< T >::setValue ( size_t offset,
const T & value )
inline

Sets the value at a given offset.

Todo

protect against invalid positions

Add implicit casting between types (eg. if T is int but the parameter's attr::AttributeType is floatT 5.3 return 5)


The documentation for this class was generated from the following files: