HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_Wire.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_Wire.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_Wire_h__
13 #define __UN_Wire_h__
14 
15 #include "UN_API.h"
16 #include "UN_Handle.h"
17 #include "UN_Port.h"
18 #include "UN_WireUtils.h"
19 
20 class UN_ConstGraph;
21 class UN_Graph;
22 
23 
24 // ============================================================================
25 /// Base class template for the UN wire handle.
26 /// Its main purpose is to factor common code for const and non-const handles.
27 template <typename BASE_CLASS, // class to derive from
28  typename GRAPH_DATA, // UN_GraphData or const UN_GraphData
29  typename PORT> // Port handle class (UN_Port or UN_ConstPort)
30 class UN_WireBase : public BASE_CLASS
31 {
32 protected:
33  /// Constructs a handle for an invalid wire.
34  UN_WireBase() = default;
35 
36  /// Constructs a handle that references the given wire in the given graph.
37  UN_WireBase( GRAPH_DATA *graph_data, UN_WireID wire_id )
38  : BASE_CLASS( graph_data, wire_id )
39  {}
40 
41 public:
42  /// @{ Returns the owner of the underlying graph data structures.
43  GRAPH_DATA * graphData() const
44  { return BASE_CLASS::graphData(); }
45  const UN_GraphData * constGraphData() const
46  { return BASE_CLASS::constGraphData(); }
47  /// @}
48 
49  /// Returns the unique ID of the wire this handle refers to.
50  UN_WireID wireID() const
51  { return UN_WireID( BASE_CLASS::dataID() ); }
52 
53  /// @{ Returns true if this wire is valid within the graph; false otherwise.
54  bool isValid() const
55  { return UN_WireUtils::isValid(
56  graphData(), wireID());
57  }
58 
59  explicit operator bool() const
60  { return isValid(); }
61  /// @}
62 
63  /// Returns the source port of this wire.
64  /// Ie, port that produces and sends the data.
65  PORT srcPort() const
66  {
67  return PORT( graphData(),
68  UN_WireUtils::srcPort( graphData(), wireID() ));
69  }
70 
71  /// Returns the destination port of this wire.
72  /// Ie, port that receives and consumes the data.
73  PORT dstPort() const
74  {
75  return PORT( graphData(),
76  UN_WireUtils::dstPort( graphData(), wireID() ));
77  }
78 };
79 
80 // ============================================================================
81 /// A handle that references a mutable wire in a graph.
82 /// It abstracts the APIs that operate on this wire's data stored inside
83 /// graph's data containers.
84 /// It is a non-const (read-write) handle, so allows both queries
85 /// and mutations of the wire's data.
86 class UN_API UN_Wire : public UN_WireBase< UN_Handle,
87  UN_GraphData, UN_Port >
88 {
89 public:
90  /// Constructs a handle for an invalid wire.
91  UN_Wire() = default;
92 
93  /// Constructs a handle referencing the given wire in the given graph.
94  UN_Wire( UN_GraphData *graph_data, UN_WireID wire_id )
95  : UN_WireBase( graph_data, wire_id )
96  {}
97 
98  /// @{ Comparison operators.
99  // Allows comparing wire handles, but guards against
100  // comparing wires to ports, for example.
101  bool operator==( const UN_Wire &other ) const
102  { return UN_ConstHandle::operator==( other ); }
103  bool operator!=( const UN_Wire &other ) const
104  { return UN_ConstHandle::operator!=( other ); }
105  /// @}
106 
107  /// Returns the graph whithin which this wire exists.
108  UN_Graph graph() const;
109 };
110 
111 
112 // ============================================================================
113 /// A handle that references a const wire in a graph.
114 /// It abstracts the APIs that operate on this wire's data stored inside
115 /// graph's data containers.
116 /// It is a constant handle, so allows only queries of the wire's data,
117 /// and does not allow setting any new values for.
118 class UN_API UN_ConstWire : public UN_WireBase< UN_ConstHandle,
119  const UN_GraphData, UN_ConstPort >
120 {
121 public:
122  /// Constructs a handle for an invalid wire.
123  UN_ConstWire() = default;
124 
125  /// Constructs a handle referencing the given wire in the given graph.
126  UN_ConstWire( const UN_GraphData *graph_data, UN_WireID wire_id )
127  : UN_WireBase( graph_data, wire_id )
128  {}
129 
130  /// Constructs a const handle from a mutable wire handle.
131  UN_ConstWire( const UN_Wire &wire )
132  : UN_ConstWire( wire.constGraphData(), wire.wireID() )
133  {}
134 
135  /// @{ Comparison operators.
136  // Allows comparing wire handles, but guards against
137  // comparing wires to wires, for example.
138  bool operator==( const UN_ConstWire &other ) const
139  { return UN_ConstHandle::operator==( other ); }
140  bool operator!=( const UN_ConstWire &other ) const
141  { return UN_ConstHandle::operator!=( other ); }
142  /// @}
143 
144 
145  /// Returns the graph whithin which this wire exists.
146  UN_ConstGraph graph() const;
147 };
148 
149 // ============================================================================
150 // Free functions to compare a non-const wire handle to a const wire handle.
151 // Note, the const to non-const comparison is covered by implicit conversion
152 // of non-const handle to const handle, and using const to const handle comp.
153 static inline bool
154 operator==( const UN_Wire &a, const UN_ConstWire &b )
155 {
156  return b == UN_ConstWire(a);
157 }
158 
159 static inline bool
160 operator!=( const UN_Wire &a, const UN_ConstWire &b )
161 {
162  return !(b == a);
163 }
164 
165 // ============================================================================
166 #endif
167 
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
bool operator==(const UN_ConstWire &other) const
Comparison operators.
Definition: UN_Wire.h:138
#define UN_API
Definition: UN_API.h:11
PORT dstPort() const
Definition: UN_Wire.h:73
OutGridT const XformOp bool bool
UN_ConstWire(const UN_GraphData *graph_data, UN_WireID wire_id)
Constructs a handle referencing the given wire in the given graph.
Definition: UN_Wire.h:126
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
PORT srcPort() const
Definition: UN_Wire.h:65
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
bool operator!=(const UN_ConstWire &other) const
Comparison operators.
Definition: UN_Wire.h:140
bool isValid() const
Returns true if this wire is valid within the graph; false otherwise.
Definition: UN_Wire.h:54
UN_ConstWire(const UN_Wire &wire)
Constructs a const handle from a mutable wire handle.
Definition: UN_Wire.h:131
bool operator!=(const UN_ConstHandle &other) const
Definition: UN_Handle.h:68
bool operator==(const UN_ConstHandle &other) const
Definition: UN_Handle.h:59
UN_WireBase(GRAPH_DATA *graph_data, UN_WireID wire_id)
Constructs a handle that references the given wire in the given graph.
Definition: UN_Wire.h:37
GRAPH_DATA * graphData() const
Returns the owner of the underlying graph data structures.
Definition: UN_Wire.h:43
bool operator!=(const UN_Wire &other) const
Comparison operators.
Definition: UN_Wire.h:103
const UN_GraphData * constGraphData() const
Returns the owner of the underlying graph data structures.
Definition: UN_Wire.h:45
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
UN_Wire(UN_GraphData *graph_data, UN_WireID wire_id)
Constructs a handle referencing the given wire in the given graph.
Definition: UN_Wire.h:94
UN_WireID wireID() const
Returns the unique ID of the wire this handle refers to.
Definition: UN_Wire.h:50
bool operator==(const UN_Wire &other) const
Comparison operators.
Definition: UN_Wire.h:101
UN_WireBase()=default
Constructs a handle for an invalid wire.