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 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_DECLARE_SPEC_H
25 #define PXR_USD_SDF_DECLARE_SPEC_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/sdf/api.h"
30 #include "pxr/usd/sdf/specType.h"
32 #include "pxr/base/tf/type.h"
33 
35 
36 class SdfSpec;
37 
38 /// Helper macros for implementing C++ spec classes corresponding to
39 /// the various scene description spec types defined by Sdf. There are
40 /// two macros that each C++ spec class must invoke, one in the class
41 /// definition and one in the implementation .cpp file. For example:
42 ///
43 /// <in MySpecType.h>
44 /// class MySpecType : public MyBaseSpecType {
45 /// SDF_DECLARE_SPEC(MySpecType, MyBaseSpecType);
46 /// ...
47 /// };
48 ///
49 /// <in MySpecType.cpp>
50 /// SDF_DEFINE_SPEC(MySchemaType, <SdfSpecType enum value>, MySpecType,
51 /// MyBaseSpecType);
52 ///
53 /// There are two sets of these macros, one for concrete spec types
54 /// and one for 'abstract' spec types that only serve as a base class
55 /// for concrete specs.
56 ///
57 #define SDF_DECLARE_ABSTRACT_SPEC(SpecType, BaseSpecType) \
58 public: \
59  SpecType() { } \
60  SpecType(const SpecType& spec) \
61  : BaseSpecType(spec) { } \
62  explicit SpecType(const Sdf_IdentityRefPtr& identity) \
63  : BaseSpecType(identity) { } \
64 protected: \
65  friend struct Sdf_CastAccess; \
66  explicit SpecType(const SdfSpec& spec) \
67  : BaseSpecType(spec) { } \
68 
69 #define SDF_DEFINE_ABSTRACT_SPEC(SchemaType, SpecType, BaseSpecType) \
70 TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
71 { \
72  TfType::Define<SpecType, TfType::Bases<BaseSpecType> >(); \
73 } \
74 TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
75 { \
76  SdfSpecTypeRegistration::RegisterAbstractSpecType< \
77  SchemaType, SpecType>(); \
78 }
79 
80 // ------------------------------------------------------------
81 
82 #define SDF_DECLARE_SPEC(SpecType, BaseSpecType) \
83  SDF_DECLARE_ABSTRACT_SPEC(SpecType, BaseSpecType) \
84 
85 #define SDF_DEFINE_SPEC(SchemaType, SpecTypeEnum, SpecType, BaseSpecType) \
86 TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
87 { \
88  TfType::Define<SpecType, TfType::Bases<BaseSpecType> >(); \
89 } \
90 TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
91 { \
92  SdfSpecTypeRegistration::RegisterSpecType<SchemaType, SpecType> \
93  (SpecTypeEnum); \
94 }
95 
96 // ------------------------------------------------------------
97 // Special set of macros for SdfSpec only.
98 
99 #define SDF_DECLARE_BASE_SPEC(SpecType) \
100 public: \
101  SpecType() { } \
102  SpecType(const SpecType& spec) : _id(spec._id) { } \
103  explicit SpecType(const Sdf_IdentityRefPtr& id) : _id(id) { } \
104 
105 #define SDF_DEFINE_BASE_SPEC(SchemaType, SpecType) \
106 TF_REGISTRY_FUNCTION_WITH_TAG(TfType, Type) \
107 { \
108  TfType::Define<SpecType>(); \
109 } \
110 TF_REGISTRY_FUNCTION_WITH_TAG(SdfSpecTypeRegistration, Registration) \
111 { \
112  SdfSpecTypeRegistration::RegisterAbstractSpecType< \
113  SchemaType, SpecType>(); \
114 }
115 
117 
118 #endif // PXR_USD_SDF_DECLARE_SPEC_H
Definition: spec.h:49
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91