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

#include <UN_NodeData.h>

+ Inheritance diagram for UN_NodeData:

Classes

class  IDIterator
 Iterator for traversing valid node IDs. More...
 
class  OrderedIDIterator
 Iterator for traversing valid node IDs in an ascending order. More...
 

Public Types

using IDRange = UT_IteratorRange< IDIterator >
 
using OrderedIDRange = UT_IteratorRange< OrderedIDIterator >
 
- Public Types inherited from UN_Data
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_NodeData (UN_CustomNodeDataPtr custom_data=UN_CustomNodeDataPtr())
 Constructors and destructors. More...
 
 ~UN_NodeData ()=default
 
 UN_NodeData (UN_NodeData &&)
 
UN_NodeDataoperator= (UN_NodeData &&)
 
void setCapacityIfNeeded (UN_DataSize min_capacity)
 
UN_NodeIDRemap merge (const UN_NodeData &src_node_data)
 
void merge (UN_NodeID node_id, const UN_Options &node_opts)
 
UN_OptionsPtr asOptions (UN_NodeID node_id) const
 
UN_NodeID addNode ()
 
UN_NodeID findOrAddRootNode ()
 Adds a root node to the container, or returns one if it already exists. More...
 
bool isValid (UN_NodeID node_id) const
 
IDRange idRange () const
 
OrderedIDRange orderedIDRange () const
 
UN_NodeIDList nodeIDs () const
 
UN_NodeIDList sortedNodeIDs () const
 
const UT_StringHoldername (UN_NodeID node_id) const
 Returns the name that identifies the node among its siblings. More...
 
void setTypeName (UN_NodeID node_id, const UT_StringRef &type_name)
 Sets the node's type that determines its functional behavour. More...
 
const UT_StringHoldertypeName (UN_NodeID node_id) const
 Returns the name of node's type that determines its functional behavour. More...
 
const UT_StringHoldercategoryName (UN_NodeID node_id) const
 
const UT_StringHoldersignatureName (UN_NodeID node_id) const
 Returns the node's signature. More...
 
void setComment (UN_NodeID node_id, const UT_StringRef &comment)
 Sets the node's comment. More...
 
const UT_StringHoldercomment (UN_NodeID node_id) const
 Returns the node's comment. More...
 
void setPosition (UN_NodeID node_id, const UT_Vector2D &position)
 Sets the node's location in the graph editor. More...
 
const UT_Vector2Dposition (UN_NodeID node_id) const
 Returns the node's location in the graph editor. More...
 
void setColor (UN_NodeID node_id, const UT_Color &color)
 Sets the node's color in the graph editor. More...
 
const UT_Colorcolor (UN_NodeID node_id) const
 Returns the node's color in the graph editor. More...
 
template<typename OP >
void updateTags (UN_NodeID node_id, const OP &op)
 
void setTags (UN_NodeID node_id, const UT_StringArray &tags)
 Sets new tags on a node via copy-assignment. More...
 
void setTags (UN_NodeID node_id, UT_StringArray &&tags)
 Sets new tags on a node via move-assignment. More...
 
const UT_StringArraytags (UN_NodeID node_id) const
 Returns node tags. More...
 
UT_StringArray stealTags (UN_NodeID node_id)
 Returns node tags moved from the data buffer entry. More...
 
template<typename OP >
void updateMetadata (UN_NodeID node_id, const OP &op)
 
void updateMetadata (UN_NodeID node_id, const UT_StringHolder &key, UT_OptionEntryPtr &&value)
 Simpler method to update a single metadata value in-place. More...
 
void setMetadata (UN_NodeID node_id, const UN_MetadataHolder &metadata)
 Sets node's new metadata via copy-assignment. More...
 
void setMetadata (UN_NodeID node_id, UN_MetadataHolder &&metadata)
 Sets node's new metadata via move-assignment. More...
 
const UN_MetadataHoldermetadata (UN_NodeID node_id) const
 Returns nodes's metadata. More...
 
UN_MetadataHolder stealMetadata (UN_NodeID node_id)
 Returns node's metadata moved from the data buffer entry. More...
 
template<typename D >
UN_GenericNodeDataBufferRef addGenericNodeDataBuffer (const UT_StringRef &name, UN_GenericBufferType type, const D &default_value)
 
template<typename T >
void setGenericData (UN_GenericBufferID buf_id, UN_NodeID node_id, const T &value)
 Sets the data value in a generic buffer for a given node. More...
 
template<typename T >
void setGenericData (UN_GenericBufferID buf_id, UN_NodeID node_id, T &&value)
 Sets the data value in a generic buffer via move. More...
 
template<typename T >
const TgenericDataRef (UN_GenericBufferID buf_id, UN_NodeID node_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_NodeID node_id) const
 Returns a copy of a data value from a generic buffer. More...
 
template<typename T >
T stealGenericData (UN_GenericBufferID buf_id, UN_NodeID node_id)
 Moves the data value out of a generic buffer. More...
 
template<typename T , typename OP >
void updateGenericData (UN_GenericBufferID buf_id, UN_NodeID node_id, const OP &op)
 Updates the data value in a generic buffer in-place via a callable. More...
 
void setCheckValidNodeNames (bool flag)
 Asserts that the node names are alphanumeric. More...
 
void setNodeNameSafeChars (const UT_StringRef &safe_chars)
 A set of additional characters that are legal in node names. More...
 
UN_CustomNodeDatacustomNodeData ()
 Returns node's custom data container, if one was provided. More...
 
const UN_CustomNodeDatacustomNodeData () const
 Returns node's custom data container, if one was provided. More...
 
- Public Member Functions inherited from UN_Data
 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...
 

Static Public Attributes

static const UT_StringHolder theDefSignatureName
 
static const UT_StringHolder theDefComment
 
static const UT_StringArray theDefTags
 
static const UN_MetadataHolder theDefMetadata
 
static const auto theDefColor = UT_Color( UT_RGB, 1.0F, 1.0F, 1.0F )
 
static const auto theDefPos = UT_Vector2D(0.0)
 

Protected Member Functions

 UN_NodeData (const UN_NodeData &)=default
 
UN_NodeDataoperator= (const UN_NodeData &)=default
 
void clearNode (UN_NodeID node_id)
 Clears the data for the given node to the default state. More...
 
bool removeNode (UN_NodeID node_id)
 
void removeAllNodes (bool reset_next_id)
 
void setName (UN_NodeID node_id, const UT_StringRef &name)
 
void setCategoryName (UN_NodeID node_id, const UT_StringRef &category_name)
 
void setSignatureName (UN_NodeID node_id, const UT_StringRef &signature_name)
 
UN_NodeIndex nodeIndex (UN_NodeID id) const
 Returns the node's data index into the data buffer arrays. More...
 
- Protected Member Functions inherited from UN_Data
 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...
 

Protected Attributes

friend UN_GraphData
 

Detailed Description

Container of data for all the nodes in the graph.

NOTE: This class is generally not trivially relocatable, because its base class (UN_Data) is not trivially relocatable (see comment there).

Definition at line 36 of file UN_NodeData.h.

Member Typedef Documentation

Returns a range for iterating valid node IDs. Does not include the root node.

Definition at line 153 of file UN_NodeData.h.

Returns a range for iterating valid node IDs. Does not include the root node.

Definition at line 158 of file UN_NodeData.h.

Constructor & Destructor Documentation

UN_NodeData::UN_NodeData ( UN_CustomNodeDataPtr  custom_data = UN_CustomNodeDataPtr())

Constructors and destructors.

UN_NodeData::~UN_NodeData ( )
default
UN_NodeData::UN_NodeData ( UN_NodeData &&  )
UN_NodeData::UN_NodeData ( const UN_NodeData )
protecteddefault

Member Function Documentation

template<typename D >
UN_GenericNodeDataBufferRef UN_NodeData::addGenericNodeDataBuffer ( const UT_StringRef name,
UN_GenericBufferType  type,
const D &  default_value 
)
inline

Adds a new named generic data buffer and returns a lightweight reference that bundles the buffer ID with this container.

Definition at line 377 of file UN_NodeData.h.

UN_NodeID UN_NodeData::addNode ( )

Adds a slot for a new node in this container. Returns an ID that should be used to refer to this new node for accessing its data (eg, name, label, etc).

UN_OptionsPtr UN_NodeData::asOptions ( UN_NodeID  node_id) const

Returns the options object representing node's properties, such as name, type, category, and also parameters and ports, but not the children. This can be then used for serialization to JSON, etc.

const UT_StringHolder& UN_NodeData::categoryName ( UN_NodeID  node_id) const
inline

Returns the node's category that groups it with other nodes that are operationally compatible (and connectable).

Definition at line 236 of file UN_NodeData.h.

void UN_NodeData::clearNode ( UN_NodeID  node_id)
protected

Clears the data for the given node to the default state.

const UT_Color& UN_NodeData::color ( UN_NodeID  node_id) const
inline

Returns the node's color in the graph editor.

Definition at line 279 of file UN_NodeData.h.

const UT_StringHolder& UN_NodeData::comment ( UN_NodeID  node_id) const
inline

Returns the node's comment.

Definition at line 255 of file UN_NodeData.h.

UN_CustomNodeData* UN_NodeData::customNodeData ( )
inline

Returns node's custom data container, if one was provided.

Definition at line 61 of file UN_NodeData.h.

const UN_CustomNodeData* UN_NodeData::customNodeData ( ) const
inline

Returns node's custom data container, if one was provided.

Definition at line 66 of file UN_NodeData.h.

UN_NodeID UN_NodeData::findOrAddRootNode ( )

Adds a root node to the container, or returns one if it already exists.

template<typename T >
const T& UN_NodeData::genericDataRef ( UN_GenericBufferID  buf_id,
UN_NodeID  node_id 
) const
inline

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

Definition at line 398 of file UN_NodeData.h.

template<typename T >
T UN_NodeData::genericDataVal ( UN_GenericBufferID  buf_id,
UN_NodeID  node_id 
) const
inline

Returns a copy of a data value from a generic buffer.

Definition at line 404 of file UN_NodeData.h.

IDRange UN_NodeData::idRange ( ) const
bool UN_NodeData::isValid ( UN_NodeID  node_id) const
inline

Returns true if the given ID refers to a valid node entry in the data buffers. Ie, such a node exists and is valid.

Definition at line 118 of file UN_NodeData.h.

UN_NodeIDRemap UN_NodeData::merge ( const UN_NodeData src_node_data)

Merges another node data container into this one. Returns a mapping between the data IDs in the merge source and destination (this) data buffers.

void UN_NodeData::merge ( UN_NodeID  node_id,
const UN_Options node_opts 
)

Sets the attributes of the node, based on the information given in the options dictionary. Leaves other attributes of this node intact.

const UN_MetadataHolder& UN_NodeData::metadata ( UN_NodeID  node_id) const
inline

Returns nodes's metadata.

Definition at line 361 of file UN_NodeData.h.

const UT_StringHolder& UN_NodeData::name ( UN_NodeID  node_id) const
inline

Returns the name that identifies the node among its siblings.

Definition at line 216 of file UN_NodeData.h.

UN_NodeIDList UN_NodeData::nodeIDs ( ) const
inline

Returns a list of all the valid node IDs in the graph. Does not include the root node.

Definition at line 163 of file UN_NodeData.h.

UN_NodeIndex UN_NodeData::nodeIndex ( UN_NodeID  id) const
inlineprotected

Returns the node's data index into the data buffer arrays.

Definition at line 430 of file UN_NodeData.h.

UN_NodeData& UN_NodeData::operator= ( UN_NodeData &&  )
UN_NodeData& UN_NodeData::operator= ( const UN_NodeData )
protecteddefault
OrderedIDRange UN_NodeData::orderedIDRange ( ) const
const UT_Vector2D& UN_NodeData::position ( UN_NodeID  node_id) const
inline

Returns the node's location in the graph editor.

Definition at line 267 of file UN_NodeData.h.

void UN_NodeData::removeAllNodes ( bool  reset_next_id)
protected

Frees the data slots occupied by all the nodes.

Parameters
'reset_next_id'If true, the node ID generator is reset to zero.
bool UN_NodeData::removeNode ( UN_NodeID  node_id)
protected

Removes the node from this container and frees the data slot it occupied. After calling this method, the container will have no knowledge of the node by this ID. Returns true on successs; false if the node was not found.

void UN_NodeData::setCapacityIfNeeded ( UN_DataSize  min_capacity)

Increases the capacity of the data buffer arrays to the given minimum, unless the capacity is already greater or equal to that minimum, in which case the capacity remains unchanged.

void UN_NodeData::setCategoryName ( UN_NodeID  node_id,
const UT_StringRef category_name 
)
inlineprotected

Sets the node's category that groups it with other nodes that are operationally compatible (and connectable). Only the friend UN_GraphData can call it because it makes little sense to change the category of a node without also changing the node type, the parent child type categories, and other aspects of the graph.

Definition at line 200 of file UN_NodeData.h.

void UN_NodeData::setCheckValidNodeNames ( bool  flag)
inline

Asserts that the node names are alphanumeric.

Definition at line 421 of file UN_NodeData.h.

void UN_NodeData::setColor ( UN_NodeID  node_id,
const UT_Color color 
)
inline

Sets the node's color in the graph editor.

Definition at line 273 of file UN_NodeData.h.

void UN_NodeData::setComment ( UN_NodeID  node_id,
const UT_StringRef comment 
)
inline

Sets the node's comment.

Definition at line 249 of file UN_NodeData.h.

template<typename T >
void UN_NodeData::setGenericData ( UN_GenericBufferID  buf_id,
UN_NodeID  node_id,
const T value 
)
inline

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

Definition at line 386 of file UN_NodeData.h.

template<typename T >
void UN_NodeData::setGenericData ( UN_GenericBufferID  buf_id,
UN_NodeID  node_id,
T &&  value 
)
inline

Sets the data value in a generic buffer via move.

Definition at line 392 of file UN_NodeData.h.

void UN_NodeData::setMetadata ( UN_NodeID  node_id,
const UN_MetadataHolder metadata 
)
inline

Sets node's new metadata via copy-assignment.

Definition at line 349 of file UN_NodeData.h.

void UN_NodeData::setMetadata ( UN_NodeID  node_id,
UN_MetadataHolder &&  metadata 
)
inline

Sets node's new metadata via move-assignment.

Definition at line 355 of file UN_NodeData.h.

void UN_NodeData::setName ( UN_NodeID  node_id,
const UT_StringRef name 
)
inlineprotected

Sets the node name that differentiates it among its siblings. Only the friend UN_GraphData can call it because it may need to enforce a unique node name.

Definition at line 187 of file UN_NodeData.h.

void UN_NodeData::setNodeNameSafeChars ( const UT_StringRef safe_chars)
inline

A set of additional characters that are legal in node names.

Definition at line 425 of file UN_NodeData.h.

void UN_NodeData::setPosition ( UN_NodeID  node_id,
const UT_Vector2D position 
)
inline

Sets the node's location in the graph editor.

Definition at line 261 of file UN_NodeData.h.

void UN_NodeData::setSignatureName ( UN_NodeID  node_id,
const UT_StringRef signature_name 
)
inlineprotected

Sets the node's signature. Node signature determines node inputs and outputs, and their types.

Definition at line 208 of file UN_NodeData.h.

void UN_NodeData::setTags ( UN_NodeID  node_id,
const UT_StringArray tags 
)
inline

Sets new tags on a node via copy-assignment.

Definition at line 303 of file UN_NodeData.h.

void UN_NodeData::setTags ( UN_NodeID  node_id,
UT_StringArray &&  tags 
)
inline

Sets new tags on a node via move-assignment.

Definition at line 309 of file UN_NodeData.h.

void UN_NodeData::setTypeName ( UN_NodeID  node_id,
const UT_StringRef type_name 
)
inline

Sets the node's type that determines its functional behavour.

Definition at line 223 of file UN_NodeData.h.

const UT_StringHolder& UN_NodeData::signatureName ( UN_NodeID  node_id) const
inline

Returns the node's signature.

Definition at line 243 of file UN_NodeData.h.

UN_NodeIDList UN_NodeData::sortedNodeIDs ( ) const
inline

Returns a list of all the valid node IDs in the graph. Does not include the root node.

Definition at line 174 of file UN_NodeData.h.

template<typename T >
T UN_NodeData::stealGenericData ( UN_GenericBufferID  buf_id,
UN_NodeID  node_id 
)
inline

Moves the data value out of a generic buffer.

Definition at line 410 of file UN_NodeData.h.

UN_MetadataHolder UN_NodeData::stealMetadata ( UN_NodeID  node_id)
inline

Returns node's metadata moved from the data buffer entry.

Definition at line 367 of file UN_NodeData.h.

UT_StringArray UN_NodeData::stealTags ( UN_NodeID  node_id)
inline

Returns node tags moved from the data buffer entry.

Definition at line 321 of file UN_NodeData.h.

const UT_StringArray& UN_NodeData::tags ( UN_NodeID  node_id) const
inline

Returns node tags.

Definition at line 315 of file UN_NodeData.h.

const UT_StringHolder& UN_NodeData::typeName ( UN_NodeID  node_id) const
inline

Returns the name of node's type that determines its functional behavour.

Definition at line 229 of file UN_NodeData.h.

template<typename T , typename OP >
void UN_NodeData::updateGenericData ( UN_GenericBufferID  buf_id,
UN_NodeID  node_id,
const OP &  op 
)
inline

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

Definition at line 415 of file UN_NodeData.h.

template<typename OP >
void UN_NodeData::updateMetadata ( UN_NodeID  node_id,
const OP &  op 
)
inline

Updates node tags in-place. Usage: updateMetadata(id, [&k, &v](auto &m) { m[k] = v); });

Definition at line 329 of file UN_NodeData.h.

void UN_NodeData::updateMetadata ( UN_NodeID  node_id,
const UT_StringHolder key,
UT_OptionEntryPtr &&  value 
)
inline

Simpler method to update a single metadata value in-place.

Definition at line 335 of file UN_NodeData.h.

template<typename OP >
void UN_NodeData::updateTags ( UN_NodeID  node_id,
const OP &  op 
)
inline

Updates the node tags in-place. Usage: updateTags(id, [&t](auto &tags) { tags.append(t); });

Definition at line 297 of file UN_NodeData.h.

Member Data Documentation

const auto UN_NodeData::theDefColor = UT_Color( UT_RGB, 1.0F, 1.0F, 1.0F )
inlinestatic

Definition at line 490 of file UN_NodeData.h.

const UT_StringHolder UN_NodeData::theDefComment
inlinestatic

Definition at line 487 of file UN_NodeData.h.

const UN_MetadataHolder UN_NodeData::theDefMetadata
inlinestatic

Definition at line 489 of file UN_NodeData.h.

const auto UN_NodeData::theDefPos = UT_Vector2D(0.0)
inlinestatic

Definition at line 491 of file UN_NodeData.h.

const UT_StringHolder UN_NodeData::theDefSignatureName
inlinestatic

Definition at line 486 of file UN_NodeData.h.

const UT_StringArray UN_NodeData::theDefTags
inlinestatic

Definition at line 488 of file UN_NodeData.h.

UN_GraphData
protected

This container can have large data, so generally, forbid the costly copy operations to the public. Knowledgable friends and derived classes can still use them.

Definition at line 50 of file UN_NodeData.h.


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