HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
input.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_INPUT_H
8 #define PXR_EXEC_VDF_INPUT_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
15 #include "pxr/exec/vdf/inputSpec.h"
16 #include "pxr/exec/vdf/mask.h"
17 #include "pxr/exec/vdf/types.h"
18 
19 #include "pxr/base/tf/span.h"
20 
21 #include <vector>
22 
24 
25 class VdfConnection;
26 class VdfNode;
27 class VdfOutput;
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 ///
31 /// A VdfInput is used to connect a VdfNode to one or more VdfNodes'
32 /// outputs. Each of the connections is represented by a VdfConnection
33 /// object that is owned by the VdfInput.
34 ///
35 class VdfInput
36 {
37 public:
38 
39  /// Destructor
40  ///
41  VDF_API
42  ~VdfInput();
43 
44  /// Constructor.
45  ///
46  /// Creates an empty connector.
47  ///
48  VdfInput(VdfNode &owner, int specIndex, const VdfOutput *output = NULL) :
49  _owner(owner), _associatedOutput(output), _specIndex(specIndex) {
50  }
51 
52  /// Returns a list of connections connected to this input.
53  ///
54  const VdfConnectionVector &GetConnections() const { return _connections; }
55 
56  /// Returns the number of connections for this input.
57  ///
58  size_t GetNumConnections() const {
59  return _connections.size();
60  }
61 
62  /// Returns the connection at \p index.
63  ///
64  const VdfConnection &operator[](size_t index) const {
65  return *_connections[index];
66  }
67 
68  /// Returns the connection at \p index, writable.
69  ///
71  return *_connections[index];
72  }
73 
74  /// Returns the spec for this input connector.
75  ///
76  VDF_API
77  const VdfInputSpec &GetSpec() const;
78 
79  /// Returns the output corresponding to this input. This is only
80  /// non-NULL for writeable input connectors.
81  ///
82  const VdfOutput *GetAssociatedOutput() const { return _associatedOutput; }
83 
84  /// Returns the owning node for this input connector.
85  ///
86  const VdfNode &GetNode() const { return _owner; }
87 
88  /// Returns the non-const owning node for this input connector.
89  ///
90  VdfNode &GetNode() { return _owner; }
91 
92  /// Returns the name of this input.
93  ///
94  const TfToken &GetName() const {
95  return GetSpec().GetName();
96  }
97 
98  /// Returns a descriptive name for this input connector.
99  ///
100  VDF_API
101  std::string GetDebugName() const;
102 
103 private:
104 
105  // Only the VdfNetwork and VdfIsolatedSubnetwork should have access to the
106  // connect API.
107  friend class VdfNetwork;
108  friend class VdfIsolatedSubnetwork;
109 
110  // VdfOutput needs to be able to call _AddConnection().
111  friend class VdfOutput;
112 
113  /// Returns the index of the connector spec of this input on the owning
114  /// node.
115  ///
116  int _GetSpecIndex() const {
117  return _specIndex;
118  }
119 
120  /// Adds a connection to \p output with the given \p mask at index
121  /// \p atIndex.
122  ///
123  /// If \p atIndex is VdfNetwork::AppendConnection the connection will be
124  /// added at the end.
125  ///
126  VdfConnection *_AddConnection(
127  VdfOutput &output,
128  const VdfMask &mask,
129  int atIndex);
130 
131  /// Removes \p connection from this input.
132  void _RemoveConnection(VdfConnection *connection);
133 
134  /// Rorders all connections according to the mapping defined by \p
135  /// newToOldIndices.
136  ///
137  /// For each index `i`, `newToOldIndices[i]` is the old connection index and
138  /// `i` is the desired new connection index. The number of indices given
139  /// must be the same as the number of input connections, each index must be
140  /// a valid connection index, and the indices must be unique.
141  ///
142  void _ReorderInputConnections(
143  const TfSpan<const VdfConnectionVector::size_type> &newToOldIndices);
144 
145 private:
146 
147  // The owner of this input connector.
148  VdfNode &_owner;
149 
150  // A pointer to a corresponding output. This is only non-null for in/out
151  // connectors.
152  const VdfOutput *_associatedOutput;
153 
154  // The list of connections on this connector.
155  VdfConnectionVector _connections;
156 
157  // The index of the connector spec for this input on the owning node.
158  int _specIndex;
159 };
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 
164 
165 #endif
VDF_API const VdfInputSpec & GetSpec() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
size_t GetNumConnections() const
Definition: input.h:58
Definition: node.h:52
size_type size() const
Definition: smallVector.h:596
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
#define VDF_API
Definition: api.h:25
Definition: input.h:35
Definition: token.h:70
const VdfConnection & operator[](size_t index) const
Definition: input.h:64
Definition: span.h:70
GLint GLuint mask
Definition: glcorearb.h:124
const TfToken & GetName() const
Definition: input.h:94
VdfConnection & GetNonConstConnection(size_t index) const
Definition: input.h:70
const TfToken & GetName() const
Returns the name of this connector.
Definition: inputSpec.h:68
VdfNode & GetNode()
Definition: input.h:90
GLuint index
Definition: glcorearb.h:786
const VdfOutput * GetAssociatedOutput() const
Definition: input.h:82
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
VDF_API ~VdfInput()
VDF_API std::string GetDebugName() const
VdfInput(VdfNode &owner, int specIndex, const VdfOutput *output=NULL)
Definition: input.h:48
const VdfNode & GetNode() const
Definition: input.h:86
const VdfConnectionVector & GetConnections() const
Definition: input.h:54