12 #ifndef __UN_NodeData_h__
13 #define __UN_NodeData_h__
79 void merge( UN_NodeID node_id,
95 UN_NodeID findOrAddRootNode();
103 void clearNode( UN_NodeID node_id );
109 bool removeNode( UN_NodeID node_id );
113 void removeAllNodes(
bool reset_next_id );
133 {
return UN_NodeID( UN_DataIndexMap::IDIterator::operator*() ); }
147 {
return UN_NodeID( UN_DataIndexMap::OrderedIDIterator::operator*() ); }
167 reinterpret_cast<UN_NodeIDList&&
>( std::move(
dataIDs() ));
168 node_ids.findAndRemove( UN_ROOT_NODE_ID );
178 reinterpret_cast<UN_NodeIDList&&
>( std::move(
sortedDataIDs() ));
179 node_ids.findAndRemove( UN_ROOT_NODE_ID );
190 || UN_Utils::isValidNodeName( name, myNodeNameSafeChars ));
191 setData( myName, node_id, name );
202 UT_ASSERT( UN_Utils::isValidCategoryName( category_name ));
203 setData( myCategoryName, node_id, category_name );
210 setData( mySignatureName, node_id, signature_name );
225 setData( myTypeName, node_id, type_name );
245 return getDataRef( mySignatureName, node_id, theDefSignatureName );
251 setData( myComment, node_id, comment );
257 return getDataRef( myComment, node_id, theDefComment );
263 setData( myPosition, node_id, position );
269 return getDataRef( myPosition, node_id, theDefPos );
275 setData( myColor, node_id, color );
281 return getDataRef( myColor, node_id, theDefColor );
296 template <
typename OP>
305 setData( myTags, node_id, tags );
311 setData( myTags, node_id, std::move(tags) );
317 return getDataRef( myTags, node_id, theDefTags );
323 return stealData( myTags, node_id, theDefTags );
328 template <
typename OP>
351 setData( myMetadata, node_id, metadata );
357 setData( myMetadata, node_id, std::move(metadata) );
363 return getDataRef( myMetadata, node_id, theDefMetadata );
369 return stealData( myMetadata, node_id, theDefMetadata );
379 const D &default_value )
399 UN_NodeID node_id )
const
400 {
return UN_Data::genericDataRef<T>( buf_id, node_id ); }
405 {
return UN_Data::genericDataVal<T>( buf_id, node_id ); }
411 {
return UN_Data::stealGenericData<T>( buf_id, node_id ); }
414 template<
typename T,
typename OP>
417 { UN_Data::updateGenericData<T>( buf_id, node_id,
op ); }
422 { myCheckValidNodeNames = flag; }
426 { myNodeNameSafeChars = safe_chars; }
447 UN_NodeID addNodeData( UN_NodeID node_id, UN_NodeIndex node_index );
455 void addCoreData( UN_NodeIndex node_index );
458 void clearCoreData( UN_NodeIndex node_index );
462 void removeCoreData()
467 void removeAllCoreData();
470 void setCoreDataCapacityIfNeeded(
UN_DataSize min_capacity );
473 bool isCoreDataSizeConsistent(
UN_DataSize expected_size )
const;
474 bool isCoreDataSizeConsistent()
const
475 {
return isCoreDataSizeConsistent( myName.size() ); }
479 bool isDataSizeConsistent()
const;
530 bool myCheckValidNodeNames =
false;
UN_GenericBufferType
Supported types for generic data buffers.
UT_UniquePtr< UN_CustomNodeData > UN_CustomNodeDataPtr
void setMetadata(UN_NodeID node_id, const UN_MetadataHolder &metadata)
Sets node's new metadata via copy-assignment.
#define SYS_STATIC_ASSERT(expr)
void updateMetadata(UN_NodeID node_id, const OP &op)
const UT_StringHolder & signatureName(UN_NodeID node_id) const
Returns the node's signature.
const UT_Vector2D & position(UN_NodeID node_id) const
Returns the node's location in the graph editor.
UN_NodeIndex nodeIndex(UN_NodeID id) const
Returns the node's data index into the data buffer arrays.
const T & genericDataRef(UN_GenericBufferID buf_id, UN_NodeID node_id) const
Returns a const ref to the data value in a generic buffer.
UN_GenericNodeDataBufferRef addGenericNodeDataBuffer(const UT_StringRef &name, UN_GenericBufferType type, const D &default_value)
void setSignatureName(UN_NodeID node_id, const UT_StringRef &signature_name)
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.
UT_Vector2T< fpreal64 > UT_Vector2D
const UT_StringHolder & categoryName(UN_NodeID node_id) const
GLsizei const GLfloat * value
bool isValid(UN_DataID data_id) const
void setPosition(UN_NodeID node_id, const UT_Vector2D &position)
Sets the node's location in the graph editor.
UN_MetadataHolder stealMetadata(UN_NodeID node_id)
Returns node's metadata moved from the data buffer entry.
void setOption(const UT_StringHolder &name, UT_OptionEntryPtr value)
const UN_CustomNodeData * customNodeData() const
Returns node's custom data container, if one was provided.
static const UN_MetadataHolder theDefMetadata
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Iterator for traversing valid node IDs in an ascending order.
Iterator for traversing valid data IDs in the map.
UN_Data & operator=(UN_Data &&)
T stealGenericData(UN_GenericBufferID buf_id, UN_NodeID node_id)
Moves the data value out of a generic buffer.
UN_CustomNodeData * customNodeData()
Returns node's custom data container, if one was provided.
value_type operator*() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
void setTags(UN_NodeID node_id, UT_StringArray &&tags)
Sets new tags on a node via move-assignment.
UN_DataIndex dataIndex(UN_DataID id) const
void setCategoryName(UN_NodeID node_id, const UT_StringRef &category_name)
GLint GLint GLsizei GLint GLenum GLenum type
V stealData(B &buffer, UN_DataID id, const V &default_value)
Helper method to return a value moved from an entry in the data buffer.
void update(const OP &op)
T genericDataVal(UN_GenericBufferID buf_id, UN_NodeID node_id) const
Returns a copy of a data value from a generic buffer.
UN_NodeIDList nodeIDs() const
UN_CustomData * customData()
Returns the custom data container, if one was provided.
static const UT_StringHolder theDefComment
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.
static const UT_StringHolder theEmptyString
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:int{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
void setCheckValidNodeNames(bool flag)
Asserts that the node names are alphanumeric.
void updateMetadata(UN_NodeID node_id, const UT_StringHolder &key, UT_OptionEntryPtr &&value)
Simpler method to update a single metadata value in-place.
void setTypeName(UN_NodeID node_id, const UT_StringRef &type_name)
Sets the node's type that determines its functional behavour.
UN_DataIDList dataIDs() const
Returns a list of all the valid IDs in this container.
OrderedIDIterator(const UN_DataIndexMap::OrderedIDIterator &id_iterator)
bool isValid(UN_NodeID node_id) const
IDIterator(const UN_DataIndexMap::IDIterator &id_iterator)
value_type operator*() const
GLuint const GLchar * name
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.
UN_API UN_OptionsPtr asOptions(const UN_GraphData *graph_data)
void updateData(B &buffer, UN_DataID id, const OP &op)
void updateTags(UN_NodeID node_id, const OP &op)
UT_StringArray stealTags(UN_NodeID node_id)
Returns node tags moved from the data buffer entry.
Maintains a mapping from data ID to data index in the data buffer.
Iterator for traversing valid node IDs.
A map of string to various well defined value types.
const UT_StringHolder & name(UN_NodeID node_id) const
Returns the name that identifies the node among its siblings.
Iterator for traversing valid data IDs in the map in an ordered fashion.
void setNodeNameSafeChars(const UT_StringRef &safe_chars)
A set of additional characters that are legal in node names.
SIM_API const UT_StringHolder position
const UN_MetadataHolder & metadata(UN_NodeID node_id) const
Returns nodes's metadata.
void setData(B &buffer, UN_DataID id, const V &value)
Helper method to copy-assign the value to an entry in the data buffer.
void setGenericData(UN_GenericBufferID buf_id, UN_NodeID node_id, T &&value)
Sets the data value in a generic buffer via move.
void setColor(UN_NodeID node_id, const UT_Color &color)
Sets the node's color in the graph editor.
void setMetadata(UN_NodeID node_id, UN_MetadataHolder &&metadata)
Sets node's new metadata via move-assignment.
const UT_StringHolder & typeName(UN_NodeID node_id) const
Returns the name of node's type that determines its functional behavour.
void setComment(UN_NodeID node_id, const UT_StringRef &comment)
Sets the node's comment.
UN_DataSize size() const
Returns the number of valid data items in the buffer.
UN_DataIDList sortedDataIDs() const
Returns a sorted list of all the valid IDs in this container.
static const UT_StringArray theDefTags
const UT_Color & color(UN_NodeID node_id) const
Returns the node's color in the graph editor.
const UT_StringArray & tags(UN_NodeID node_id) const
Returns node tags.
UN_GenericBufferID addGenericBuffer(const UT_StringRef &name, UN_GenericBufferType type, const D &default_value)
const UT_StringHolder & comment(UN_NodeID node_id) const
Returns the node's comment.
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.
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
UN_NodeIDList sortedNodeIDs() const
void setTags(UN_NodeID node_id, const UT_StringArray &tags)
Sets new tags on a node via copy-assignment.
OrderedIDRange orderedIDRange() const
UT_UniquePtr< UN_Options > UN_OptionsPtr
void setName(UN_NodeID node_id, const UT_StringRef &name)
static const UT_StringHolder theDefSignatureName