Loading...
Searching...
No Matches
connectorSpecs.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_CONNECTOR_SPECS_H
8#define PXR_EXEC_VDF_CONNECTOR_SPECS_H
9
11
12#include "pxr/pxr.h"
13
16#include "pxr/exec/vdf/tokens.h"
17
18#include "pxr/base/tf/type.h"
20
21PXR_NAMESPACE_OPEN_SCOPE
22
41
42
49template < typename T >
51{
52 // We choose a small vector with default size 1 to optimize for common
53 // cases, including nodes with a single output.
55
56public:
58 using const_iterator = typename _VectorType::const_iterator;
59
62
65 // Copy other vector into our new one.
66 Append(rhs);
67 }
68
71 : _specs(std::move(rhs._specs)) {
72 }
73
76 // Clear our specs, and copy the others into them.
78 Append(rhs);
79 return *this;
80 }
81
84 // Clear our specs, and move the others into them.
86 _specs = std::move(rhs._specs);
87 return *this;
88 }
89
91 void Append(const VdfConnectorSpecs<T> &specs) {
92 _specs.reserve(_specs.size() + specs._specs.size());
93 for (const T *spec : specs._specs) {
94 _specs.push_back( new T(*spec) );
95 }
96 }
97
100 void Reserve(size_t numSpecs) {
101 _specs.reserve(numSpecs);
102 }
103
105 size_t GetSize() const { return _specs.size(); }
106
108 const_iterator begin() const { return _specs.begin(); }
109
111 const_iterator end() const { return _specs.end(); }
112
113protected:
114
121 _ClearSpecs();
122 }
123
125 void _ClearSpecs() {
126 const_iterator e = _specs.end();
127 for (const_iterator i = _specs.begin(); i != e; ++i) {
128 delete *i;
129 }
130 _specs.clear();
131 }
132
134 const T *_GetConnectorSpec(int idx) const
135 {
136 return _specs[idx];
137 }
138
140 void _AddConnector(T *cs)
141 {
142 _specs.push_back(cs);
143 }
144
145private:
146
147 // A list of specs held in this container class.
148 _VectorType _specs;
149};
150
151
157class VdfInputSpecs : public VdfConnectorSpecs<VdfInputSpec>
158{
159public:
160
168 template <typename T> VdfInputSpecs &
169 ReadConnector(const TfToken &inName,
170 const TfToken &outName = VdfTokens->empty,
171 bool prerequisite = false)
172 {
173 _AddConnector(VdfInputSpec::New<T>(
174 inName, outName, VdfInputSpec::READ, prerequisite));
175 return *this;
176 }
177
181 template <typename T> VdfInputSpecs &
182 ReadWriteConnector(const TfToken &inName, const TfToken &outName)
183 {
184 _AddConnector(VdfInputSpec::New<T>(
185 inName, outName, VdfInputSpec::READWRITE, /* prerequisite */false));
186 return *this;
187 }
188
191 const VdfInputSpec *GetInputSpec(int idx) const
192 {
193 return _GetConnectorSpec(idx);
194 }
195
200 const TfType &type,
201 const TfToken &inName,
202 const TfToken &outName = VdfTokens->empty,
203 bool prerequisite = false)
204 {
206 VdfInputSpec::New(
207 type, inName, outName, VdfInputSpec::READ, prerequisite));
208 return *this;
209 }
210
215 const TfType &type,
216 const TfToken &inName,
217 const TfToken &outName)
218 {
220 VdfInputSpec::New(
221 type, inName, outName, VdfInputSpec::READWRITE,
222 /*prerequisite*/ false));
223 return *this;
224 }
225
228 VDF_API
229 bool operator==(const VdfInputSpecs &rhs) const;
230 bool operator!=(const VdfInputSpecs &rhs) const {
231 return !(*this == rhs);
232 }
233};
234
235
241class VdfOutputSpecs : public VdfConnectorSpecs<VdfOutputSpec>
242{
243public:
244
246 template <typename T> VdfOutputSpecs &
247 Connector(const TfToken &name)
248 {
249 _AddConnector(VdfOutputSpec::New<T>(name));
250 return *this;
251 }
252
254 const VdfOutputSpec *GetOutputSpec(int idx) const
255 {
256 return _GetConnectorSpec(idx);
257 }
258
262 Connector(const TfType &type, const TfToken &name)
263 {
264 _AddConnector(VdfOutputSpec::New(type, name));
265 return *this;
266 }
267
270 VDF_API
271 bool operator==(const VdfOutputSpecs &rhs) const;
272 bool operator!=(const VdfOutputSpecs &rhs) const {
273 return !(*this == rhs);
274 }
275};
276
278
279PXR_NAMESPACE_CLOSE_SCOPE
280
281#endif
void push_back(const value_type &v)
Copy an entry to the back of the vector,.
Definition: smallVector.h:478
void reserve(size_type newCapacity)
Reserve storage for newCapacity entries.
Definition: smallVector.h:410
size_type size() const
Returns the current size of the vector.
Definition: smallVector.h:596
void clear()
Clear the entries in the vector.
Definition: smallVector.h:441
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
The classes contained in this file are the containers for input and output specs.
size_t GetSize() const
Returns number of connectors in this spec.
~VdfConnectorSpecs()
Destructor.
VdfConnectorSpecs< T > & operator=(VdfConnectorSpecs< T > &&rhs)
Move assignment operator.
const_iterator begin() const
Returns a const_iterator to the beginning of the connectors.
const T * _GetConnectorSpec(int idx) const
Returns connector spec at index idx.
VdfConnectorSpecs< T > & operator=(const VdfConnectorSpecs< T > &rhs)
Copy assignment operator.
VdfConnectorSpecs()
Constructor.
void _AddConnector(T *cs)
Adds a connector to our list.
void Append(const VdfConnectorSpecs< T > &specs)
Appends a set of specs to this one.
VdfConnectorSpecs(const VdfConnectorSpecs< T > &rhs)
Copy constructor.
VdfConnectorSpecs(VdfConnectorSpecs< T > &&rhs)
Move constructor.
void Reserve(size_t numSpecs)
Allocates space for numSpecs connector specs, to avoid re-allocation when adding specs,...
const_iterator end() const
Returns a const_iterator to the end of the connectors.
typename _VectorType::const_iterator const_iterator
Iterator type.
void _ClearSpecs()
Clears list of specs.
A VdfInputSpec describes an input connector.
Definition: inputSpec.h:30
VdfInputSpecs is a container for VdfInputSpec objects.
VdfInputSpecs & ReadConnector(const TfType &type, const TfToken &inName, const TfToken &outName=VdfTokens->empty, bool prerequisite=false)
Non-templated version of ReadConnector(), the given type must be registered for runtime type dispatch...
VdfInputSpecs & ReadWriteConnector(const TfToken &inName, const TfToken &outName)
Create a "Read/Write" connector with the name inName associated with the output named outName.
const VdfInputSpec * GetInputSpec(int idx) const
Returns connector spec at index idx.
VdfInputSpecs & ReadWriteConnector(const TfType &type, const TfToken &inName, const TfToken &outName)
Non-templated version of ReadWriteConnector(), the given type must be registered for runtime type dis...
VdfInputSpecs & ReadConnector(const TfToken &inName, const TfToken &outName=VdfTokens->empty, bool prerequisite=false)
Create a "Read" connector with the name inName and optionally associated with the output named outNam...
VDF_API bool operator==(const VdfInputSpecs &rhs) const
Returns true if two InputSpecs are equal.
A VdfOuptutSpec describes an output connector.
Definition: outputSpec.h:40
VdfOutputSpecs is a container for VdfOutputSpec objects.
VDF_API bool operator==(const VdfOutputSpecs &rhs) const
Returns true if two OutputSpecs are equal.
VdfOutputSpecs & Connector(const TfType &type, const TfToken &name)
Non-templated version of Connector(), the given type must be registered for runtime type dispatching.
const VdfOutputSpec * GetOutputSpec(int idx) const
Returns connector spec at index idx.
VdfOutputSpecs & Connector(const TfToken &name)
Create an "Out" connector with the given name.
STL namespace.