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 associated with the type of the
81  /// property.
82  ///
83  /// \sa GetType()
84  NDR_API
85  const VtValue& GetDefaultValue() const { return _defaultValue; }
86 
87  /// Whether this property is an output.
88  NDR_API
89  bool IsOutput() const { return _isOutput; }
90 
91  /// Whether this property's type is an array type.
92  NDR_API
93  bool IsArray() const { return (_arraySize > 0) || _isDynamicArray; }
94 
95  /// Whether this property's array type is dynamically-sized.
96  NDR_API
97  bool IsDynamicArray() const { return _isDynamicArray; };
98 
99  /// Gets this property's array size.
100  ///
101  /// If this property is a fixed-size array type, the array size is returned.
102  /// In the case of a dynamically-sized array, this method returns the array
103  /// size that the parser reports, and should not be relied upon to be
104  /// accurate. A parser may report -1 for the array size, for example, to
105  /// indicate a dynamically-sized array. For types that are not a fixed-size
106  /// array or dynamic array, this returns 0.
107  NDR_API
108  int GetArraySize() const { return _arraySize; }
109 
110  /// Gets a string with basic information about this property. Helpful for
111  /// things like adding this property to a log.
112  NDR_API
113  virtual std::string GetInfoString() const;
114 
115  /// @}
116 
117 
118  /// \name Metadata
119  /// The metadata returned here is a direct result of what the parser plugin
120  /// is able to determine about the node. See the documentation for a
121  /// specific parser plugin to get help on what the parser is looking for to
122  /// populate these values.
123  /// @{
124 
125  /// All of the metadata that came from the parse process.
126  NDR_API
127  virtual const NdrTokenMap& GetMetadata() const { return _metadata; }
128 
129  /// @}
130 
131 
132  /// \name Connection Information
133  /// @{
134 
135  /// Whether this property can be connected to other properties.
136  NDR_API
137  virtual bool IsConnectable() const;
138 
139  /// Determines if this property can be connected to the specified property.
140  NDR_API
141  virtual bool CanConnectTo(const NdrProperty& other) const;
142 
143  /// @}
144 
145 
146  /// \name Utilities
147  /// @{
148 
149  /// Converts the property's type from `GetType()` into a `SdfValueTypeName`.
150  ///
151  /// Two scenarios can result: an exact mapping from property type to Sdf
152  /// type, and an inexact mapping. In the first scenario, the first element
153  /// in the pair will be the cleanly-mapped Sdf type, and the second element,
154  /// a TfToken, will be empty. In the second scenario, the Sdf type will be
155  /// set to `Token` to indicate an unclean mapping, and the second element
156  /// will be set to the original type returned by `GetType()`.
157  ///
158  /// This base property class is generic and cannot know ahead of time how to
159  /// perform this mapping reliably, thus it will always fall into the second
160  /// scenario. It is up to specialized properties to perform the mapping.
161  ///
162  /// \sa GetDefaultValueAsSdfType()
163  NDR_API
164  virtual const NdrSdfTypeIndicator GetTypeAsSdfType() const;
165 
166  /// Provides default value corresponding to the SdfValueTypeName returned
167  /// by GetTypeAsSdfType.
168  ///
169  /// Derived classes providing an implementation for GetTypeAsSdfType should
170  /// also provide an implementation for this.
171  ///
172  /// \sa GetTypeAsSdfType()
173  NDR_API
174  virtual const VtValue& GetDefaultValueAsSdfType() const;
175 
176  /// @}
177 
178 protected:
179  NdrProperty& operator=(const NdrProperty&) = delete;
180 
184  bool _isOutput;
185  size_t _arraySize;
189 };
190 
192 
193 #endif // PXR_USD_NDR_PROPERTY_H
bool _isConnectable
Definition: property.h:187
size_t _arraySize
Definition: property.h:185
NDR_API int GetArraySize() const
Definition: property.h:108
virtual NDR_API const NdrTokenMap & GetMetadata() const
All of the metadata that came from the parse process.
Definition: property.h:127
virtual NDR_API bool CanConnectTo(const NdrProperty &other) const
Determines if this property can be connected to the specified property.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
NDR_API bool IsDynamicArray() const
Whether this property's array type is dynamically-sized.
Definition: property.h:97
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:89
std::pair< SdfValueTypeName, TfToken > NdrSdfTypeIndicator
Definition: declare.h:83
virtual NDR_API ~NdrProperty()
Destructor.
Definition: token.h:87
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.
NDR_API const TfToken & GetName() const
Gets the name of the property.
Definition: property.h:74
GLuint const GLchar * name
Definition: glcorearb.h:786
TfToken _name
Definition: property.h:181
NDR_API const VtValue & GetDefaultValue() const
Definition: property.h:85
#define NDR_API
Definition: api.h:40
bool _isDynamicArray
Definition: property.h:186
NdrTokenMap _metadata
Definition: property.h:188
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
TfToken _type
Definition: property.h:182
#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:93
VtValue _defaultValue
Definition: property.h:183
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > NdrTokenMap
Definition: declare.h:61
type
Definition: core.h:1059
NDR_API const TfToken & GetType() const
Gets the type of the property.
Definition: property.h:78
Definition: value.h:167
virtual NDR_API const NdrSdfTypeIndicator GetTypeAsSdfType() const
bool _isOutput
Definition: property.h:184