12 #ifndef __UN_PortUtils_h__
13 #define __UN_PortUtils_h__
21 namespace UN_PortUtils
27 return graph_data && graph_data->
isValid( port_id );
32 deletePort(
UN_GraphData *graph_data, UN_PortID port_id )
34 if(
isValid( graph_data, port_id ))
40 portKind(
const UN_GraphData *graph_data, UN_PortID port_id )
58 name(
const UN_GraphData *graph_data, UN_PortID port_id )
67 setTypeName(
UN_GraphData *graph_data, UN_PortID port_id,
76 typeName(
const UN_GraphData *graph_data, UN_PortID port_id )
121 stealTags(
UN_GraphData *graph_data, UN_PortID port_id )
131 template <
typename OP>
133 updateTags(
UN_GraphData *graph_data, UN_PortID port_id,
const OP &
op )
141 tags(
const UN_GraphData *graph_data, UN_PortID port_id )
155 UN_PortID src_port_id, UN_PortID dst_port_id );
159 static inline const UN_WireIDList &
162 static const UN_WireIDList theEmptyList;
164 return isValid( graph_data, dst_port_id )
165 ? graph_data->
srcWires( dst_port_id )
171 static inline const UN_WireIDList &
174 static const UN_WireIDList theEmptyList;
176 return isValid( graph_data, src_port_id )
177 ? graph_data->
dstWires( src_port_id )
203 srcWireCount(
const UN_GraphData *graph_data, UN_PortID dst_port_id )
212 dstWireCount(
const UN_GraphData *graph_data, UN_PortID src_port_id )
222 wireCount(
const UN_GraphData *graph_data, UN_PortID port_id )
226 graph_data->
dstWires( port_id ).size() )
232 srcPortCount(
const UN_GraphData *graph_data, UN_PortID dst_port_id )
234 return srcWireCount( graph_data, dst_port_id );
239 dstPortCount(
const UN_GraphData *graph_data, UN_PortID src_port_id )
241 return dstWireCount( graph_data, src_port_id );
247 portCount(
const UN_GraphData *graph_data, UN_PortID port_id )
249 return wireCount( graph_data, port_id );
277 template <
bool IS_SOURCE_ITERATOR>
289 const UN_WireIDList::const_iterator &wire_id_iterator )
290 : myGraphData( graph_data )
291 , myWireIDIterator( wire_id_iterator )
297 return myWireIDIterator == other.myWireIDIterator
298 && myGraphData == other.myGraphData;
319 if constexpr (IS_SOURCE_ITERATOR)
320 return myGraphData->
srcPort( *myWireIDIterator );
322 return myGraphData->
dstPort( *myWireIDIterator );
336 UN_WireIDList::const_iterator myWireIDIterator;
377 return srcPortCount( graph_data, dst_port_id ) > 0;
384 UN_PortID src_port_id )
387 if( p == src_port_id )
397 return dstPortCount( graph_data, src_port_id ) > 0;
404 UN_PortID dst_port_id )
407 if( p == dst_port_id )
425 UN_PortID port_id, UN_PortID src_or_dst_port_id )
const UT_StringHolder & typeName(UN_PortID port_id) const
Returns the name of the port's type.
UN_API WireRange dstWireRange(const UN_GraphData *graph_data, UN_PortID src_port_id)
GLuint GLsizei const GLchar * label
UT_StringArray stealTags(UN_PortID port_id)
Returns port's tags moved from the data buffer entry.
__hostdev__ bool isValid(GridType gridType, GridClass gridClass)
return true if the combination of GridType and GridClass is valid.
UN_API UN_WireID srcWire(const UN_GraphData *graph_data, UN_PortID dst_port_id)
PortIterator(const UN_GraphData *graph_data, const UN_WireIDList::const_iterator &wire_id_iterator)
Constructor for the start iterator.
UN_API WireRange srcWireRange(const UN_GraphData *graph_data, UN_PortID dst_port_id)
void setTags(UN_PortID port_id, const UT_StringArray &tags)
Sets new tags on a port via copy-assignment.
std::ptrdiff_t difference_type
const UT_StringHolder & name(UN_PortID port_id) const
Returns the port name that identifies it on the node.
void setTypeName(UN_PortID port_id, const UT_StringRef &type_name)
Sets the name of the port's type.
void deletePort(UN_PortID port)
Deletes the port.
bool operator!=(const PortIterator &other) const
Inequality comparison operator.
static const UT_StringArray theDefTags
UN_WireIDList::const_iterator WireIterator
UN_API SrcPortRange srcPortRange(const UN_GraphData *graph_data, UN_PortID dst_port_id)
UN_PortID operator*() const
Returns the current port ID.
bool isValid(UN_NodeID node) const
void updateTags(UN_PortID port_id, const OP &op)
bool operator==(const PortIterator &other) const
Equality comparison operator.
void setPortName(UN_PortID port_id, const UT_StringRef &name)
Sets the name of the given port.
UN_PortKind kind(UN_PortID port_id) const
Returns the port's kind indicating whether it is an input or an output.
UN_API UN_WireID connectPorts(UN_GraphData *graph_data, UN_PortID src_port_id, UN_PortID dst_port_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.
const UN_WireIDList & dstWires(UN_PortID port) const
UNI_PortKind
Specifies the port kind, ie, wheter it is an input or an output port.
UN_API UN_WireID dstWire(const UN_GraphData *graph_data, UN_PortID src_port_id)
void setLabel(UN_PortID port_id, const UT_StringRef &label)
Sets the port's label.
UN_API bool isConnectedToSrc(const UN_GraphData *dst_graph_data, UN_PortID dst_port_id, const UN_ConstPort &src_port)
const UN_GraphData * graph() const
Returns the underlying graph in which the current node exists.
GLuint const GLchar * name
UN_API UN_PortIDList dstPorts(const UN_GraphData *graph_data, UN_PortID src_port_id)
UN_API bool isConnectedToDst(const UN_GraphData *src_graph_data, UN_PortID src_port_id, const UN_ConstPort &dst_port)
UN_API UN_PortID srcPort(const UN_GraphData *graph_data, UN_PortID dst_port_id)
UN_PortID srcPort(UN_WireID wire) const
const UN_WireIDList & srcWires(UN_PortID port) const
UN_API DstPortRange dstPortRange(const UN_GraphData *graph_data, UN_PortID src_port_id)
const UT_StringArray & tags(UN_PortID port_id) const
Returns port's tags.
UN_PortData & portData()
Returns the container of data for the ports in the graph.
const UT_StringHolder & label(UN_PortID port_id) const
Returns the port's label.
UN_API UN_WireIDList srcWires(const UN_GraphData *graph_data, UN_NodeID node_id, UN_PortKind port_kind)
UN_API UN_PortID dstPort(const UN_GraphData *graph_data, UN_PortID src_port_id)
UN_API bool isConnected(const UN_GraphData *graph_data, UN_PortID port_id, const UN_ConstPort &src_or_dst_port)
PortIterator & operator++()
Increment operator.
UN_PortID dstPort(UN_WireID wire) const
std::input_iterator_tag iterator_category
UN_API UN_WireIDList dstWires(const UN_GraphData *graph_data, UN_NodeID node_id, UN_PortKind port_kind)
UN_API UN_PortIDList srcPorts(const UN_GraphData *graph_data, UN_PortID dst_port_id)