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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_USD_NDR_PROPERTY_H
26 #define PXR_USD_NDR_PROPERTY_H
27 
28 /// \file ndr/property.h
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/ndr/api.h"
32 #include "pxr/base/tf/token.h"
33 #include "pxr/base/vt/value.h"
34 #include "pxr/usd/ndr/declare.h"
35 
37 
38 /// \class NdrProperty
39 ///
40 /// Represents a property (input or output) that is part of a `NdrNode`
41 /// instance.
42 ///
43 /// A property must have a name and type, but may also specify a host of
44 /// additional metadata. Instances can also be queried to determine if another
45 /// `NdrProperty` instance can be connected to it.
46 ///
47 /// In almost all cases, this class will not be used directly. More specialized
48 /// properties can be created that derive from `NdrProperty`; those specialized
49 /// properties can add their own domain-specific data and methods.
51 {
52 public:
53  /// Constructor.
54  NDR_API
56  const TfToken& name,
57  const TfToken& type,
58  const VtValue& defaultValue,
59  bool isOutput,
60  size_t arraySize,
61  bool isDynamicArray,
62  const NdrTokenMap& metadata
63  );
64 
65  /// Destructor.
66  NDR_API
67  virtual ~NdrProperty();
68 
69  /// \name The Basics
70  /// @{
71 
72  /// Gets the name of the property.
73  NDR_API
74  const TfToken& GetName() const { return _name; }
75 
76  /// Gets the type of the property.
77  NDR_API
78  const TfToken& GetType() const { return _type; }
79 
80  /// Gets this property's default value.
81  NDR_API
82  const VtValue& GetDefaultValue() const { return _defaultValue; }
83 
84  /// Whether this property is an output.
85  NDR_API
86  bool IsOutput() const { return _isOutput; }
87 
88  /// Whether this property's type is an array type.
89  NDR_API
90  bool IsArray() const { return (_arraySize > 0) || _isDynamicArray; }
91 
92  /// Whether this property's array type is dynamically-sized.
93  NDR_API
94  bool IsDynamicArray() const { return _isDynamicArray; };
95 
96  /// Gets this property's array size.
97  ///
98  /// If this property is a fixed-size array type, the array size is returned.
99  /// In the case of a dynamically-sized array, this method returns the array
100  /// size that the parser reports, and should not be relied upon to be
101  /// accurate. A parser may report -1 for the array size, for example, to
102  /// indicate a dynamically-sized array. For types that are not a fixed-size
103  /// array or dynamic array, this returns 0.
104  NDR_API
105  int GetArraySize() const { return _arraySize; }
106 
107  /// Gets a string with basic information about this property. Helpful for
108  /// things like adding this property to a log.
109  NDR_API
110  virtual std::string GetInfoString() const;
111 
112  /// @}
113 
114 
115  /// \name Metadata
116  /// The metadata returned here is a direct result of what the parser plugin
117  /// is able to determine about the node. See the documentation for a
118  /// specific parser plugin to get help on what the parser is looking for to
119  /// populate these values.
120  /// @{
121 
122  /// All of the metadata that came from the parse process.
123  NDR_API
124  virtual const NdrTokenMap& GetMetadata() const { return _metadata; }
125 
126  /// @}
127 
128 
129  /// \name Connection Information
130  /// @{
131 
132  /// Whether this property can be connected to other properties.
133  NDR_API
134  virtual bool IsConnectable() const;
135 
136  /// Determines if this property can be connected to the specified property.
137  NDR_API
138  virtual bool CanConnectTo(const NdrProperty& other) const;
139 
140  /// @}
141 
142 
143  /// \name Utilities
144  /// @{
145 
146  /// Converts the property's type from `GetType()` into a `SdfValueTypeName`.
147  ///
148  /// Two scenarios can result: an exact mapping from property type to Sdf
149  /// type, and an inexact mapping. In the first scenario, the first element
150  /// in the pair will be the cleanly-mapped Sdf type, and the second element,
151  /// a TfToken, will be empty. In the second scenario, the Sdf type will be
152  /// set to `Token` to indicate an unclean mapping, and the second element
153  /// will be set to the original type returned by `GetType()`.
154  ///
155  /// This base property class is generic and cannot know ahead of time how to
156  /// perform this mapping reliably, thus it will always fall into the second
157  /// scenario. It is up to specialized properties to perform the mapping.
158  NDR_API
159  virtual const SdfTypeIndicator GetTypeAsSdfType() const;
160 
161  /// @}
162 
163 protected:
164  NdrProperty& operator=(const NdrProperty&) = delete;
165 
169  bool _isOutput;
170  size_t _arraySize;
174 };
175 
177 
178 #endif // PXR_USD_NDR_PROPERTY_H
bool _isConnectable
Definition: property.h:172
size_t _arraySize
Definition: property.h:170
std::pair< SdfValueTypeName, TfToken > SdfTypeIndicator
Definition: declare.h:83
NDR_API int GetArraySize() const
Definition: property.h:105
GLuint const GLchar * name
Definition: glew.h:1814
virtual NDR_API const NdrTokenMap & GetMetadata() const
All of the metadata that came from the parse process.
Definition: property.h:124
virtual NDR_API bool CanConnectTo(const NdrProperty &other) const
Determines if this property can be connected to the specified property.
NDR_API bool IsDynamicArray() const
Whether this property's array type is dynamically-sized.
Definition: property.h:94
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:86
virtual NDR_API ~NdrProperty()
Destructor.
Definition: token.h:87
virtual NDR_API bool IsConnectable() const
Whether this property can be connected to other properties.
NDR_API NdrProperty(const TfToken &name, const TfToken &type, const VtValue &defaultValue, bool isOutput, size_t arraySize, bool isDynamicArray, const NdrTokenMap &metadata)
Constructor.
NDR_API const TfToken & GetName() const
Gets the name of the property.
Definition: property.h:74
TfToken _name
Definition: property.h:166
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
virtual NDR_API const SdfTypeIndicator GetTypeAsSdfType() const
NDR_API const VtValue & GetDefaultValue() const
Gets this property's default value.
Definition: property.h:82
#define NDR_API
Definition: api.h:40
bool _isDynamicArray
Definition: property.h:171
GLsizei const GLchar *const * string
Definition: glew.h:1844
NdrTokenMap _metadata
Definition: property.h:173
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
TfToken _type
Definition: property.h:167
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
NDR_API bool IsArray() const
Whether this property's type is an array type.
Definition: property.h:90
VtValue _defaultValue
Definition: property.h:168
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > NdrTokenMap
Definition: declare.h:61
NDR_API const TfToken & GetType() const
Gets the type of the property.
Definition: property.h:78
Definition: value.h:174
bool _isOutput
Definition: property.h:169