HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_Port.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UN_Port.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_Port_h__
13 #define __UN_Port_h__
14 
15 #include "UN_API.h"
16 #include "UN_Iterator.h"
17 #include "UN_Handle.h"
18 
19 
20 class UN_Node;
21 class UN_PortData;
22 template<typename> class UT_Array;
23 
24 
25 // ============================================================================
26 /// A light-weight handle for a port data object.
27 ///
28 /// The actual port data (UN_PortDataStruct) is owned and managed by UN_GraphData,
29 /// and UN_Port serves as a handle for clients to refer to that port data.
30 
31 class UN_API UN_Port : public UN_Handle
32 {
33 public:
34 
35  /// Convenience constructor for the port handle.
36  UN_Port( UN_GraphData *graph_data, UN_PortID port_id );
37 
38  /// @{ Default destructor, constructors and assignment operators.
39  UN_Port();
40  ~UN_Port();
41  UN_Port( const UN_Port & );
42  UN_Port( UN_Port && );
43  UN_Port& operator=( const UN_Port & );
44  UN_Port& operator=( UN_Port && );
45  /// @}
46 
47  /// @{ Returns true if the parameter exists; false otherwise.
48  bool isValid() const;
49  explicit operator bool() const
50  { return isValid(); }
51  /// @}
52 
53  /// @{ Comparison operators
54  bool operator==( const UN_Port &other ) const
55  { return UN_Handle::operator==( other ); }
56  bool operator!=( const UN_Port &other ) const
57  { return UN_Handle::operator!=( other ); }
58  /// @}
59 
60 
61  /// Returns the parent of this node.
62  UN_Node node() const;
63 
64  /// Returns the kind of a port. Ie, if a port is an input or an output.
65  UN_PortKind kind() const;
66 
67  /// Returns the name of the port.
68  UT_StringHolder name() const;
69 
70  /// Returns name of the type of the port.
71  UT_StringHolder typeName() const;
72 
73 
74  /// Connects this port to a source from which to obtain data or a value.
75  /// Returns the newly created connection wire (may be invalid, if error).
76  // TODO: FIXME: add a 'mode' parm to specify whether to replace, append, or
77  // prepend the new connection. Currently we replace.
78  UN_Wire connectSrcPort(
79  const UN_Port &src_port ) const;
80 
81  /// Disconnects this port from the given source.
82  void disconnectSrcPort(
83  const UN_Port &src_port ) const;
84 
85  /// Disconnect this port from all its connected sources.
86  void disconnectAllSrcPorts() const;
87 
88  /// Disconnect this port from all its connected destinations,
89  /// to which this port provides data.
90  void disconnectAllDstPorts() const;
91 
92 
93  /// Returns the wires connecting this port to its sources.
94  /// Ie, connection wires from which this port takes (receives) data.
95  UT_Array<UN_Wire> srcWires() const;
96 
97  /// Returns the wires connecting this port to its destinations.
98  /// Ie, connection wires to which this port provides (sends) data.
99  UT_Array<UN_Wire> dstWires() const;
100 
101  /// Returns the first source port connected to this port.
102  /// May return an invalid port if no source port is connected.
103  /// This is a convenience method for very common graphs,
104  /// where ports can have at most one source.
105  UN_Port srcPort() const;
106 
107 
108  /// And iterator and a range for iterating over connected source ports.
109  using SrcPortIterator = UN_WireArrayPortIterator< /*src=*/ true >;
111 
112  /// Returns a range for iterating over this port's source ports.
113  SrcPortRange srcPortRange() const;
114 
115 
116  /// And iterator and a range for iterating over connected destination ports.
117  using DstPortIterator = UN_WireArrayPortIterator< /*src=*/ false >;
119 
120  /// Returns a range for iterating over this port's destination ports.
121  DstPortRange dstPortRange() const;
122 
123 
124  /// Deletes this port.
125  void destroy() const;
126 
127  /// Returns the unique ID of the port data this handle refers to.
128  UN_PortID portID() const
129  { return UN_PortID( dataID() ); }
130 protected:
131  /// The port data container for all the ports in the graph.
132  UN_PortData * portData() const;
133 };
134 
135 
136 #endif
137 
UN_PortKind
Differentiates between input and output ports.
Definition: UN_Types.h:308
UN_DataID dataID() const
Definition: UN_Handle.h:66
#define UN_API
Definition: UN_API.h:11
bool operator==(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:50
bool operator!=(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:56
UN_Handle & operator=(const UN_Handle &)=default
Default destructor, constructors and assignment operators.
UN_PortID portID() const
Returns the unique ID of the port data this handle refers to.
Definition: UN_Port.h:128
bool operator==(const UN_Port &other) const
Comparison operators.
Definition: UN_Port.h:54
bool operator!=(const UN_Port &other) const
Comparison operators.
Definition: UN_Port.h:56