HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
valueTypeName.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 #ifndef PXR_USD_SDF_VALUE_TYPE_NAME_H
25 #define PXR_USD_SDF_VALUE_TYPE_NAME_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/api.h"
29 #include "pxr/base/tf/token.h"
30 
31 #include <iosfwd>
32 #include <string>
33 #include <vector>
34 
36 
37 class TfEnum;
38 class TfType;
39 class VtValue;
40 class Sdf_ValueTypeImpl;
41 
42 /// \struct SdfTupleDimensions
43 ///
44 /// Represents the shape of a value type (or that of an element in an array).
45 ///
47 {
48 public:
50  SdfTupleDimensions(size_t m) : size(1) { d[0] = m; }
51  SdfTupleDimensions(size_t m, size_t n) : size(2) { d[0] = m; d[1] = n; }
52  SdfTupleDimensions(const size_t (&s)[2])
53  : size(2) { d[0] = s[0]; d[1] = s[1]; }
54 
55  SDF_API
56  bool operator==(const SdfTupleDimensions& rhs) const;
57  bool operator!=(const SdfTupleDimensions& rhs) const {
58  return !(*this == rhs);
59  }
60 
61 public:
62  size_t d[2];
63  size_t size;
64 };
65 
66 /// \class SdfValueTypeName
67 ///
68 /// Represents a value type name, i.e. an attribute's type name. Usually,
69 /// a value type name associates a string with a \c TfType and an optional
70 /// role, along with additional metadata. A schema registers all known
71 /// value type names and may register multiple names for the same TfType
72 /// and role pair. All name strings for a given pair are collectively
73 /// called its aliases.
74 ///
75 /// A value type name may also represent just a name string, without a
76 /// \c TfType, role or other metadata. This is currently used exclusively
77 /// to unserialize and re-serialize an attribute's type name where that
78 /// name is not known to the schema.
79 ///
80 /// Because value type names can have aliases and those aliases may change
81 /// in the future, clients should avoid using the value type name's string
82 /// representation except to report human readable messages and when
83 /// serializing. Clients can look up a value type name by string using
84 /// \c SdfSchemaBase::FindType() and shouldn't otherwise need the string.
85 /// Aliases compare equal, even if registered by different schemas.
86 ///
88 {
89 public:
90  /// Constructs an invalid type name.
91  SDF_API
93 
94  /// Returns the type name as a token. This should not be used for
95  /// comparison purposes.
96  SDF_API
97  TfToken GetAsToken() const;
98 
99  /// Returns the \c TfType of the type.
100  SDF_API
101  const TfType& GetType() const;
102 
103  /// Returns the C++ type name for this type. This may not be the same
104  /// as the type name returned by GetType().GetTypeName(), since that
105  /// method may have had additional transformations applied for
106  /// readability.
107  SDF_API
108  const std::string& GetCPPTypeName() const;
109 
110  /// Returns the type's role.
111  SDF_API
112  const TfToken& GetRole() const;
113 
114  /// Returns the default value for the type.
115  SDF_API
116  const VtValue& GetDefaultValue() const;
117 
118  /// Returns the default unit enum for the type.
119  SDF_API
120  const TfEnum& GetDefaultUnit() const;
121 
122  /// Returns the scalar version of this type name if it's an array type
123  /// name, otherwise returns this type name. If there is no scalar type
124  /// name then this returns the invalid type name.
125  SDF_API
126  SdfValueTypeName GetScalarType() const;
127 
128  /// Returns the array version of this type name if it's an scalar type
129  /// name, otherwise returns this type name. If there is no array type
130  /// name then this returns the invalid type name.
131  SDF_API
132  SdfValueTypeName GetArrayType() const;
133 
134  /// Returns \c true iff this type is a scalar. The invalid type is
135  /// considered neither scalar nor array.
136  SDF_API
137  bool IsScalar() const;
138 
139  /// Returns \c true iff this type is an array. The invalid type is
140  /// considered neither scalar nor array.
141  SDF_API
142  bool IsArray() const;
143 
144  /// Returns the dimensions of the scalar value, e.g. 3 for a 3D point.
145  SDF_API
147 
148  /// Returns \c true if this type name is equal to \p rhs. Aliases
149  /// compare equal.
150  SDF_API
151  bool operator==(const SdfValueTypeName& rhs) const;
152  bool operator!=(const SdfValueTypeName& rhs) const {
153  return !(*this == rhs);
154  }
155 
156  /// Returns \c true if this type name is equal to \p rhs. Aliases
157  /// compare equal. Avoid relying on this overload.
158  SDF_API
159  bool operator==(const std::string& rhs) const;
160  bool operator!=(const std::string& rhs) const {
161  return !(*this == rhs);
162  }
163 
164  /// Returns \c true if this type name is equal to \p rhs. Aliases
165  /// compare equal. Avoid relying on this overload.
166  SDF_API
167  bool operator==(const TfToken& rhs) const;
168  bool operator!=(const TfToken& rhs) const {
169  return !(*this == rhs);
170  }
171 
172  friend inline
173  bool operator==(const std::string& lhs, const SdfValueTypeName& rhs) {
174  return rhs == lhs;
175  }
176  friend inline
177  bool operator!=(const std::string& lhs, const SdfValueTypeName& rhs) {
178  return !(rhs == lhs);
179  }
180 
181  friend inline
182  bool operator==(const TfToken& lhs, const SdfValueTypeName &rhs) {
183  return rhs == lhs;
184  }
185  friend inline
186  bool operator!=(const TfToken& lhs, const SdfValueTypeName &rhs) {
187  return !(rhs == lhs);
188  }
189 
190  /// Returns a hash value for this type name.
191  SDF_API
192  size_t GetHash() const;
193 
194  /// Explicit bool conversion operator. Converts to \c true if this is a
195  /// valid, non-empty type, \c false otherwise.
196  explicit operator bool() const
197  {
198  return !_IsEmpty();
199  }
200 
201  /// Returns all aliases of the type name as tokens. These should not
202  /// be used for comparison purposes.
203  SDF_API
204  std::vector<TfToken> GetAliasesAsTokens() const;
205 
206 private:
207  friend class Sdf_ValueTypeRegistry;
208  friend struct Sdf_ValueTypePrivate;
209 
210  SDF_API
211  explicit SdfValueTypeName(const Sdf_ValueTypeImpl*);
212 
213  SDF_API
214  bool _IsEmpty() const;
215 
216 private:
217  const Sdf_ValueTypeImpl* _impl;
218 };
219 
220 /// Functor for hashing a \c SdfValueTypeName.
222  size_t operator()(const SdfValueTypeName& x) const
223  {
224  return x.GetHash();
225  }
226 };
227 
228 inline size_t
229 hash_value(const SdfValueTypeName& typeName)
230 {
231  return typeName.GetHash();
232 }
233 
234 SDF_API std::ostream& operator<<(std::ostream&, const SdfValueTypeName& typeName);
235 
237 
238 #endif // PXR_USD_SDF_VALUE_TYPE_NAME_H
friend bool operator==(const std::string &lhs, const SdfValueTypeName &rhs)
SDF_API const VtValue & GetDefaultValue() const
Returns the default value for the type.
bool operator!=(const SdfValueTypeName &rhs) const
bool operator!=(const SdfTupleDimensions &rhs) const
Definition: valueTypeName.h:57
friend bool operator==(const TfToken &lhs, const SdfValueTypeName &rhs)
SdfTupleDimensions(size_t m, size_t n)
Definition: valueTypeName.h:51
SDF_API const std::string & GetCPPTypeName() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
bool operator!=(const TfToken &rhs) const
size_t hash_value(const SdfValueTypeName &typeName)
GLdouble s
Definition: glad.h:3009
Definition: enum.h:136
SDF_API SdfValueTypeName GetScalarType() const
SDF_API SdfTupleDimensions GetDimensions() const
Returns the dimensions of the scalar value, e.g. 3 for a 3D point.
SDF_API std::ostream & operator<<(std::ostream &, const SdfValueTypeName &typeName)
SdfTupleDimensions(const size_t(&s)[2])
Definition: valueTypeName.h:52
SDF_API bool IsScalar() const
SDF_API TfToken GetAsToken() const
SDF_API bool IsArray() const
GLdouble n
Definition: glcorearb.h:2008
Definition: token.h:87
friend bool operator!=(const TfToken &lhs, const SdfValueTypeName &rhs)
SDF_API SdfValueTypeName()
Constructs an invalid type name.
SDF_API const TfEnum & GetDefaultUnit() const
Returns the default unit enum for the type.
GLint GLenum GLint x
Definition: glcorearb.h:409
SDF_API const TfToken & GetRole() const
Returns the type's role.
friend bool operator!=(const std::string &lhs, const SdfValueTypeName &rhs)
SDF_API bool operator==(const SdfValueTypeName &rhs) const
#define SDF_API
Definition: api.h:40
GLsizeiptr size
Definition: glcorearb.h:664
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
Functor for hashing a SdfValueTypeName.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SDF_API std::vector< TfToken > GetAliasesAsTokens() const
Definition: type.h:64
friend class Sdf_ValueTypeRegistry
size_t operator()(const SdfValueTypeName &x) const
friend struct Sdf_ValueTypePrivate
bool operator!=(const std::string &rhs) const
SDF_API const TfType & GetType() const
Returns the TfType of the type.
SDF_API SdfValueTypeName GetArrayType() const
SdfTupleDimensions(size_t m)
Definition: valueTypeName.h:50
SDF_API size_t GetHash() const
Returns a hash value for this type name.
Definition: value.h:164
SDF_API bool operator==(const SdfTupleDimensions &rhs) const