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

#include <UN_Data.h>

+ Inheritance diagram for UN_Data:

Public Types

using IDRange = UN_DataIndexMap::IDRange
 Returns a range for iterating valid IDs. More...
 
using OrderedIDRange = UN_DataIndexMap::OrderedIDRange
 Returns a range for iterating valid IDs in an ascending order. More...
 

Public Member Functions

 UN_Data (UN_CustomDataPtr custom_data=UN_CustomDataPtr())
 Constructors and destructors. More...
 
 ~UN_Data ()=default
 
 UN_Data (UN_Data &&)
 Move operators. More...
 
UN_Dataoperator= (UN_Data &&)
 
IDRange idRange () const
 
OrderedIDRange orderedIDRange () const
 
UN_DataIDList dataIDs () const
 Returns a list of all the valid IDs in this container. More...
 
UN_DataIDList sortedDataIDs () const
 Returns a sorted list of all the valid IDs in this container. More...
 
UN_DataSize size () const
 Returns the number of valid data items in the buffer. More...
 
UN_DataSize indexSize () const
 
UN_DataSize idSize () const
 
template<typename D >
UN_GenericBufferID addGenericBuffer (const UT_StringRef &name, UN_GenericBufferType type, const D &default_value)
 
UN_GenericBufferType genericBufferType (UN_GenericBufferID id) const
 Returns the type of the generic buffer identified by the given ID. More...
 
UN_GenericBufferID findGenericBuffer (const UT_StringRef &name) const
 
const UT_StringHoldergenericBufferName (UN_GenericBufferID id) const
 Returns the name of the generic buffer identified by the given ID. More...
 
UN_CustomDatacustomData ()
 Returns the custom data container, if one was provided. More...
 
const UN_CustomDatacustomData () const
 Returns the custom data container, if one was provided. More...
 

Protected Member Functions

 UN_Data (const UN_Data &)
 
UN_Dataoperator= (const UN_Data &)
 
UN_DataMergeInfo mergeData (const UN_Data &src_data, bool combine_id_zero=false)
 
std::pair< UN_DataID,
UN_DataIndex
addData ()
 
std::pair< UN_DataID,
UN_DataIndex
findOrAddData (UN_DataID data_id)
 
bool removeData (UN_DataID data_id)
 
void removeAllData (bool reset_next_id)
 
bool isValid (UN_DataID data_id) const
 
UN_DataIndex dataIndex (UN_DataID id) const
 
UN_DataSize dataBufferSize () const
 
UN_DataSize freeDataBufferSize () const
 
UN_DataSize usedDataBufferSize () const
 
template<typename V , typename B >
void setData (B &buffer, UN_DataID id, const V &value)
 Helper method to copy-assign the value to an entry in the data buffer. More...
 
template<typename V , typename B >
void setData (B &buffer, UN_DataID id, V &&value)
 Helper method to move-assign the value to an entry in the data buffer. More...
 
template<typename V , typename B >
const V & getDataRef (const B &buffer, UN_DataID id, const V &default_value) const
 Helper method to return a const ref to an entry in the data buffer. More...
 
template<typename V , typename B >
getDataVal (const B &buffer, UN_DataID id, const V &default_value) const
 
template<typename V , typename B >
stealData (B &buffer, UN_DataID id, const V &default_value)
 Helper method to return a value moved from an entry in the data buffer. More...
 
template<typename OP , typename B >
void updateData (B &buffer, UN_DataID id, const OP &op)
 
template<typename T >
void setGenericData (UN_GenericBufferID buf_id, UN_DataID id, const T &value)
 Sets the data value in a generic buffer for a given data ID. More...
 
template<typename T >
void setGenericData (UN_GenericBufferID buf_id, UN_DataID id, T &&value)
 Sets the data value in a generic buffer via move. More...
 
template<typename T >
const TgenericDataRef (UN_GenericBufferID buf_id, UN_DataID id) const
 Returns a const ref to the data value in a generic buffer. More...
 
template<typename T >
T genericDataVal (UN_GenericBufferID buf_id, UN_DataID id) const
 
template<typename T >
T stealGenericData (UN_GenericBufferID buf_id, UN_DataID id)
 Moves the data value out of a generic buffer. More...
 
template<typename T , typename OP >
void updateGenericData (UN_GenericBufferID buf_id, UN_DataID id, const OP &op)
 Updates the data value in a generic buffer in-place via a callable. More...
 
void addGenericData (UN_DataIndex index)
 Adds a data slot at the given index to all generic buffers. More...
 
void clearGenericData (UN_DataIndex index)
 Clears the generic data at the given index to defaults. More...
 
void removeAllGenericData ()
 Removes all data from all generic buffers. More...
 
void setGenericDataCapacityIfNeeded (UN_DataSize min_capacity)
 Grows all generic buffers to the given minimum capacity. More...
 
void mergeGenericData (const UN_Data &src, const UN_DataMergeInfo &merge_info)
 Merges generic data from another UN_Data container. More...
 
bool isGenericDataSizeConsistent (UN_DataSize expected_size) const
 Returns true if all generic buffers have the expected size. More...
 

Detailed Description

A generic container of the data buffers.

NOTE: This class is generally not trivially relocatable, because it sets a pointer to its member (myIndexMap) on another member (myCustomData).

Definition at line 28 of file UN_Data.h.

Member Typedef Documentation

Returns a range for iterating valid IDs.

Definition at line 54 of file UN_Data.h.

Returns a range for iterating valid IDs in an ascending order.

Definition at line 59 of file UN_Data.h.

Constructor & Destructor Documentation

UN_Data::UN_Data ( UN_CustomDataPtr  custom_data = UN_CustomDataPtr())

Constructors and destructors.

UN_Data::~UN_Data ( )
default
UN_Data::UN_Data ( UN_Data &&  )

Move operators.

UN_Data::UN_Data ( const UN_Data )
protected

This container can have large data, so generally, forbid the costly copy operations to the public.

Member Function Documentation

std::pair< UN_DataID, UN_DataIndex > UN_Data::addData ( )
inlineprotected

Adds a slot for new data in the data buffers of this container, and returns the data ID by which this slot can be refered to, and also at which index in a buffer the data slot is expected to be. A slot usually corresponds to a concrete graph element (eg, a node), and data buffer slots store some info about it, (eg, a name or a type). NOTE: The derived classes must insert a corresponding entry in all of their data buffers, at the given index. The index can also be found by dataIndex(ID).

Definition at line 112 of file UN_Data.h.

template<typename D >
UN_GenericBufferID UN_Data::addGenericBuffer ( const UT_StringRef name,
UN_GenericBufferType  type,
const D &  default_value 
)
inline

Adds a new named generic 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 241 of file UN_Data.h.

void UN_Data::addGenericData ( UN_DataIndex  index)
inlineprotected

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

Definition at line 328 of file UN_Data.h.

void UN_Data::clearGenericData ( UN_DataIndex  index)
inlineprotected

Clears the generic data at the given index to defaults.

Definition at line 332 of file UN_Data.h.

UN_CustomData* UN_Data::customData ( )
inline

Returns the custom data container, if one was provided.

Definition at line 47 of file UN_Data.h.

const UN_CustomData* UN_Data::customData ( ) const
inline

Returns the custom data container, if one was provided.

Definition at line 49 of file UN_Data.h.

UN_DataSize UN_Data::dataBufferSize ( ) const
inlineprotected

Returns the size of the data buffers that use indexing based on the dataIndex() lookup call that maps IDs to indices. The size is the lagest index ever issued plus one. Ie, it is the number of data entries a buffer can currently hold.

Definition at line 154 of file UN_Data.h.

UN_DataIDList UN_Data::dataIDs ( ) const
inline

Returns a list of all the valid IDs in this container.

Definition at line 64 of file UN_Data.h.

UN_DataIndex UN_Data::dataIndex ( UN_DataID  id) const
inlineprotected

Returns the data index into the data buffer arrays (ie, arrays implemented and owned by the sub-classes). The data index locates a slot (entries in the data buffers) for the graph element (eg, for a node) by the given ID.

Definition at line 147 of file UN_Data.h.

UN_GenericBufferID UN_Data::findGenericBuffer ( const UT_StringRef name) const
inline

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

Definition at line 259 of file UN_Data.h.

std::pair< UN_DataID, UN_DataIndex > UN_Data::findOrAddData ( UN_DataID  data_id)
inlineprotected

Returns an existing data buffer index for the given data ID, if already exists in the container, or adds a new slot for the data and returns the newly created index for it.

Definition at line 119 of file UN_Data.h.

UN_DataSize UN_Data::freeDataBufferSize ( ) const
inlineprotected

Returns the number of free slots in the data buffer. Ie, the buffer consists of data entry slots that are either occupied or free, and this menthod returns the free slots count.

Definition at line 160 of file UN_Data.h.

const UT_StringHolder& UN_Data::genericBufferName ( UN_GenericBufferID  id) const
inline

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

Definition at line 266 of file UN_Data.h.

UN_GenericBufferType UN_Data::genericBufferType ( UN_GenericBufferID  id) const
inline

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

Definition at line 251 of file UN_Data.h.

template<typename T >
const T& UN_Data::genericDataRef ( UN_GenericBufferID  buf_id,
UN_DataID  id 
) const
inlineprotected

Returns a const ref to the data value in a generic buffer.

Definition at line 293 of file UN_Data.h.

template<typename T >
T UN_Data::genericDataVal ( UN_GenericBufferID  buf_id,
UN_DataID  id 
) const
inlineprotected

Returns a copy of a data value from a generic buffer. Useful when cannot call genericDataRef() for types that cannot return by reference (eg, bool with bit-packed UN_DataBuffer<bool>).

Definition at line 303 of file UN_Data.h.

template<typename V , typename B >
const V& UN_Data::getDataRef ( const B &  buffer,
UN_DataID  id,
const V &  default_value 
) const
inlineprotected

Helper method to return a const ref to an entry in the data buffer.

Definition at line 190 of file UN_Data.h.

template<typename V , typename B >
V UN_Data::getDataVal ( const B &  buffer,
UN_DataID  id,
const V &  default_value 
) const
inlineprotected

Helper method to return a value constructed from an entry in the data buffer. This is useful when the type returned here differs from the underlying entry type. In particular, this is needed for UN_BoolDataBuffer whose underlying entries are bits (for which we can't return a const reference) while here we are returning bool (byte).

Definition at line 204 of file UN_Data.h.

IDRange UN_Data::idRange ( ) const
inline

Definition at line 55 of file UN_Data.h.

UN_DataSize UN_Data::idSize ( ) const
inline

Returns the upper limit on the numerical value of the valid data IDs issued by this container. Ie, maximum ID plus one.

Definition at line 82 of file UN_Data.h.

UN_DataSize UN_Data::indexSize ( ) const
inline

Returns the upper limit on the valid indices issued by this container. Ie, maximum index value plus one.

Definition at line 77 of file UN_Data.h.

bool UN_Data::isGenericDataSizeConsistent ( UN_DataSize  expected_size) const
inlineprotected

Returns true if all generic buffers have the expected size.

Definition at line 352 of file UN_Data.h.

bool UN_Data::isValid ( UN_DataID  data_id) const
inlineprotected

Returns true if the given ID refers to a valid data slot (entries) in the data buffers. Eg, for node data buffers, if such a node exists and is valid.

Definition at line 140 of file UN_Data.h.

UN_DataMergeInfo UN_Data::mergeData ( const UN_Data src_data,
bool  combine_id_zero = false 
)
inlineprotected

Merges another data container into this one.

If fuse_id_zero is true, the data for the ID zero is not copied to a brand new data slot, but is combined with existing slot ID of zero. Some data containers (subclasses) use ID of zero for a special entity that is treated differently than the rest. Notably, the node data container uses ID of zero for the root node, and the root node from the src should not become a regular node here. Instead, src root ID maps to dst root ID and their data is combined.

Definition at line 95 of file UN_Data.h.

void UN_Data::mergeGenericData ( const UN_Data src,
const UN_DataMergeInfo merge_info 
)
inlineprotected

Merges generic data from another UN_Data container.

Definition at line 346 of file UN_Data.h.

UN_Data& UN_Data::operator= ( UN_Data &&  )
UN_Data& UN_Data::operator= ( const UN_Data )
protected
OrderedIDRange UN_Data::orderedIDRange ( ) const
inline

Definition at line 60 of file UN_Data.h.

void UN_Data::removeAllData ( bool  reset_next_id)
inlineprotected

Frees the data slots occupied by all the data.

Parameters
'reset_next_id'If true, the data ID generator is reset to zero.

Definition at line 133 of file UN_Data.h.

void UN_Data::removeAllGenericData ( )
inlineprotected

Removes all data from all generic buffers.

Definition at line 336 of file UN_Data.h.

bool UN_Data::removeData ( UN_DataID  data_id)
inlineprotected

Removes the data slot from this container and frees the slot it used to occupy. The slot may be reused in the future for other data item (but with different data ID). After calling this method the container will have no knowledge of the data by this ID. Returns true on successs; false if the data was not found.

Definition at line 128 of file UN_Data.h.

template<typename V , typename B >
void UN_Data::setData ( B &  buffer,
UN_DataID  id,
const V &  value 
)
inlineprotected

Helper method to copy-assign the value to an entry in the data buffer.

Definition at line 173 of file UN_Data.h.

template<typename V , typename B >
void UN_Data::setData ( B &  buffer,
UN_DataID  id,
V &&  value 
)
inlineprotected

Helper method to move-assign the value to an entry in the data buffer.

Definition at line 181 of file UN_Data.h.

template<typename T >
void UN_Data::setGenericData ( UN_GenericBufferID  buf_id,
UN_DataID  id,
const T value 
)
inlineprotected

Sets the data value in a generic buffer for a given data ID.

Definition at line 275 of file UN_Data.h.

template<typename T >
void UN_Data::setGenericData ( UN_GenericBufferID  buf_id,
UN_DataID  id,
T &&  value 
)
inlineprotected

Sets the data value in a generic buffer via move.

Definition at line 284 of file UN_Data.h.

void UN_Data::setGenericDataCapacityIfNeeded ( UN_DataSize  min_capacity)
inlineprotected

Grows all generic buffers to the given minimum capacity.

Definition at line 340 of file UN_Data.h.

UN_DataSize UN_Data::size ( void  ) const
inline

Returns the number of valid data items in the buffer.

Definition at line 72 of file UN_Data.h.

UN_DataIDList UN_Data::sortedDataIDs ( ) const
inline

Returns a sorted list of all the valid IDs in this container.

Definition at line 68 of file UN_Data.h.

template<typename V , typename B >
V UN_Data::stealData ( B &  buffer,
UN_DataID  id,
const V &  default_value 
)
inlineprotected

Helper method to return a value moved from an entry in the data buffer.

Definition at line 213 of file UN_Data.h.

template<typename T >
T UN_Data::stealGenericData ( UN_GenericBufferID  buf_id,
UN_DataID  id 
)
inlineprotected

Moves the data value out of a generic buffer.

Definition at line 311 of file UN_Data.h.

template<typename OP , typename B >
void UN_Data::updateData ( B &  buffer,
UN_DataID  id,
const OP &  op 
)
inlineprotected

Helper method to update an entry value in the data buffer. It updates a data value in-place in the data buffer, which for complex data values (eg, dictionaries or arrays) is faster than getting and setting the value (although stealing and setting may be comparable). This is a convenient and useful idiom, that tries to avoid the buffer data aliasing issues. Intended usage: updateData(buff, id, [&key, &value](auto &x) { x[key] = value; });

Definition at line 229 of file UN_Data.h.

template<typename T , typename OP >
void UN_Data::updateGenericData ( UN_GenericBufferID  buf_id,
UN_DataID  id,
const OP &  op 
)
inlineprotected

Updates the data value in a generic buffer in-place via a callable.

Definition at line 319 of file UN_Data.h.

UN_DataSize UN_Data::usedDataBufferSize ( ) const
inlineprotected

Returns the number of valid data entries in the data buffer. Ie, the buffer consists of data entry slots that are either occupied or free, and this menthod returns the occupied slots count.

Definition at line 166 of file UN_Data.h.


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