HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_DataBuffer< T > Class Template Reference

#include <UN_DataBuffer.h>

Public Member Functions

 UN_DataBuffer ()=default
 
 UN_DataBuffer (UN_DataSize size)
 
T stealData (UN_DataIndex index)
 Returns a moved value from an entry in a data buffer. More...
 
template<typename OP >
void updateData (UN_DataIndex index, const OP &op)
 
void addData (UN_DataIndex index, const T &init_value=T())
 Adds an entry slot to the data buffer. More...
 
void appendData (const T &value, exint count)
 Appends count copies of the given value. More...
 
void appendData (const UN_DataBuffer< T > &src, UN_DataIndex start, UN_DataSize size)
 Appends a span of entries from another buffer. More...
 
void clear ()
 Resets the data to an empty buffer. More...
 
UN_DataSize size () const
 Returns the number of elements held in the data buffer. More...
 
void setCapacityIfNeeded (UN_DataSize min_capacity)
 
bool isValidIndex (UN_DataIndex index) const
 Return true if given index is valid. More...
 
void setData (UN_DataIndex index, const T &value)
 Sets the data value for the entry at a given index. More...
 
void setData (UN_DataIndex index, T &&value)
 Sets the data value for the entry at a given index. More...
 
const TgetDataRef (UN_DataIndex index) const
 
const Toperator[] (UN_DataIndex index) const
 

Detailed Description

template<typename T>
class UN_DataBuffer< T >

Vectorized memory buffer that contains data entries for a particular aspect for a group of items of the same kind in the graph. Each entry in the buffer holds a piece of data for a single item. For example, a buffer may hold names for the nodes, so each buffer entry holds a name for a single node. This class is templated on the type of the entries it stores.

Definition at line 27 of file UN_DataBuffer.h.

Constructor & Destructor Documentation

template<typename T>
UN_DataBuffer< T >::UN_DataBuffer ( )
default
template<typename T>
UN_DataBuffer< T >::UN_DataBuffer ( UN_DataSize  size)
inline

Definition at line 34 of file UN_DataBuffer.h.

Member Function Documentation

template<typename T>
void UN_DataBuffer< T >::addData ( UN_DataIndex  index,
const T init_value = T() 
)
inline

Adds an entry slot to the data buffer.

Definition at line 74 of file UN_DataBuffer.h.

template<typename T>
void UN_DataBuffer< T >::appendData ( const T value,
exint  count 
)
inline

Appends count copies of the given value.

Definition at line 86 of file UN_DataBuffer.h.

template<typename T>
void UN_DataBuffer< T >::appendData ( const UN_DataBuffer< T > &  src,
UN_DataIndex  start,
UN_DataSize  size 
)
inline

Appends a span of entries from another buffer.

Definition at line 92 of file UN_DataBuffer.h.

template<typename T>
void UN_DataBuffer< T >::clear ( )
inline

Resets the data to an empty buffer.

Definition at line 102 of file UN_DataBuffer.h.

template<typename T>
const T& UN_DataBuffer< T >::getDataRef ( UN_DataIndex  index) const
inline

Returns the data value for the entry at a given index. Note, this buffer class does not provide a getter method that returns a mutable (non-const) reference to the underlying data to avoid aliasing, which is problematic for threading. However, it provides stealData() to move the value out of buffer.

Definition at line 51 of file UN_DataBuffer.h.

template<typename T>
bool UN_DataBuffer< T >::isValidIndex ( UN_DataIndex  index) const
inline

Return true if given index is valid.

Definition at line 115 of file UN_DataBuffer.h.

template<typename T>
const T& UN_DataBuffer< T >::operator[] ( UN_DataIndex  index) const
inline

Returns the data value for the entry at a given index. Note, this buffer class does not provide a getter method that returns a mutable (non-const) reference to the underlying data to avoid aliasing, which is problematic for threading. However, it provides stealData() to move the value out of buffer.

Definition at line 53 of file UN_DataBuffer.h.

template<typename T>
void UN_DataBuffer< T >::setCapacityIfNeeded ( UN_DataSize  min_capacity)
inline

Definition at line 111 of file UN_DataBuffer.h.

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

Sets the data value for the entry at a given index.

Definition at line 40 of file UN_DataBuffer.h.

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

Sets the data value for the entry at a given index.

Definition at line 42 of file UN_DataBuffer.h.

template<typename T>
UN_DataSize UN_DataBuffer< T >::size ( void  ) const
inline

Returns the number of elements held in the data buffer.

Definition at line 106 of file UN_DataBuffer.h.

template<typename T>
T UN_DataBuffer< T >::stealData ( UN_DataIndex  index)
inline

Returns a moved value from an entry in a data buffer.

Definition at line 58 of file UN_DataBuffer.h.

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

Updates a data entry value in-place inside the data buffer. For complex data types (eg, dictionaries or arrays) it is faster than getting and setting the value (although stealing and setting back a moved value is comparable). This is a convenient and useful idiom, that tries to avoid the buffer aliasing issues, that cause problems in multithreading. Intended usage: updateData(index, [&key, &value](auto &dict) { dict[key] = value; });

Definition at line 70 of file UN_DataBuffer.h.


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