HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_GenericData Class Reference

#include <UN_GenericData.h>

Public Member Functions

template<typename D >
UN_GenericBufferID addBuffer (const UT_StringRef &name, UN_GenericBufferType type, const D &default_value, UN_DataSize buffer_size)
 
UN_GenericBufferType bufferType (UN_GenericBufferID id) const
 Returns the type of the buffer identified by the given ID. More...
 
exint numBuffers () const
 Returns the number of generic buffers. More...
 
UN_GenericBufferID findBuffer (const UT_StringRef &name) const
 
const UT_StringHolderbufferName (UN_GenericBufferID id) const
 Returns the name of the buffer identified by the given ID. More...
 
template<typename T >
void setData (UN_GenericBufferID buf_id, UN_DataIndex index, const T &value)
 Sets the data value for a given buffer and index. More...
 
template<typename T >
void setData (UN_GenericBufferID buf_id, UN_DataIndex index, T &&value)
 Sets the data value via move for a given buffer and index. More...
 
template<typename T >
const TgetDataRef (UN_GenericBufferID buf_id, UN_DataIndex index) const
 
template<typename T >
T getDataVal (UN_GenericBufferID buf_id, UN_DataIndex index) const
 
template<typename T >
T stealData (UN_GenericBufferID buf_id, UN_DataIndex index)
 
template<typename T , typename OP >
void updateData (UN_GenericBufferID buf_id, UN_DataIndex index, const OP &op)
 
void addData (UN_DataIndex index)
 Adds a data slot at the given index to all generic buffers. More...
 
void clearData (UN_DataIndex index)
 Clears the data at the given index to defaults in all generic buffers. More...
 
void removeAllData ()
 Removes all data from all generic buffers. More...
 
void setCapacityIfNeeded (UN_DataSize min_capacity)
 Grows all generic buffers to the given minimum capacity if needed. More...
 
void mergeData (const UN_GenericData &src, const UN_DataMergeInfo &merge_info)
 Merges data from another UN_GenericData container. More...
 
bool isDataSizeConsistent (UN_DataSize expected_size) const
 Returns true if all buffers have the expected size. More...
 
bool isDataSizeConsistent () const
 Returns true if all buffers have the expected size. More...
 

Detailed Description

Container for dynamically added data buffers of known types.

Unlike the built-in buffers in UN_NodeData or UN_PortData, which are fixed at compile time, this class allows buffers to be added on demand at runtime by specifying a desired data type. Each buffer is identified by a UN_GenericBufferID returned from addBuffer().

Data access uses template methods (setData<T>, getDataRef<T>) that compile down to direct buffer access via std::get<>() — no virtual dispatch. Lifecycle operations (addData, clearData, etc.) use std::visit.

Definition at line 223 of file UN_GenericData.h.

Member Function Documentation

template<typename D >
UN_GenericBufferID UN_GenericData::addBuffer ( const UT_StringRef name,
UN_GenericBufferType  type,
const D &  default_value,
UN_DataSize  buffer_size 
)
inline

Adds a new named data buffer with a caller-specified default value. If a buffer with the same name already exists and the type matches, its existing ID is returned. If the name exists but the type conflicts, an invalid ID is returned.

Definition at line 231 of file UN_GenericData.h.

void UN_GenericData::addData ( UN_DataIndex  index)

Adds a data slot at the given index to all generic buffers.

const UT_StringHolder& UN_GenericData::bufferName ( UN_GenericBufferID  id) const
inline

Returns the name of the buffer identified by the given ID.

Definition at line 274 of file UN_GenericData.h.

UN_GenericBufferType UN_GenericData::bufferType ( UN_GenericBufferID  id) const
inline

Returns the type of the buffer identified by the given ID.

Definition at line 262 of file UN_GenericData.h.

void UN_GenericData::clearData ( UN_DataIndex  index)

Clears the data at the given index to defaults in all generic buffers.

UN_GenericBufferID UN_GenericData::findBuffer ( const UT_StringRef name) const

Returns the ID of the buffer with the given name, or an invalid ID if no such buffer exists.

template<typename T >
const T& UN_GenericData::getDataRef ( UN_GenericBufferID  buf_id,
UN_DataIndex  index 
) const
inline

Returns a const ref to the data value for a given buffer and index. Returns the buffer's stored default for invalid indices.

Definition at line 305 of file UN_GenericData.h.

template<typename T >
T UN_GenericData::getDataVal ( UN_GenericBufferID  buf_id,
UN_DataIndex  index 
) const
inline

Returns a copy of the data value for a given buffer and index. Returns a copy of the buffer's stored default for invalid indices. Useful when cannot call getDataRef() for types that cannot return by reference (eg, bool with bit-packed UN_DataBuffer<bool>).

Definition at line 321 of file UN_GenericData.h.

bool UN_GenericData::isDataSizeConsistent ( UN_DataSize  expected_size) const

Returns true if all buffers have the expected size.

bool UN_GenericData::isDataSizeConsistent ( ) const

Returns true if all buffers have the expected size.

void UN_GenericData::mergeData ( const UN_GenericData src,
const UN_DataMergeInfo merge_info 
)

Merges data from another UN_GenericData container.

exint UN_GenericData::numBuffers ( ) const
inline

Returns the number of generic buffers.

Definition at line 266 of file UN_GenericData.h.

void UN_GenericData::removeAllData ( )

Removes all data from all generic buffers.

void UN_GenericData::setCapacityIfNeeded ( UN_DataSize  min_capacity)

Grows all generic buffers to the given minimum capacity if needed.

template<typename T >
void UN_GenericData::setData ( UN_GenericBufferID  buf_id,
UN_DataIndex  index,
const T value 
)
inline

Sets the data value for a given buffer and index.

Definition at line 279 of file UN_GenericData.h.

template<typename T >
void UN_GenericData::setData ( UN_GenericBufferID  buf_id,
UN_DataIndex  index,
T &&  value 
)
inline

Sets the data value via move for a given buffer and index.

Definition at line 291 of file UN_GenericData.h.

template<typename T >
T UN_GenericData::stealData ( UN_GenericBufferID  buf_id,
UN_DataIndex  index 
)
inline

Moves the data value out of a given buffer and index. Returns a copy of the buffer's stored default for invalid indices.

Definition at line 334 of file UN_GenericData.h.

template<typename T , typename OP >
void UN_GenericData::updateData ( UN_GenericBufferID  buf_id,
UN_DataIndex  index,
const OP &  op 
)
inline

Updates the data value in-place via a callable. Usage: updateData<T>(buf_id, index, [](auto &v) { v = ...; });

Definition at line 347 of file UN_GenericData.h.


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