HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UN_Parm.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_Parm.h ( UN Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UN_Parm_h__
13 #define __UN_Parm_h__
14 
15 #include "UN_API.h"
16 #include "UN_Handle.h"
17 #include "UN_ParmUtils.h"
18 
19 class UN_ConstGraph;
20 class UN_ConstNode;
21 class UN_Graph;
22 class UN_Node;
23 
24 
25 // ============================================================================
26 /// Base class template for the UN parameter handle.
27 /// Its main purpose is to factor common code for const and non-const handles.
28 template <typename BASE_CLASS, // class to derive from
29  typename GRAPH_DATA> // UN_GraphData or const UN_GraphData
30 class UN_ParmBase : public BASE_CLASS
31 {
32 protected:
33  /// Constructs a handle for an invalid parameter.
34  UN_ParmBase() = default;
35 
36  /// Constructs a handle that references the given parm in the given graph.
37  // Note, it's a template to allow either a const or a non-const graph.
38  template <typename GRAPH>
39  UN_ParmBase( GRAPH *graph_data, UN_ParmID parm_id )
40  : BASE_CLASS( graph_data, parm_id )
41  {}
42 
43 public:
44  /// @{ Returns the owner of the underlying graph data structures.
45  GRAPH_DATA * graphData() const
46  { return BASE_CLASS::graphData(); }
47  const UN_GraphData * constGraphData() const
48  { return BASE_CLASS::constGraphData(); }
49  /// @}
50 
51  /// Returns the unique ID of the parameter this handle refers to.
52  UN_ParmID parmID() const
53  { return UN_ParmID( BASE_CLASS::dataID() ); }
54 
55  /// @{ Returns true if this parm is valid within the graph; false otherwise.
56  bool isValid() const
57  {
58  return UN_ParmUtils::isValid(
59  graphData(), parmID());
60  }
61 
62  explicit operator bool() const
63  { return isValid(); }
64  /// @}
65 
66 
67  /// Returns the parameter name that identifies it on the node.
68  const UT_StringHolder & name() const
69  {
70  return UN_ParmUtils::name( graphData(), parmID() );
71  }
72 
73  /// Returns the parameter's type that determines the value type.
74  const UT_StringHolder & typeName() const
75  {
76  return UN_ParmUtils::typeName( graphData(), parmID() );
77  }
78 
79  /// Returns the value of the parameter.
81  {
82  return UN_ParmUtils::value( graphData(), parmID() );
83  }
84 };
85 
86 
87 // ============================================================================
88 /// A handle that references a mutable parameter in a graph.
89 /// It abstracts the APIs that operate on this parameter's data,
90 /// which is stored inside graph's data containers.
91 /// It is a non-const (read-write) handle, so allows both queries
92 /// and mutations (edits) of the parameter's data.
93 class UN_API UN_Parm : public UN_ParmBase< UN_Handle, UN_GraphData >
94 {
95 public:
96  /// Constructs a handle for an invalid node.
97  UN_Parm() = default;
98 
99  /// Constructs a handle referencing the given parameter in the given graph.
100  UN_Parm( UN_GraphData *graph_data, UN_ParmID parm_id )
101  : UN_ParmBase( graph_data, parm_id )
102  {}
103 
104  /// @{ Comparison operators.
105  // Allows comparing parm handles, but guards against
106  // comparing parms to wires, for example.
107  bool operator==( const UN_Parm &other ) const
108  { return UN_ConstHandle::operator==( other ); }
109  bool operator!=( const UN_Parm &other ) const
110  { return UN_ConstHandle::operator!=( other ); }
111  /// @}
112 
113 
114  /// Returns the graph whithin which this port exists.
115  UN_Graph graph() const;
116 
117  /// Returns the node to which this parameter belongs.
118  UN_Node node() const;
119 
120 
121  /// Sets the parameter value.
122  void setValue( const UT_OptionEntry &value ) const
123  {
124  UN_ParmUtils::setValue( graphData(), parmID(), value);
125  }
126 
127  /// Sets the parameter value using move-assignment.
129  {
130  UN_ParmUtils::setValue( graphData(), parmID(), std::move( value ));
131  }
132 
133  /// Deletes this parameter and removes from the node and the graph.
134  void destroy() const
135  {
136  UN_ParmUtils::deleteParm( graphData(), parmID() );
137  }
138 };
139 
140 // ============================================================================
141 /// A handle that references a const parameter in a graph.
142 /// It abstracts the APIs that operate on this parameter's data stored inside
143 /// graph's data containers.
144 /// It is a constant handle, so allows only queries of the parameter's data,
145 /// but does not allow setting any new values on it.
146 class UN_API UN_ConstParm : public UN_ParmBase< UN_ConstHandle,
147  const UN_GraphData >
148 {
149 public:
150  /// Constructs a handle for an invalid parameter.
151  UN_ConstParm() = default;
152 
153  /// Constructs a handle referencing the given parameter in the given graph.
154  UN_ConstParm( const UN_GraphData *graph_data, UN_ParmID parm_id )
155  : UN_ParmBase( graph_data, parm_id )
156  {}
157 
158  /// Constructs a const handle from a mutable parm handle.
159  UN_ConstParm( const UN_Parm &parm )
160  : UN_ConstParm( parm.constGraphData(), parm.parmID() )
161  {}
162 
163  /// @{ Comparison operators.
164  // Allows comparing parm handles, but guards against
165  // comparing parm to wires, for example.
166  bool operator==( const UN_ConstParm &other ) const
167  { return UN_ConstHandle::operator==( other ); }
168  bool operator!=( const UN_ConstParm &other ) const
169  { return UN_ConstHandle::operator!=( other ); }
170  /// @}
171 
172 
173  /// Returns the graph whithin which this parameter exists.
174  UN_ConstGraph graph() const;
175 
176  /// Returns the node to which this parameter belongs.
177  UN_ConstNode node() const;
178 };
179 
180 // ============================================================================
181 // Free functions to compare a non-const parm handle to a const parm handle.
182 // Note, the const to non-const comparison is covered by implicit conversion
183 // of non-const handle to const handle, and using const to const handle comp.
184 static inline bool
185 operator==( const UN_Parm &a, const UN_ConstParm &b )
186 {
187  return b == UN_ConstParm(a);
188 }
189 
190 static inline bool
191 operator!=( const UN_Parm &a, const UN_ConstParm &b )
192 {
193  return !(b == a);
194 }
195 
196 // ============================================================================
197 
198 #endif
199 
UN_ParmID parmID() const
Returns the unique ID of the parameter this handle refers to.
Definition: UN_Parm.h:52
bool operator==(const UN_ConstParm &other) const
Comparison operators.
Definition: UN_Parm.h:166
UN_ConstParm(const UN_Parm &parm)
Constructs a const handle from a mutable parm handle.
Definition: UN_Parm.h:159
GLsizei const GLfloat * value
Definition: glcorearb.h:824
const UT_StringHolder & typeName() const
Returns the parameter's type that determines the value type.
Definition: UN_Parm.h:74
GRAPH_DATA * graphData() const
Returns the owner of the underlying graph data structures.
Definition: UN_Parm.h:45
bool operator==(const UN_Parm &other) const
Comparison operators.
Definition: UN_Parm.h:107
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define UN_API
Definition: UN_API.h:11
void setValue(UT_OptionEntryPtr &&value) const
Sets the parameter value using move-assignment.
Definition: UN_Parm.h:128
OutGridT const XformOp bool bool
UN_Parm(UN_GraphData *graph_data, UN_ParmID parm_id)
Constructs a handle referencing the given parameter in the given graph.
Definition: UN_Parm.h:100
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
UT_OptionEntryPtr value() const
Returns the value of the parameter.
Definition: UN_Parm.h:80
bool operator!=(const UN_ConstParm &other) const
Comparison operators.
Definition: UN_Parm.h:168
void destroy() const
Deletes this parameter and removes from the node and the graph.
Definition: UN_Parm.h:134
void setValue(const UT_OptionEntry &value) const
Sets the parameter value.
Definition: UN_Parm.h:122
const UT_StringHolder & name() const
Returns the parameter name that identifies it on the node.
Definition: UN_Parm.h:68
UN_ConstParm(const UN_GraphData *graph_data, UN_ParmID parm_id)
Constructs a handle referencing the given parameter in the given graph.
Definition: UN_Parm.h:154
bool operator!=(const UN_Parm &other) const
Comparison operators.
Definition: UN_Parm.h:109
bool operator!=(const UN_ConstHandle &other) const
Definition: UN_Handle.h:68
bool operator==(const UN_ConstHandle &other) const
Definition: UN_Handle.h:59
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
UN_ParmBase()=default
Constructs a handle for an invalid parameter.
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
bool isValid() const
Returns true if this parm is valid within the graph; false otherwise.
Definition: UN_Parm.h:56
UN_ParmBase(GRAPH *graph_data, UN_ParmID parm_id)
Constructs a handle that references the given parm in the given graph.
Definition: UN_Parm.h:39
const UN_GraphData * constGraphData() const
Returns the owner of the underlying graph data structures.
Definition: UN_Parm.h:47