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_TYPES_H
25 #define PXR_USD_SDF_TYPES_H
26 
27 /// \file sdf/types.h
28 /// Basic Sdf data types
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/sdf/api.h"
32 #include "pxr/usd/sdf/assetPath.h"
33 #include "pxr/usd/sdf/declareHandles.h"
34 #include "pxr/usd/sdf/listOp.h"
35 #include "pxr/usd/sdf/timeCode.h"
36 #include "pxr/usd/sdf/valueTypeName.h"
37 
38 #include "pxr/base/arch/demangle.h"
39 #include "pxr/base/arch/inttypes.h"
40 #include "pxr/base/gf/half.h"
41 #include "pxr/base/gf/matrix2d.h"
42 #include "pxr/base/gf/matrix3d.h"
43 #include "pxr/base/gf/matrix4d.h"
44 #include "pxr/base/gf/quatd.h"
45 #include "pxr/base/gf/quatf.h"
46 #include "pxr/base/gf/quath.h"
47 #include "pxr/base/gf/vec2d.h"
48 #include "pxr/base/gf/vec2f.h"
49 #include "pxr/base/gf/vec2h.h"
50 #include "pxr/base/gf/vec2i.h"
51 #include "pxr/base/gf/vec3d.h"
52 #include "pxr/base/gf/vec3f.h"
53 #include "pxr/base/gf/vec3h.h"
54 #include "pxr/base/gf/vec3i.h"
55 #include "pxr/base/gf/vec4d.h"
56 #include "pxr/base/gf/vec4f.h"
57 #include "pxr/base/gf/vec4h.h"
58 #include "pxr/base/gf/vec4i.h"
59 #include "pxr/base/tf/enum.h"
60 #include "pxr/base/tf/preprocessorUtils.h"
61 #include "pxr/base/tf/staticTokens.h"
62 #include "pxr/base/tf/token.h"
63 #include "pxr/base/tf/type.h"
64 #include "pxr/base/vt/array.h"
65 #include "pxr/base/vt/dictionary.h"
66 #include "pxr/base/vt/value.h"
67 
68 #include <boost/noncopyable.hpp>
69 #include <boost/preprocessor/list/for_each.hpp>
70 #include <boost/preprocessor/list/size.hpp>
71 #include <boost/preprocessor/punctuation/comma.hpp>
72 #include <boost/preprocessor/selection/max.hpp>
73 #include <boost/preprocessor/seq/for_each.hpp>
74 #include <boost/preprocessor/seq/seq.hpp>
75 #include <boost/preprocessor/tuple/elem.hpp>
76 #include <boost/shared_ptr.hpp>
77 #include <iosfwd>
78 #include <list>
79 #include <map>
80 #include <stdint.h>
81 #include <string>
82 #include <typeinfo>
83 #include <vector>
84 
85 PXR_NAMESPACE_OPEN_SCOPE
86 
87 class SdfPath;
88 
89 /// An enum that specifies the type of an object. Objects
90 /// are entities that have fields and are addressable by path.
91 enum SdfSpecType {
92     // The unknown type has a value of 0 so that SdfSpecType() is unknown.
93     SdfSpecTypeUnknown = 0,
94 
95     // Real concrete types
96     SdfSpecTypeAttribute,
97     SdfSpecTypeConnection,
98     SdfSpecTypeExpression,
99     SdfSpecTypeMapper,
100     SdfSpecTypeMapperArg,
101     SdfSpecTypePrim,
102     SdfSpecTypePseudoRoot,
103     SdfSpecTypeRelationship,
104     SdfSpecTypeRelationshipTarget,
105     SdfSpecTypeVariant,
106     SdfSpecTypeVariantSet,
107 
108     SdfNumSpecTypes
109 };
110 
111 /// An enum that identifies the possible specifiers for an
112 /// SdfPrimSpec. The SdfSpecifier enum is registered as a TfEnum
113 /// for converting to and from <c>std::string</c>.
114 ///
115 /// <b>SdfSpecifier:</b>
116 /// <ul>
117 /// <li><b>SdfSpecifierDef.</b> Defines a concrete prim.
118 /// <li><b>SdfSpecifierOver.</b> Overrides an existing prim.
119 /// <li><b>SdfSpecifierClass.</b> Defines an abstract prim.
120 /// <li><b>SdfNumSpecifiers.</b> The number of specifiers.
121 /// </ul>
122 ///
123 enum SdfSpecifier {
124     SdfSpecifierDef,
125     SdfSpecifierOver,
126     SdfSpecifierClass,
127     SdfNumSpecifiers
128 };
129 
130 /// Returns true if the specifier defines a prim.
131 inline
132 bool
SdfIsDefiningSpecifier(SdfSpecifier spec)133 SdfIsDefiningSpecifier(SdfSpecifier spec)
134 {
135     return (spec != SdfSpecifierOver);
136 }
137 
138 /// An enum that defines permission levels.
139 ///
140 /// Permissions control which layers may refer to or express
141 /// opinions about a prim.  Opinions expressed about a prim, or
142 /// relationships to that prim, by layers that are not allowed
143 /// permission to access the prim will be ignored.
144 ///
145 /// <b>SdfPermission:</b>
146 /// <ul>
147 /// <li><b>SdfPermissionPublic.</b> Public prims can be referred to by
148 ///     anything. (Available to any client.)
149 /// <li><b>SdfPermissionPrivate.</b> Private prims can be referred to
150 ///     only within the local layer stack, and not across references
151 ///     or inherits. (Not available to clients.)
152 /// <li><b>SdfNumPermission.</b> Internal sentinel value.
153 /// </ul>
154 ///
155 enum SdfPermission {
156     SdfPermissionPublic,
157     SdfPermissionPrivate,
158 
159     SdfNumPermissions
160 };
161 
162 /// An enum that identifies variability types for attributes.
163 /// Variability indicates whether the attribute may vary over time and
164 /// value coordinates, and if its value comes through authoring or
165 /// or from its owner.
166 ///
167 /// <b>SdfVariability:</b>
168 /// <ul>
169 ///     <li><b>SdfVariabilityVarying.</b> Varying attributes may be directly
170 ///            authored, animated and affected on by Actions.  They are the
171 ///            most flexible.
172 ///     <li><b>SdfVariabilityUniform.</b> Uniform attributes may be authored
173 ///            only with non-animated values (default values).  They cannot
174 ///            be affected by Actions, but they can be connected to other
175 ///            Uniform attributes.
176 ///     <li><b>SdNumVariabilities.</b> Internal sentinel value.
177 /// </ul>
178 ///
179 enum SdfVariability {
180     SdfVariabilityVarying,
181     SdfVariabilityUniform,
182 
183     SdfNumVariabilities
184 };
185 
186 
187 /// An enum for TfError codes related to authoring operations.
188 ///
189 /// <b>SdfAuthoringError:</b>
190 /// <ul>
191 ///     <li><b>SdfAuthoringErrorUnrecognizedFields.</b> This error is raised if
192 ///            SdfLayer::TransferContent, or SdfLayer::SetField API is called
193 ///            for layers of differing schema, and fields from the source layer
194 ///            are not recognized by the target layer's schema.
195 ///     <li><b>SdfAuthoringErrorUnrecognizedSpecType.</b> This error is raised
196 ///            in attempts to create specs on layers with spec types that are
197 ///            not recognized by the layer's schema.
198 /// </ul>
199 ///
200 enum SdfAuthoringError
201 {
202     SdfAuthoringErrorUnrecognizedFields,
203     SdfAuthoringErrorUnrecognizedSpecType
204 };
205 
206 // Each category of compatible units of measurement is defined by a
207 // preprocessor sequence of tuples.  Each such sequence gives rise to an enum
208 // representing the corresponding unit category.  All the unit categories are
209 // listed in _SDF_UNITS where each entry is a two-tuple with the unit category
210 // name as the first element, and the second element is the units in that
211 // category.  Each tuple in a unit category sequence corresponds to a unit of
212 // measurement represented by an enumerant whose name is given by concatenating
213 // 'Sdf', the unit category name, the word 'Unit' and the first entry in the
214 // tuple.  (E.g. units of category 'Length' are represented by an enum named
215 // SdfLengthUnit with enumerants SdfLengthUnitInch, SdfLengthUnitMeter and so
216 // forth.)  The second element in the tuple is the display name for the unit,
217 // and the third element is the relative size of the unit compared to the menv
218 // default unit for the unit category (which has a relative size of 1.0).
219 // Dimensionless quantities use a special 'Dimensionless' unit category
220 // represented by the enum SdfDimensionlessUnit.
221 #define _SDF_LENGTH_UNITS       \
222 ((Millimeter, "mm",  0.001))    \
223 ((Centimeter, "cm",  0.01))     \
224 ((Decimeter,  "dm",  0.1))      \
225 ((Meter,      "m",   1.0))      \
226 ((Kilometer,  "km",  1000.0))   \
227 ((Inch,       "in",  0.0254))   \
228 ((Foot,       "ft",  0.3048))   \
229 ((Yard,       "yd",  0.9144))   \
230 ((Mile,       "mi",  1609.344))
231 
232 #define _SDF_ANGULAR_UNITS      \
233 ((Degrees, "deg", 1.0))         \
234 ((Radians, "rad", 57.2957795130823208768))
235 
236 #define _SDF_DIMENSIONLESS_UNITS \
237 ((Percent, "%", 0.01))           \
238 ((Default, "default", 1.0))
239 
240 #define _SDF_UNITS                          \
241 ((Length, _SDF_LENGTH_UNITS),               \
242 ((Angular, _SDF_ANGULAR_UNITS),             \
243 ((Dimensionless, _SDF_DIMENSIONLESS_UNITS), \
244  BOOST_PP_NIL)))
245 
246 #define _SDF_UNIT_TAG(tup) BOOST_PP_TUPLE_ELEM(3, 0, tup)
247 #define _SDF_UNIT_NAME(tup) BOOST_PP_TUPLE_ELEM(3, 1, tup)
248 #define _SDF_UNIT_SCALE(tup) BOOST_PP_TUPLE_ELEM(3, 2, tup)
249 
250 #define _SDF_UNITSLIST_CATEGORY(tup) BOOST_PP_TUPLE_ELEM(2, 0, tup)
251 #define _SDF_UNITSLIST_TUPLES(tup) BOOST_PP_TUPLE_ELEM(2, 1, tup)
252 #define _SDF_UNITSLIST_ENUM(elem) BOOST_PP_CAT(BOOST_PP_CAT(Sdf, \
253                                     _SDF_UNITSLIST_CATEGORY(elem)), Unit)
254 
255 #define _SDF_DECLARE_UNIT_ENUMERANT(r, tag, elem) \
256     BOOST_PP_CAT(Sdf ## tag ## Unit, _SDF_UNIT_TAG(elem)),
257 
258 #define _SDF_DECLARE_UNIT_ENUM(r, unused, elem)          \
259 enum _SDF_UNITSLIST_ENUM(elem) {                         \
260     BOOST_PP_SEQ_FOR_EACH(_SDF_DECLARE_UNIT_ENUMERANT,   \
261                           _SDF_UNITSLIST_CATEGORY(elem), \
262                           _SDF_UNITSLIST_TUPLES(elem))   \
263 };
264 BOOST_PP_LIST_FOR_EACH(_SDF_DECLARE_UNIT_ENUM, ~, _SDF_UNITS)
265 
266 // Compute the max number of enumerants over all unit enums
267 #define _SDF_MAX_UNITS_OP(d, state, list) \
268     BOOST_PP_MAX_D(d, state, BOOST_PP_SEQ_SIZE(_SDF_UNITSLIST_TUPLES(list)))
269 #define _SDF_UNIT_MAX_UNITS \
270     BOOST_PP_LIST_FOLD_LEFT(_SDF_MAX_UNITS_OP, 0, _SDF_UNITS)
271 
272 // Compute the number of unit enums
273 #define _SDF_UNIT_NUM_TYPES BOOST_PP_LIST_SIZE(_SDF_UNITS)
274 
275 // Compute the number of bits needed to hold _SDF_UNIT_MAX_UNITS and
276 // _SDF_UNIT_NUM_TYPES.
277 #define _SDF_UNIT_MAX_UNITS_BITS TF_BITS_FOR_VALUES(_SDF_UNIT_MAX_UNITS)
278 #define _SDF_UNIT_TYPES_BITS     TF_BITS_FOR_VALUES(_SDF_UNIT_NUM_TYPES)
279 
280 /// A map of mapper parameter names to parameter values.
281 typedef std::map<std::string, VtValue> SdfMapperParametersMap;
282 
283 /// A map of reference variant set names to variants in those sets.
284 typedef std::map<std::string, std::string> SdfVariantSelectionMap;
285 
286 /// A map of variant set names to list of variants in those sets.
287 typedef std::map<std::string, std::vector<std::string> > SdfVariantsMap;
288 
289 /// A map of source SdfPaths to target SdfPaths for relocation.
290 //  Note: This map needs to be lexicographically sorted for Csd composition
291 //        implementation, so SdfPath::FastLessThan is explicitly omitted as
292 //        the Compare template parameter.
293 typedef std::map<SdfPath, SdfPath> SdfRelocatesMap;
294 
295 /// A map from sample times to sample values.
296 typedef std::map<double, VtValue> SdfTimeSampleMap;
297 
298 /// Gets the show default unit for the given /a typeName.
299 SDF_API TfEnum SdfDefaultUnit( TfToken const &typeName );
300 
301 /// Gets the show default unit for the given /a unit.
302 SDF_API const TfEnum &SdfDefaultUnit( const TfEnum &unit );
303 
304 /// Gets the unit category for a given /a unit.
305 SDF_API const std::string &SdfUnitCategory( const TfEnum &unit );
306 
307 /// Converts from one unit of measure to another. The \a fromUnit and \a toUnit
308 /// units must be of the same type (for example, both of type SdfLengthUnit).
309 SDF_API double SdfConvertUnit( const TfEnum &fromUnit, const TfEnum &toUnit );
310 
311 /// Gets the name for a given /a unit.
312 SDF_API const std::string &SdfGetNameForUnit( const TfEnum &unit );
313 
314 /// Gets a unit for the given /a name
315 SDF_API const TfEnum &SdfGetUnitFromName( const std::string &name );
316 
317 /// Given a value, returns if there is a valid corresponding valueType.
318 SDF_API bool SdfValueHasValidType(VtValue const& value);
319 
320 /// Given an sdf valueType name, produce TfType if the type name specifies a
321 /// valid sdf value type.
322 SDF_API TfType SdfGetTypeForValueTypeName(TfToken const &name);
323 
324 /// Given a value, produce the sdf valueType name.  If you provide a value that
325 /// does not return true for SdfValueHasValidType, the return value is
326 /// unspecified.
327 SDF_API SdfValueTypeName SdfGetValueTypeNameForValue(VtValue const &value);
328 
329 /// Return role name for \p typeName.  Return empty token if \p typeName has no
330 /// associated role name.
331 SDF_API TfToken SdfGetRoleNameForValueTypeName(TfToken const &typeName);
332 
333 // Sdf allows a specific set of types for attribute and metadata values.
334 // These types and some additional metadata are listed in the preprocessor
335 // sequence of tuples below. First element is a tag name that is appended to
336 // 'SdfValueType' to produce the C++ traits type for the value type.
337 // Second element is the value type name, third element is the corresponding
338 // C++ type, and the fourth element is the tuple of tuple dimensions.
339 //
340 // Libraries may extend this list and define additional value types.
341 // When doing so, the type must be declared using the SDF_DECLARE_VALUE_TYPE
342 // macro below. The type must also be registered in the associated schema using
343 // SdfSchema::_RegisterValueType(s).
344 #define _SDF_SCALAR_VALUE_TYPES                        \
345     ((Bool,       bool,       bool,           ()    )) \
346     ((UChar,      uchar,      unsigned char,  ()    )) \
347     ((Int,        int,        int,            ()    )) \
348     ((UInt,       uint,       unsigned int,   ()    )) \
349     ((Int64,      int64,      int64_t,        ()    )) \
350     ((UInt64,     uint64,     uint64_t,       ()    )) \
351     ((Half,       half,       GfHalf,         ()    )) \
352     ((Float,      float,      float,          ()    )) \
353     ((Double,     double,     double,         ()    )) \
354     ((TimeCode,   timecode,   SdfTimeCode,    ()    )) \
355     ((String,     string,     std::string,    ()    )) \
356     ((Token,      token,      TfToken,        ()    )) \
357     ((Asset,      asset,      SdfAssetPath,   ()    ))
358 
359 #define _SDF_DIMENSIONED_VALUE_TYPES                   \
360     ((Matrix2d,   matrix2d,   GfMatrix2d,     (2,2) )) \
361     ((Matrix3d,   matrix3d,   GfMatrix3d,     (3,3) )) \
362     ((Matrix4d,   matrix4d,   GfMatrix4d,     (4,4) )) \
363     ((Quath,      quath,      GfQuath,        (4)   )) \
364     ((Quatf,      quatf,      GfQuatf,        (4)   )) \
365     ((Quatd,      quatd,      GfQuatd,        (4)   )) \
366     ((Int2,       int2,       GfVec2i,        (2)   )) \
367     ((Half2,      half2,      GfVec2h,        (2)   )) \
368     ((Float2,     float2,     GfVec2f,        (2)   )) \
369     ((Double2,    double2,    GfVec2d,        (2)   )) \
370     ((Int3,       int3,       GfVec3i,        (3)   )) \
371     ((Half3,      half3,      GfVec3h,        (3)   )) \
372     ((Float3,     float3,     GfVec3f,        (3)   )) \
373     ((Double3,    double3,    GfVec3d,        (3)   )) \
374     ((Int4,       int4,       GfVec4i,        (4)   )) \
375     ((Half4,      half4,      GfVec4h,        (4)   )) \
376     ((Float4,     float4,     GfVec4f,        (4)   )) \
377     ((Double4,    double4,    GfVec4d,        (4)   ))
378 
379 #define SDF_VALUE_TYPES _SDF_SCALAR_VALUE_TYPES _SDF_DIMENSIONED_VALUE_TYPES
380 
381 // Accessors for individual elements in the value types tuples.
382 #define SDF_VALUE_CPP_TYPE(tup) BOOST_PP_TUPLE_ELEM(4, 2, tup)
383 #define SDF_VALUE_CPP_ARRAY_TYPE(tup) VtArray<BOOST_PP_TUPLE_ELEM(4, 2, tup)>
384 
385 template <class T>
386 struct SdfValueTypeTraits {
387     static const bool IsValueType = false;
388 };
389 
390 // Allow character arrays to be treated as Sdf value types.
391 // Sdf converts character arrays to strings for scene description.
392 template <int N>
393 struct SdfValueTypeTraits<char[N]> {
394     static const bool IsValueType = true;
395 };
396 
397 #define SDF_DECLARE_VALUE_TYPE_TRAITS(r, unused, elem)                      \
398 template <>                                                                 \
399 struct SdfValueTypeTraits<SDF_VALUE_CPP_TYPE(elem)> {                       \
400     static const bool IsValueType = true;                                   \
401 };                                                                          \
402 template <>                                                                 \
403 struct SdfValueTypeTraits<SDF_VALUE_CPP_ARRAY_TYPE(elem)> {                 \
404     static const bool IsValueType = true;                                   \
405 };
406 
407 BOOST_PP_SEQ_FOR_EACH(SDF_DECLARE_VALUE_TYPE_TRAITS, ~, SDF_VALUE_TYPES);
408 
409 /// Convert \p dict to a valid metadata dictionary for scene description.  Valid
410 /// metadata dictionaries have values that are any of SDF_VALUE_TYPES (or
411 /// VtArrays of those), plus VtDictionary with values of those types (or
412 /// similarly nested VtDictionaries).
413 ///
414 /// Certain conversions are performed in an attempt to produce a valid metadata
415 /// dictionary.  For example:
416 ///
417 /// Convert std::vector<VtValue> to VtArray<T> where T is the type of the first
418 /// element in the vector.  Fail conversion for empty vectors where a concrete
419 /// type cannot be inferred.
420 ///
421 /// Convert python sequences to VtArray<T> where T is the type of the first
422 /// element in the python sequence, when converted to VtValue, if that T is an
423 /// SDF_VALUE_TYPE).  Fail conversion for empty sequences where a concrete type
424 /// cannot be inferred.
425 ///
426 /// If any values cannot be converted to valid SDF_VALUE_TYPES, omit those
427 /// elements and add a message to \p errMsg indicating which values were
428 /// omitted.
429 ///
430 SDF_API
431 bool
432 SdfConvertToValidMetadataDictionary(VtDictionary *dict, std::string *errMsg);
433 
434 #define SDF_VALUE_ROLE_NAME_TOKENS              \
435     (Point)                                     \
436     (Normal)                                    \
437     (Vector)                                    \
438     (Color)                                     \
439     (Frame)                                     \
440     (Transform)                                 \
441     (PointIndex)                                \
442     (EdgeIndex)                                 \
443     (FaceIndex)                                 \
444     (TextureCoordinate)
445 
446 TF_DECLARE_PUBLIC_TOKENS(SdfValueRoleNames, SDF_API, SDF_VALUE_ROLE_NAME_TOKENS);
447 
448 SDF_DECLARE_HANDLES(SdfLayer);
449 
450 SDF_DECLARE_HANDLES(SdfAttributeSpec);
451 SDF_DECLARE_HANDLES(SdfPrimSpec);
452 SDF_DECLARE_HANDLES(SdfPropertySpec);
453 SDF_DECLARE_HANDLES(SdfSpec);
454 SDF_DECLARE_HANDLES(SdfRelationshipSpec);
455 SDF_DECLARE_HANDLES(SdfVariantSetSpec);
456 SDF_DECLARE_HANDLES(SdfVariantSpec);
457 
458 typedef std::map<std::string, SdfVariantSetSpecHandle>
459     SdfVariantSetSpecHandleMap;
460 
461 /// Writes the string representation of \c SdfSpecifier to \a out.
462 SDF_API
463 std::ostream & operator<<( std::ostream &out, const SdfSpecifier &spec );
464 
465 /// Writes the string representation of \c SdfRelocatesMap to \a out.
466 SDF_API
467 std::ostream & operator<<( std::ostream &out,
468                            const SdfRelocatesMap &reloMap );
469 
470 /// Writes the string representation of \c SdfTimeSampleMap to \a out.
471 SDF_API
472 std::ostream & operator<<( std::ostream &out,
473                            const SdfTimeSampleMap &sampleMap );
474 
475 SDF_API
476 std::ostream &VtStreamOut(const SdfVariantSelectionMap &, std::ostream &);
477 
478 /// \class SdfUnregisteredValue
479 /// Stores a representation of the value for an unregistered metadata
480 /// field encountered during text layer parsing.
481 ///
482 /// This provides the ability to serialize this data to a layer, as
483 /// well as limited inspection and editing capabilities (e.g., moving
484 /// this data to a different spec or field) even when the data type
485 /// of the value isn't known.
486 class SdfUnregisteredValue :
487     public boost::equality_comparable<SdfUnregisteredValue>
488 {
489 public:
490     /// Wraps an empty VtValue
491     SDF_API SdfUnregisteredValue();
492 
493     /// Wraps a std::string
494     SDF_API explicit SdfUnregisteredValue(const std::string &value);
495 
496     /// Wraps a VtDictionary
497     SDF_API explicit SdfUnregisteredValue(const VtDictionary &value);
498 
499     /// Wraps a SdfUnregisteredValueListOp
500     SDF_API explicit SdfUnregisteredValue(const SdfUnregisteredValueListOp &value);
501 
502     /// Returns the wrapped VtValue specified in the constructor
503     const VtValue& GetValue() const {
504         return _value;
505     }
506 
507     /// Hash.
508     friend size_t hash_value(const SdfUnregisteredValue &uv) {
509         return uv._value.GetHash();
510     }
511 
512     /// Returns true if the wrapped VtValues are equal
513     SDF_API bool operator==(const SdfUnregisteredValue &other) const;
514 
515 private:
516     VtValue _value;
517 };
518 
519 /// Writes the string representation of \c SdfUnregisteredValue to \a out.
520 SDF_API std::ostream &operator << (std::ostream &out, const SdfUnregisteredValue &value);
521 
522 class Sdf_ValueTypeNamesType : boost::noncopyable {
523 public:
524     SdfValueTypeName Bool;
525     SdfValueTypeName UChar, Int, UInt, Int64, UInt64;
526     SdfValueTypeName Half, Float, Double, TimeCode;
527     SdfValueTypeName String, Token, Asset;
528     SdfValueTypeName Int2,     Int3,     Int4;
529     SdfValueTypeName Half2,    Half3,    Half4;
530     SdfValueTypeName Float2,   Float3,   Float4;
531     SdfValueTypeName Double2,  Double3,  Double4;
532     SdfValueTypeName Point3h,  Point3f,  Point3d;
533     SdfValueTypeName Vector3h, Vector3f, Vector3d;
534     SdfValueTypeName Normal3h, Normal3f, Normal3d;
535     SdfValueTypeName Color3h,  Color3f,  Color3d;
536     SdfValueTypeName Color4h,  Color4f,  Color4d;
537     SdfValueTypeName Quath,    Quatf,    Quatd;
538     SdfValueTypeName Matrix2d, Matrix3d, Matrix4d;
539     SdfValueTypeName Frame4d;
540     SdfValueTypeName TexCoord2h, TexCoord2f, TexCoord2d;
541     SdfValueTypeName TexCoord3h, TexCoord3f, TexCoord3d;
542 
543     SdfValueTypeName BoolArray;
544     SdfValueTypeName UCharArray, IntArray, UIntArray, Int64Array, UInt64Array;
545     SdfValueTypeName HalfArray, FloatArray, DoubleArray, TimeCodeArray;
546     SdfValueTypeName StringArray, TokenArray, AssetArray;
547     SdfValueTypeName Int2Array,     Int3Array,     Int4Array;
548     SdfValueTypeName Half2Array,    Half3Array,    Half4Array;
549     SdfValueTypeName Float2Array,   Float3Array,   Float4Array;
550     SdfValueTypeName Double2Array,  Double3Array,  Double4Array;
551     SdfValueTypeName Point3hArray,  Point3fArray,  Point3dArray;
552     SdfValueTypeName Vector3hArray, Vector3fArray, Vector3dArray;
553     SdfValueTypeName Normal3hArray, Normal3fArray, Normal3dArray;
554     SdfValueTypeName Color3hArray,  Color3fArray,  Color3dArray;
555     SdfValueTypeName Color4hArray,  Color4fArray,  Color4dArray;
556     SdfValueTypeName QuathArray,    QuatfArray,    QuatdArray;
557     SdfValueTypeName Matrix2dArray, Matrix3dArray, Matrix4dArray;
558     SdfValueTypeName Frame4dArray;
559     SdfValueTypeName TexCoord2hArray, TexCoord2fArray, TexCoord2dArray;
560     SdfValueTypeName TexCoord3hArray, TexCoord3fArray, TexCoord3dArray;
561 
562     SDF_API ~Sdf_ValueTypeNamesType();
563     struct _Init {
564         SDF_API static const Sdf_ValueTypeNamesType* New();
565     };
566 
567     // For Pixar internal backwards compatibility.
568     TfToken GetSerializationName(const SdfValueTypeName&) const;
569     TfToken GetSerializationName(const VtValue&) const;
570     TfToken GetSerializationName(const TfToken&) const;
571 
572 private:
573     friend const Sdf_ValueTypeNamesType* Sdf_InitializeValueTypeNames();
574     Sdf_ValueTypeNamesType();
575 };
576 
577 extern SDF_API TfStaticData<const Sdf_ValueTypeNamesType,
578     Sdf_ValueTypeNamesType::_Init> SdfValueTypeNames;
579 
580 /// \class SdfValueBlock
581 /// A special value type that can be used to explicitly author an
582 /// opinion for an attribute's default value or time sample value
583 /// that represents having no value. Note that this is different
584 /// from not having a value authored.
585 ///
586 /// One could author such a value in two ways.
587 ///
588 /// \code
589 /// attribute->SetDefaultValue(VtValue(SdfValueBlock());
590 /// ...
591 /// layer->SetTimeSample(attribute->GetPath(), 101, VtValue(SdfValueBlock()));
592 /// \endcode
593 ///
594 struct SdfValueBlock {
595     bool operator==(const SdfValueBlock& block) const { return true; }
596     bool operator!=(const SdfValueBlock& block) const { return false; }
597 
598 private:
599     friend inline size_t hash_value(const SdfValueBlock &block) { return 0; }
600 };
601 
602 // Write out the string representation of a block.
603 SDF_API std::ostream& operator<<(std::ostream&, SdfValueBlock const&);
604 
605 // A class that represents a human-readable value.  This is used for the special
606 // purpose of producing layers that serialize field values in alternate ways; to
607 // produce more human-readable output, for example.
608 struct SdfHumanReadableValue {
609     SdfHumanReadableValue() = default;
610     explicit SdfHumanReadableValue(std::string const &text) : _text(text) {}
611 
612     bool operator==(SdfHumanReadableValue const &other) const {
613         return GetText() == other.GetText();
614     }
615     bool operator!=(SdfHumanReadableValue const &other) const {
616         return !(*this == other);
617     }
618 
619     std::string const &GetText() const { return _text; }
620 private:
621     std::string _text;
622 };
623 
624 SDF_API
625 std::ostream &operator<<(std::ostream &out, const SdfHumanReadableValue &hrval);
626 
627 SDF_API
628 size_t hash_value(const SdfHumanReadableValue &hrval);
629 
630 PXR_NAMESPACE_CLOSE_SCOPE
631 
632 #endif // PXR_USD_SDF_TYPES_H
633