HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
node.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_NDR_NODE_H
9 #define PXR_USD_NDR_NODE_H
10 
11 /// \file ndr/node.h
12 ///
13 /// \deprecated
14 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
15 /// in sdr/shaderNode.h
16 
17 #include "pxr/pxr.h"
18 #include "pxr/usd/ndr/api.h"
19 #include "pxr/base/tf/token.h"
20 #include "pxr/usd/ndr/declare.h"
22 #include "pxr/usd/ndr/property.h"
23 
25 
26 /// \class NdrNode
27 ///
28 /// Represents an abstract node. Describes information like the name of the
29 /// node, what its inputs and outputs are, and any associated metadata.
30 ///
31 /// In almost all cases, this class will not be used directly. More specialized
32 /// nodes can be created that derive from `NdrNode`; those specialized nodes can
33 /// add their own domain-specific data and methods.
34 ///
35 /// \deprecated
36 /// Deprecated in favor of SdrShaderNode
37 class NdrNode
38 {
39 public:
40  /// Constructor.
41  NDR_API
42  NdrNode(const NdrIdentifier& identifier,
43  const NdrVersion& version,
44  const std::string& name,
45  const TfToken& family,
46  const TfToken& context,
47  const TfToken& sourceType,
48  const std::string& definitionURI,
49  const std::string& implementationURI,
50  NdrPropertyUniquePtrVec&& properties,
51  const NdrTokenMap& metadata = NdrTokenMap(),
52  const std::string &sourceCode = std::string());
53 
54  /// Destructor.
55  NDR_API
56  virtual ~NdrNode();
57 
58  /// \name The Basics
59  /// @{
60 
61  /// Return the identifier of the node.
62  const NdrIdentifier& GetIdentifier() const { return _identifier; }
63 
64  /// Return the version of the node
65  ///
66  /// \deprecated
67  /// Deprecated in favor of SdrShaderNode::GetShaderVersion
68  NdrVersion GetVersion() const { return _version; }
69 
70  /// Gets the name of the node.
71  const std::string& GetName() const { return _name; }
72 
73  /// Gets the name of the family that the node belongs to. An empty token
74  /// will be returned if the node does not belong to a family.
75  const TfToken& GetFamily() const { return _family; }
76 
77  /// Gets the context of the node.
78  ///
79  /// The context is the context that the node declares itself as having (or,
80  /// if a particular node does not declare a context, it will be assigned a
81  /// default context by the parser).
82  ///
83  /// As a concrete example from the `Sdr` library, a shader with a specific
84  /// source type may perform different duties vs. another shader with the
85  /// same source type. For example, one shader with a source type of
86  /// `SdrArgsParser::SourceType` may declare itself as having a context of
87  /// 'pattern', while another shader of the same source type may say it is
88  /// used for lighting, and thus has a context of 'light'.
89  const TfToken& GetContext() const { return _context; }
90 
91  /// Gets the type of source that this node originated from.
92  ///
93  /// Note that this is distinct from `GetContext()`, which is the type that
94  /// the node declares itself as having.
95  ///
96  /// As a concrete example from the `Sdr` library, several shader parsers
97  /// exist and operate on different types of shaders. In this scenario, each
98  /// distinct type of shader (OSL, Args, etc) is considered a different
99  /// _source_, even though they are all shaders. In addition, the shaders
100  /// under each source type may declare themselves as having a specific
101  /// context (shaders can serve different roles). See `GetContext()` for
102  /// more information on this.
103  const TfToken& GetSourceType() const { return _sourceType; }
104 
105  /// Gets the URI to the resource that provided this node's
106  /// definition. Could be a path to a file, or some other resource
107  /// identifier. This URI should be fully resolved.
108  ///
109  /// \sa NdrNode::GetResolvedImplementationURI()
110  const std::string& GetResolvedDefinitionURI() const { return _definitionURI; }
111 
112  /// Gets the URI to the resource that provides this node's
113  /// implementation. Could be a path to a file, or some other resource
114  /// identifier. This URI should be fully resolved.
115  ///
116  /// \sa NdrNode::GetResolvedDefinitionURI()
117  const std::string& GetResolvedImplementationURI() const { return _implementationURI; }
118 
119  /// Returns the source code for this node. This will be empty for most
120  /// nodes. It will be non-empty only for the nodes that are constructed
121  /// using \ref NdrRegistry::GetNodeFromSourceCode(), in which case, the
122  /// source code has not been parsed (or even compiled) yet.
123  ///
124  /// An unparsed node with non-empty source-code but no properties is
125  /// considered to be invalid. Once the node is parsed and the relevant
126  /// properties and metadata are extracted from the source code, the node
127  /// becomes valid.
128  ///
129  /// \sa NdrNode::IsValid
130  const std::string &GetSourceCode() const { return _sourceCode; }
131 
132  /// Whether or not this node is valid. A node that is valid indicates that
133  /// the parser plugin was able to successfully parse the contents of this
134  /// node.
135  ///
136  /// Note that if a node is not valid, some data like its name, URI, source
137  /// code etc. could still be available (data that was obtained during the
138  /// discovery process). However, other data that must be gathered from the
139  /// parsing process will NOT be available (eg, inputs and outputs).
140  NDR_API
141  virtual bool IsValid() const { return _isValid; }
142 
143  /// Gets a string with basic information about this node. Helpful for
144  /// things like adding this node to a log.
145  NDR_API
146  virtual std::string GetInfoString() const;
147 
148  /// @}
149 
150 
151  /// \name Inputs and Outputs
152  /// An input or output is also generically referred to as a "property".
153  /// @{
154 
155  /// Get an ordered list of all the input names on this node.
156  ///
157  /// \deprecated
158  /// Deprecated in favor of SdrShaderNode::GetShaderInputNames
159  NDR_API
160  const NdrTokenVec& GetInputNames() const;
161 
162  /// Get an ordered list of all the output names on this node.
163  ///
164  /// \deprecated
165  /// Deprecated in favor of SdrShaderNode::GetShaderOutputNames
166  NDR_API
167  const NdrTokenVec& GetOutputNames() const;
168 
169  /// Get an input property by name. `nullptr` is returned if an input with
170  /// the given name does not exist.
171  ///
172  /// \deprecated
173  /// Deprecated in favor of SdrShaderNode::GetShaderInput
174  NDR_API
175  NdrPropertyConstPtr GetInput(const TfToken& inputName) const;
176 
177  /// Get an output property by name. `nullptr` is returned if an output with
178  /// the given name does not exist.
179  ///
180  /// \deprecated
181  /// Deprecated in favor of SdrShaderNode::GetShaderOutput
182  NDR_API
183  NdrPropertyConstPtr GetOutput(const TfToken& outputName) const;
184 
185  /// @}
186 
187 
188  /// \name Metadata
189  /// The metadata returned here is a direct result of what the parser plugin
190  /// is able to determine about the node. See the documentation for a
191  /// specific parser plugin to get help on what the parser is looking for to
192  /// populate these values.
193  /// @{
194 
195  /// All metadata that came from the parse process. Specialized nodes may
196  /// isolate values in the metadata (with possible manipulations and/or
197  /// additional parsing) and expose those values in their API.
198  NDR_API
199  const NdrTokenMap& GetMetadata() const;
200 
201  /// @}
202 
203 protected:
204  NdrNode& operator=(const NdrNode&) = delete;
205 
206  bool _isValid;
209  std::string _name;
213  std::string _definitionURI;
214  std::string _implementationURI;
217  std::string _sourceCode;
218 
223 };
224 
226 
227 #endif // PXR_USD_NDR_NODE_H
NDR_API const NdrTokenVec & GetOutputNames() const
const TfToken & GetSourceType() const
Definition: node.h:103
NdrPropertyPtrMap _outputs
Definition: node.h:221
std::vector< TfToken > NdrTokenVec
Definition: declare.h:50
const std::string & GetResolvedImplementationURI() const
Definition: node.h:117
NDR_API NdrPropertyConstPtr GetOutput(const TfToken &outputName) const
NDR_API const NdrTokenMap & GetMetadata() const
NdrPropertyPtrMap _inputs
Definition: node.h:219
const std::string & GetResolvedDefinitionURI() const
Definition: node.h:110
NdrNode & operator=(const NdrNode &)=delete
NdrTokenVec _inputNames
Definition: node.h:220
NDR_API NdrNode(const NdrIdentifier &identifier, const NdrVersion &version, const std::string &name, const TfToken &family, const TfToken &context, const TfToken &sourceType, const std::string &definitionURI, const std::string &implementationURI, NdrPropertyUniquePtrVec &&properties, const NdrTokenMap &metadata=NdrTokenMap(), const std::string &sourceCode=std::string())
Constructor.
std::string _name
Definition: node.h:209
const std::string & GetSourceCode() const
Definition: node.h:130
NdrTokenVec _outputNames
Definition: node.h:222
std::vector< NdrPropertyUniquePtr > NdrPropertyUniquePtrVec
Definition: declare.h:58
std::string _definitionURI
Definition: node.h:213
Definition: token.h:70
Definition: node.h:37
const TfToken & GetContext() const
Definition: node.h:89
TfToken _family
Definition: node.h:210
NdrTokenMap _metadata
Definition: node.h:216
GLuint const GLchar * name
Definition: glcorearb.h:786
NdrIdentifier _identifier
Definition: node.h:207
NdrPropertyUniquePtrVec _properties
Definition: node.h:215
virtual NDR_API bool IsValid() const
Definition: node.h:141
#define NDR_API
Definition: api.h:23
GT_API const UT_StringHolder version
const NdrIdentifier & GetIdentifier() const
Return the identifier of the node.
Definition: node.h:62
NDR_API NdrPropertyConstPtr GetInput(const TfToken &inputName) const
bool _isValid
Definition: node.h:206
TfToken _context
Definition: node.h:211
std::string _sourceCode
Definition: node.h:217
NdrVersion GetVersion() const
Definition: node.h:68
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
const TfToken & GetFamily() const
Definition: node.h:75
const std::string & GetName() const
Gets the name of the node.
Definition: node.h:71
virtual NDR_API ~NdrNode()
Destructor.
std::string _implementationURI
Definition: node.h:214
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
TfToken _sourceType
Definition: node.h:212
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > NdrTokenMap
Definition: declare.h:52
std::unordered_map< TfToken, NdrPropertyConstPtr, TfToken::HashFunctor > NdrPropertyPtrMap
Definition: declare.h:60
NdrVersion _version
Definition: node.h:208
NDR_API const NdrTokenVec & GetInputNames() const
virtual NDR_API std::string GetInfoString() const
NdrProperty const * NdrPropertyConstPtr
Definition: declare.h:56