HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
property.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_PROPERTY_H
9 #define PXR_USD_NDR_PROPERTY_H
10 
11 /// \file ndr/property.h
12 ///
13 /// \deprecated
14 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
15 /// in sdr/property.h
16 
17 #include "pxr/pxr.h"
18 #include "pxr/usd/ndr/api.h"
20 #include "pxr/base/tf/token.h"
21 #include "pxr/base/vt/value.h"
22 #include "pxr/usd/ndr/declare.h"
23 
25 
26 /// \class NdrProperty
27 ///
28 /// Represents a property (input or output) that is part of a `NdrNode`
29 /// instance.
30 ///
31 /// A property must have a name and type, but may also specify a host of
32 /// additional metadata. Instances can also be queried to determine if another
33 /// `NdrProperty` instance can be connected to it.
34 ///
35 /// In almost all cases, this class will not be used directly. More specialized
36 /// properties can be created that derive from `NdrProperty`; those specialized
37 /// properties can add their own domain-specific data and methods.
38 ///
39 /// \deprecated
40 /// Deprecated in favor of SdrShaderProperty
42 {
43 public:
44  /// Constructor.
45  NDR_API
47  const TfToken& name,
48  const TfToken& type,
49  const VtValue& defaultValue,
50  bool isOutput,
51  size_t arraySize,
52  bool isDynamicArray,
53  const NdrTokenMap& metadata
54  );
55 
56  /// Destructor.
57  NDR_API
58  virtual ~NdrProperty();
59 
60  /// \name The Basics
61  /// @{
62 
63  /// Gets the name of the property.
64  NDR_API
65  const TfToken& GetName() const { return _name; }
66 
67  /// Gets the type of the property.
68  NDR_API
69  const TfToken& GetType() const { return _type; }
70 
71  /// Gets this property's default value associated with the type of the
72  /// property.
73  ///
74  /// \sa GetType()
75  NDR_API
76  const VtValue& GetDefaultValue() const { return _defaultValue; }
77 
78  /// Whether this property is an output.
79  NDR_API
80  bool IsOutput() const { return _isOutput; }
81 
82  /// Whether this property's type is an array type.
83  NDR_API
84  bool IsArray() const { return (_arraySize > 0) || _isDynamicArray; }
85 
86  /// Whether this property's array type is dynamically-sized.
87  NDR_API
88  bool IsDynamicArray() const { return _isDynamicArray; };
89 
90  /// Gets this property's array size.
91  ///
92  /// If this property is a fixed-size array type, the array size is returned.
93  /// In the case of a dynamically-sized array, this method returns the array
94  /// size that the parser reports, and should not be relied upon to be
95  /// accurate. A parser may report -1 for the array size, for example, to
96  /// indicate a dynamically-sized array. For types that are not a fixed-size
97  /// array or dynamic array, this returns 0.
98  NDR_API
99  int GetArraySize() const { return _arraySize; }
100 
101  /// Gets a string with basic information about this property. Helpful for
102  /// things like adding this property to a log.
103  NDR_API
104  virtual std::string GetInfoString() const;
105 
106  /// @}
107 
108 
109  /// \name Metadata
110  /// The metadata returned here is a direct result of what the parser plugin
111  /// is able to determine about the node. See the documentation for a
112  /// specific parser plugin to get help on what the parser is looking for to
113  /// populate these values.
114  /// @{
115 
116  /// All of the metadata that came from the parse process.
117  NDR_API
118  virtual const NdrTokenMap& GetMetadata() const { return _metadata; }
119 
120  /// @}
121 
122 
123  /// \name Connection Information
124  /// @{
125 
126  /// Whether this property can be connected to other properties.
127  NDR_API
128  virtual bool IsConnectable() const;
129 
130  /// Determines if this property can be connected to the specified property.
131  ///
132  /// \deprecated
133  /// Deprecated in favor of
134  /// SdrShaderProperty::CanConnectTo(SdrShaderProperty)
135  NDR_API
136  virtual bool CanConnectTo(const NdrProperty& other) const;
137 
138  /// @}
139 
140 
141  /// \name Utilities
142  /// @{
143 
144  /// Converts the property's type from `GetType()` into a
145  /// `NdrSdfTypeIndicator`.
146  ///
147  /// Two scenarios can result: an exact mapping from property type to Sdf
148  /// type, and an inexact mapping. In the first scenario,
149  /// NdrSdfTypeIndicator will contain a cleanly-mapped Sdf type. In the
150  /// second scenario, the NdrSdfTypeIndicator will contain an Sdf type
151  /// set to `Token` to indicate an unclean mapping, and
152  /// NdrSdfTypeIndicator::HasSdfType will return false.
153  ///
154  /// This base property class is generic and cannot know ahead of time how to
155  /// perform this mapping reliably, thus it will always fall into the second
156  /// scenario. It is up to specialized properties to perform the mapping.
157  ///
158  /// \sa GetDefaultValueAsSdfType()
159  NDR_API
160  virtual NdrSdfTypeIndicator GetTypeAsSdfType() const;
161 
162  /// Provides default value corresponding to the SdfValueTypeName returned
163  /// by GetTypeAsSdfType.
164  ///
165  /// Derived classes providing an implementation for GetTypeAsSdfType should
166  /// also provide an implementation for this.
167  ///
168  /// \sa GetTypeAsSdfType()
169  NDR_API
170  virtual const VtValue& GetDefaultValueAsSdfType() const;
171 
172  /// @}
173 
174 protected:
175  NdrProperty& operator=(const NdrProperty&) = delete;
176 
180  bool _isOutput;
181  size_t _arraySize;
185 };
186 
188 
189 #endif // PXR_USD_NDR_PROPERTY_H
bool _isConnectable
Definition: property.h:183
size_t _arraySize
Definition: property.h:181
NDR_API int GetArraySize() const
Definition: property.h:99
virtual NDR_API const NdrTokenMap & GetMetadata() const
All of the metadata that came from the parse process.
Definition: property.h:118
virtual NDR_API bool CanConnectTo(const NdrProperty &other) const
NDR_API bool IsDynamicArray() const
Whether this property's array type is dynamically-sized.
Definition: property.h:88
virtual NDR_API std::string GetInfoString() const
NdrProperty & operator=(const NdrProperty &)=delete
NDR_API bool IsOutput() const
Whether this property is an output.
Definition: property.h:80
virtual NDR_API ~NdrProperty()
Destructor.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Definition: token.h:70
virtual NDR_API bool IsConnectable() const
Whether this property can be connected to other properties.
virtual NDR_API const VtValue & GetDefaultValueAsSdfType() const
NDR_API NdrProperty(const TfToken &name, const TfToken &type, const VtValue &defaultValue, bool isOutput, size_t arraySize, bool isDynamicArray, const NdrTokenMap &metadata)
Constructor.
virtual NDR_API NdrSdfTypeIndicator GetTypeAsSdfType() const
NDR_API const TfToken & GetName() const
Gets the name of the property.
Definition: property.h:65
GLuint const GLchar * name
Definition: glcorearb.h:786
TfToken _name
Definition: property.h:177
NDR_API const VtValue & GetDefaultValue() const
Definition: property.h:76
#define NDR_API
Definition: api.h:23
bool _isDynamicArray
Definition: property.h:182
NdrTokenMap _metadata
Definition: property.h:184
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
TfToken _type
Definition: property.h:178
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
NDR_API bool IsArray() const
Whether this property's type is an array type.
Definition: property.h:84
VtValue _defaultValue
Definition: property.h:179
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > NdrTokenMap
Definition: declare.h:52
NDR_API const TfToken & GetType() const
Gets the type of the property.
Definition: property.h:69
Definition: value.h:146
bool _isOutput
Definition: property.h:180