HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
declareSpec.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_SDF_DECLARE_SPEC_H
8 #define PXR_USD_SDF_DECLARE_SPEC_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/sdf/api.h"
13 #include "pxr/usd/sdf/specType.h"
15 #include "pxr/base/tf/type.h"
16 
18 
19 class SdfSpec;
20 
21 /// Helper macros for implementing C++ spec classes corresponding to
22 /// the various scene description spec types defined by Sdf. There are
23 /// two macros that each C++ spec class must invoke, one in the class
24 /// definition and one in the implementation .cpp file. For example:
25 ///
26 /// <in MySpecType.h>
27 /// class MySpecType : public MyBaseSpecType {
28 /// SDF_DECLARE_SPEC(MySpecType, MyBaseSpecType);
29 /// ...
30 /// };
31 ///
32 /// <in MySpecType.cpp>
33 /// SDF_DEFINE_SPEC(MySchemaType, <SdfSpecType enum value>, MySpecType,
34 /// MyBaseSpecType);
35 ///
36 /// There are two sets of these macros, one for concrete spec types
37 /// and one for 'abstract' spec types that only serve as a base class
38 /// for concrete specs.
39 ///
40 #define SDF_DECLARE_ABSTRACT_SPEC(SpecType, BaseSpecType) \
41 public: \
42  SpecType() { } \
43  SpecType(const SpecType& spec) \
44  : BaseSpecType(spec) { } \
45  explicit SpecType(const Sdf_IdentityRefPtr& identity) \
46  : BaseSpecType(identity) { } \
47 protected: \
48  friend struct Sdf_CastAccess; \
49  explicit SpecType(const SdfSpec& spec) \
50  : BaseSpecType(spec) { } \
51 
52 #define SDF_DEFINE_ABSTRACT_SPEC(SchemaType, SpecType, BaseSpecType) \
53 TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
54 { \
55  TfType::Define<SpecType, TfType::Bases<BaseSpecType> >(); \
56 } \
57 TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
58 { \
59  SdfSpecTypeRegistration::RegisterAbstractSpecType< \
60  SchemaType, SpecType>(); \
61 }
62 
63 // ------------------------------------------------------------
64 
65 #define SDF_DECLARE_SPEC(SpecType, BaseSpecType) \
66  SDF_DECLARE_ABSTRACT_SPEC(SpecType, BaseSpecType) \
67 
68 #define SDF_DEFINE_SPEC(SchemaType, SpecTypeEnum, SpecType, BaseSpecType) \
69 TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
70 { \
71  TfType::Define<SpecType, TfType::Bases<BaseSpecType> >(); \
72 } \
73 TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
74 { \
75  SdfSpecTypeRegistration::RegisterSpecType<SchemaType, SpecType> \
76  (SpecTypeEnum); \
77 }
78 
79 // ------------------------------------------------------------
80 // Special set of macros for SdfSpec only.
81 
82 #define SDF_DECLARE_BASE_SPEC(SpecType) \
83 public: \
84  SpecType() { } \
85  SpecType(const SpecType& spec) : _id(spec._id) { } \
86  explicit SpecType(const Sdf_IdentityRefPtr& id) : _id(id) { } \
87 
88 #define SDF_DEFINE_BASE_SPEC(SchemaType, SpecType) \
89 TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
90 { \
91  TfType::Define<SpecType>(); \
92 } \
93 TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
94 { \
95  SdfSpecTypeRegistration::RegisterAbstractSpecType< \
96  SchemaType, SpecType>(); \
97 }
98 
100 
101 #endif // PXR_USD_SDF_DECLARE_SPEC_H
Definition: spec.h:32
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74