Loading...
Searching...
No Matches
object.h
Go to the documentation of this file.
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_VDF_OBJECT_H
8#define PXR_EXEC_VDF_OBJECT_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
15
16#include "pxr/base/tf/token.h"
17
18#include <set>
19#include <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23class VdfConnection;
24class VdfInput;
25class VdfNode;
26class VdfOutput;
27
40{
41public:
42
44 enum Type
45 {
46 Undefined = -1, // Marks the undefined type.
47
48 Node, // The object is a VdfNode.
49 Connection, // The object is a VdfConnection.
50 Input, // The object is a VdfInput.
51 Output // The object is a VdfOutput.
52 };
53
57 : _node(NULL),
58 _type(Undefined),
59 _isConst(false) {}
60
64 : _node(node),
65 _type(Node),
66 _isConst(false) {}
67
70 VdfObjectPtr(const VdfNode *node)
71 : _constNode(node),
72 _type(Node),
73 _isConst(true) {}
74
78 : _connection(connection),
79 _type(Connection),
80 _isConst(false) {}
81
84 VdfObjectPtr(const VdfConnection *connection)
85 : _constConnection(connection),
86 _type(Connection),
87 _isConst(true) {}
88
92 : _input(input),
93 _type(Input),
94 _isConst(false) {}
95
98 VdfObjectPtr(const VdfInput *input)
99 : _constInput(input),
100 _type(Input),
101 _isConst(true) {}
102
106 : _output(output),
107 _type(Output),
108 _isConst(false) {}
109
112 VdfObjectPtr(const VdfOutput *output)
113 : _constOutput(output),
114 _type(Output),
115 _isConst(true) {}
116
120 {
121 _node = rhs._node;
122 _type = rhs._type;
123 _isConst = rhs._isConst;
124
125 return *this;
126 }
127
130 bool operator<(const VdfObjectPtr &rhs) const
131 {
132 return _node < rhs._node;
133 }
134
135 bool operator<=(const VdfObjectPtr &rhs) const
136 {
137 return !(rhs < *this);
138 }
139
142 bool operator>(const VdfObjectPtr &rhs) const
143 {
144 return rhs < *this;
145 }
146
147 bool operator>=(const VdfObjectPtr &rhs) const
148 {
149 return !(*this < rhs);
150 }
151
154 bool operator==(const VdfObjectPtr &rhs) const
155 {
156 return _type == rhs._type &&
157 _node == rhs._node;
158 }
159
162 bool operator!=(const VdfObjectPtr &rhs) const
163 {
164 return !(*this == rhs);
165 }
166
170 {
171 size_t operator()(const VdfObjectPtr &obj) const
172 {
173 return (size_t)obj._node;
174 }
175 };
176
179 operator bool() const
180 {
181 return _node;
182 }
183
186 Type GetType() const
187 {
188 return _type;
189 }
190
193 bool IsConst() const
194 {
195 return _isConst;
196 }
197
200 bool IsNode() const
201 {
202 return _type == Node;
203 }
204
207 bool IsConnection() const
208 {
209 return _type == Connection;
210 }
211
214 bool IsInput() const
215 {
216 return _type == Input;
217 }
218
221 bool IsOutput() const
222 {
223 return _type == Output;
224 }
225
230 {
231 TF_AXIOM(IsNode());
232 TF_AXIOM(!IsConst());
233 return _node;
234 }
235
240 {
242 TF_AXIOM(!IsConst());
243 return _connection;
244 }
245
250 {
251 TF_AXIOM(IsInput());
252 TF_AXIOM(!IsConst());
253 return _input;
254 }
255
260 {
262 TF_AXIOM(!IsConst());
263 return _output;
264 }
265
268 const VdfNode &GetNode() const
269 {
270 TF_AXIOM(IsNode());
271 return *_constNode;
272 }
273
278 {
280 return *_constConnection;
281 }
282
285 const VdfInput &GetInput() const
286 {
287 TF_AXIOM(IsInput());
288 return *_constInput;
289 }
290
294 const VdfOutput &GetOutput() const
295 {
297 return *_constOutput;
298 }
299
303 const VdfNode *GetIfNode() const
304 {
305 return IsNode() ? _constNode : NULL;
306 }
307
312 {
313 return IsConnection() ? _constConnection : NULL;
314 }
315
319 const VdfInput *GetIfInput() const
320 {
321 return IsInput() ? _constInput : NULL;
322 }
323
327 const VdfOutput *GetIfOutput() const
328 {
329 return IsOutput() ? _constOutput : NULL;
330 }
331
336 {
337 return (!IsConst() && IsNode()) ? _node : NULL;
338 }
339
344 {
345 return (!IsConst() && IsConnection()) ? _connection : NULL;
346 }
347
352 {
353 return (!IsConst() && IsInput()) ? _input : NULL;
354 }
355
360 {
361 return (!IsConst() && IsOutput()) ? _output : NULL;
362 }
363
368 VDF_API
369 const VdfNode *GetOwningNode() const;
370
373 VDF_API
374 std::string GetDebugName() const;
375
378 const void *GetIdentity() const
379 {
380 // Note: Since all different types are stored in an union, we just
381 // pick the first const type to return.
382 return _constNode;
383 }
384
385// -----------------------------------------------------------------------------
386
387private:
388
389 // Stores pointers as needed for the different object types.
390 union
391 {
392 VdfNode *_node;
393 VdfConnection *_connection;
394 VdfInput *_input;
395 VdfOutput *_output;
396
397 const VdfNode *_constNode;
398 const VdfConnection *_constConnection;
399 const VdfInput *_constInput;
400 const VdfOutput *_constOutput;
401 };
402
403 // Holds the type of the object.
404 Type _type;
405
406 // If set, the object being held is const.
407 bool _isConst;
408};
409
412typedef std::vector<VdfObjectPtr> VdfObjectPtrVector;
413
416typedef std::set<VdfObjectPtr> VdfObjectPtrSet;
417
418PXR_NAMESPACE_CLOSE_SCOPE
419
420#endif
A class that fully represents a connection between two VdfNodes.
Definition: connection.h:30
A VdfInput is used to connect a VdfNode to one or more VdfNodes' outputs.
Definition: input.h:36
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
An universal class to represent pointers to various Vdf types.
Definition: object.h:40
VdfObjectPtr(const VdfNode *node)
Ctor to create an anchor from a const node.
Definition: object.h:70
Type
Type of object.
Definition: object.h:45
VdfObjectPtr(VdfOutput *output)
Ctor to create an anchor from a output.
Definition: object.h:105
VdfObjectPtr(VdfInput *input)
Ctor to create an anchor from a input.
Definition: object.h:91
VdfInput * GetNonConstInput() const
Returns a non-const pointer to an input.
Definition: object.h:249
const VdfNode & GetNode() const
Returns a const reference to a node.
Definition: object.h:268
bool IsConnection() const
Returns true if the object is a node.
Definition: object.h:207
VdfNode * GetIfNonConstNode() const
Returns a pointer to a VdfNode if the object is holding a non-const node, NULL otherwise.
Definition: object.h:335
const VdfOutput & GetOutput() const
Returns a const reference to an output.
Definition: object.h:294
Type GetType() const
Returns the type of the object.
Definition: object.h:186
bool IsNode() const
Returns true if the object is a node.
Definition: object.h:200
bool operator!=(const VdfObjectPtr &rhs) const
Not equal operator.
Definition: object.h:162
VDF_API std::string GetDebugName() const
Returns a debug name for this object.
const VdfNode * GetIfNode() const
Returns a pointer to a VdfNode if the object is holding a node, NULL otherwise.
Definition: object.h:303
VdfInput * GetIfNonConstInput() const
Returns a pointer to a VdfInput if the object is holding a non-const input, NULL otherwise.
Definition: object.h:351
VdfObjectPtr(const VdfInput *input)
Ctor to create an anchor from a input.
Definition: object.h:98
VDF_API const VdfNode * GetOwningNode() const
Returns the owning node of this object if object is an input or output.
VdfConnection * GetIfNonConstConnection() const
Returns a pointer to a VdfConnection if the object is holding a non-const connection,...
Definition: object.h:343
const VdfOutput * GetIfOutput() const
Returns a pointer to a VdfOutput if the object is holding a output, NULL otherwise.
Definition: object.h:327
VdfObjectPtr(const VdfConnection *connection)
Ctor to create an anchor from a const connection.
Definition: object.h:84
const VdfConnection * GetIfConnection() const
Returns a pointer to a VdfConnection if the object is holding a connection, NULL otherwise.
Definition: object.h:311
bool IsConst() const
Returns true, if the object being hold is const.
Definition: object.h:193
bool operator>(const VdfObjectPtr &rhs) const
More than operator used for map.
Definition: object.h:142
VdfConnection * GetNonConstConnection() const
Returns a non-const pointer to a connection.
Definition: object.h:239
bool operator==(const VdfObjectPtr &rhs) const
Equality operator.
Definition: object.h:154
VdfNode * GetNonConstNode() const
Returns a non-const pointer to a node.
Definition: object.h:229
bool IsInput() const
Returns true if the object is a node.
Definition: object.h:214
const VdfInput & GetInput() const
Returns a const reference to an input.
Definition: object.h:285
const VdfInput * GetIfInput() const
Returns a pointer to a VdfInput if the object is holding a input, NULL otherwise.
Definition: object.h:319
VdfObjectPtr(VdfNode *node)
Ctor to create an anchor from a node.
Definition: object.h:63
const void * GetIdentity() const
Returns the identity of this object as a void *.
Definition: object.h:378
VdfOutput * GetIfNonConstOutput() const
Returns a pointer to a VdfOutput if the object is holding a non-const output, NULL otherwise.
Definition: object.h:359
const VdfConnection & GetConnection() const
Returns a const reference to a connection.
Definition: object.h:277
VdfObjectPtr()
Ctor to create the NULL object.
Definition: object.h:56
bool IsOutput() const
Returns true if the object is a node.
Definition: object.h:221
bool operator<(const VdfObjectPtr &rhs) const
Less than operator used for map.
Definition: object.h:130
VdfObjectPtr(const VdfOutput *output)
Ctor to create an anchor from a output.
Definition: object.h:112
VdfObjectPtr & operator=(const VdfObjectPtr &rhs)
Assignment operator.
Definition: object.h:119
VdfOutput * GetNonConstOutput() const
Returns a non-const pointer to an output.
Definition: object.h:259
VdfObjectPtr(VdfConnection *connection)
Ctor to create an anchor from a connection.
Definition: object.h:77
A VdfOutput represents an output on a node.
Definition: output.h:32
std::set< VdfObjectPtr > VdfObjectPtrSet
An object set.
Definition: object.h:416
std::vector< VdfObjectPtr > VdfObjectPtrVector
An object vector.
Definition: object.h:412
#define TF_AXIOM(cond)
Aborts if the condition cond is not met.
Definition: diagnostic.h:193
Functor to use for hash maps.
Definition: object.h:170
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...