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 template<typename> class UT_Array;
22 
23 
24 // ============================================================================
25 /// A light-weight handle for a port data object.
26 ///
27 /// The actual port data (UN_PortData) is owned and managed by UN_GraphData,
28 /// and UN_Port serves as a handle for clients to refer to that port data.
29 
30 class UN_API UN_Port : public UN_Handle
31 {
32 public:
33 
34  /// Convenience constructor for the port handle.
35  UN_Port( UN_GraphData *graph_data,
36  UN_PortIndex port_index,
37  UN_PortID port_id );
38 
39  /// @{ Default destructor, constructors and assignment operators.
40  UN_Port();
41  ~UN_Port();
42  UN_Port( const UN_Port & );
43  UN_Port( UN_Port && );
44  UN_Port& operator=( const UN_Port & );
45  UN_Port& operator=( UN_Port && );
46  /// @}
47 
48  /// @{ Returns true if the parameter exists; false otherwise.
49  bool isValid() const;
50  explicit operator bool() const
51  { return isValid(); }
52  /// @}
53 
54  /// @{ Comparison operators
55  bool operator==( const UN_Port &other ) const
56  { return UN_Handle::operator==( other ); }
57  bool operator!=( const UN_Port &other ) const
58  { return UN_Handle::operator!=( other ); }
59  /// @}
60 
61 
62  /// Returns the parent of this node.
63  UN_Node node() const;
64 
65  /// Returns the kind of a port. Ie, if a port is an input or an output.
66  UN_PortKind kind() const;
67 
68  /// Returns the name of the port.
69  UT_StringHolder name() const;
70 
71  /// Returns name of the type of the port.
72  UT_StringHolder typeName() const;
73 
74 
75  /// Connects this port to a source from which to obtain data or a value.
76  /// Returns the newly created connection wire (may be invalid, if error).
77  // TODO: FIXME: add a 'mode' parm to specify whether to replace, append, or
78  // prepend the new connection. Currently we replace.
79  UN_Wire connectSource(
80  const UN_Port &src_port ) const;
81 
82  /// Disconnects this port from the given source.
83  void disconnectSource(
84  const UN_Port &src_port ) const;
85 
86  /// Disconnect this port from all its connected sources.
87  void disconnectSources() const;
88 
89  /// Disconnect this port from all its connected destinations,
90  /// to which this port provides data.
91  void disconnectDestinations() const;
92 
93 
94  /// Returns the wires connecting this port to its sources.
95  /// Ie, connection wires from which this port takes (receives) data.
96  UT_Array<UN_Wire> sourceWires() const;
97 
98  /// Returns the wires connecting this port to its destinations.
99  /// Ie, connection wires to which this port provides (sends) data.
100  UT_Array<UN_Wire> destinationWires() const;
101 
102  /// Returns the first source port connected to this port.
103  /// May return an invalid port if no source port is connected.
104  /// This is a convenience method for very common graphs,
105  /// where ports can have at most one source.
106  UN_Port sourcePort() const;
107 
108 
109  /// And iterator and a range for iterating over connected source ports.
112 
113  /// Returns a range for iterating over this port's source ports.
114  SourcePortRange sourcePortRange() const;
115 
116 
117  /// And iterator and a range for iterating over connected destination ports.
120 
121  /// Returns a range for iterating over this port's destination ports.
122  DestinationPortRange destinationPortRange() const;
123 
124 
125  /// Deletes this port.
126  void destroy() const;
127 
128  /// Returns the port data index this handle refers to.
130  { return UN_PortIndex( dataIndex() ); }
131 
132  /// Returns the unique ID of the port data this handle refers to.
134  { return UN_PortID( dataID() ); }
135 };
136 
137 
138 #endif
139 
UN_PortKind
Differentiates input node ports from output node ports.
Definition: UN_Types.h:322
UN_DataID dataID() const
The unique ID of a data object during the lifespan of the owner graph.
Definition: UN_Handle.h:74
UN_PortIndex portIndex() const
Returns the port data index this handle refers to.
Definition: UN_Port.h:129
#define UN_API
Definition: UN_API.h:11
bool operator==(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:53
UN_DataIndex dataIndex() const
Definition: UN_Handle.h:70
bool operator!=(const UN_Handle &other) const
Comparison operators.
Definition: UN_Handle.h:60
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:133
A port ID.
Definition: UN_Types.h:297
bool operator==(const UN_Port &other) const
Comparison operators.
Definition: UN_Port.h:55
bool operator!=(const UN_Port &other) const
Comparison operators.
Definition: UN_Port.h:57