valueTypeName.h
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 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 class TfEnum;
38 class TfType;
39 class VtValue;
40 class Sdf_ValueTypeImpl;
41 
47 {
48 public:
49  SdfTupleDimensions() : size(0) {}
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 
88 {
89 public:
91  SDF_API
93 
96  SDF_API
97  TfToken GetAsToken() const;
98 
100  SDF_API
101  const TfType& GetType() const;
102 
107  SDF_API
108  const std::string& GetCPPTypeName() const;
109 
111  SDF_API
112  const TfToken& GetRole() const;
113 
115  SDF_API
116  const VtValue& GetDefaultValue() const;
117 
119  SDF_API
120  const TfEnum& GetDefaultUnit() const;
121 
125  SDF_API
127 
131  SDF_API
133 
136  SDF_API
137  bool IsScalar() const;
138 
141  SDF_API
142  bool IsArray() const;
143 
145  SDF_API
147 
150  SDF_API
151  bool operator==(const SdfValueTypeName& rhs) const;
152  bool operator!=(const SdfValueTypeName& rhs) const {
153  return !(*this == rhs);
154  }
155 
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 
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 
191  SDF_API
192  size_t GetHash() const;
193 
196  explicit operator bool() const
197  {
198  return !_IsEmpty();
199  }
200 
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 
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 
236 PXR_NAMESPACE_CLOSE_SCOPE
237 
238 #endif // PXR_USD_SDF_VALUE_TYPE_NAME_H
SDF_API bool IsScalar() const
Returns true iff this type is a scalar.
SDF_API bool IsArray() const
Returns true iff this type is an array.
SDF_API std::vector< TfToken > GetAliasesAsTokens() const
Returns all aliases of the type name as tokens.
SDF_API const TfToken & GetRole() const
Returns the type's role.
An enum class that records both enum type and enum value.
Definition: enum.h:139
Represents a value type name, i.e.
Definition: valueTypeName.h:87
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
SDF_API bool operator==(const SdfValueTypeName &rhs) const
Returns true if this type name is equal to rhs.
SDF_API const TfEnum & GetDefaultUnit() const
Returns the default unit enum for the type.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
SDF_API const std::string & GetCPPTypeName() const
Returns the C++ type name for this type.
SDF_API SdfValueTypeName()
Constructs an invalid type name.
SDF_API SdfValueTypeName GetArrayType() const
Returns the array version of this type name if it's an scalar type name, otherwise returns this type ...
Functor for hashing a SdfValueTypeName.
SDF_API SdfTupleDimensions GetDimensions() const
Returns the dimensions of the scalar value, e.g. 3 for a 3D point.
TfType represents a dynamic runtime type.
Definition: type.h:64
Represents the shape of a value type (or that of an element in an array).
Definition: valueTypeName.h:46
SDF_API TfToken GetAsToken() const
Returns the type name as a token.
SDF_API const TfType & GetType() const
Returns the TfType of the type.
SDF_API const VtValue & GetDefaultValue() const
Returns the default value for the type.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:168
SDF_API SdfValueTypeName GetScalarType() const
Returns the scalar version of this type name if it's an array type name, otherwise returns this type ...
SDF_API size_t GetHash() const
Returns a hash value for this type name.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...