HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
specType.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_SPEC_TYPE_H
25 #define PXR_USD_SDF_SPEC_TYPE_H
26 
27 /// \file sdf/specType.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/types.h"
31 
32 #include <typeinfo>
33 #include <vector>
34 
36 
37 class SdfSpec;
38 class TfType;
39 
40 /// \class SdfSpecTypeRegistration
41 ///
42 /// Provides functions to register spec types with the runtime typing system
43 /// used to cast between C++ spec types. Implementations of C++ spec types
44 /// should use as follows:
45 ///
46 /// For a concrete spec type that corresponds to a specific SdfSpecType:
47 /// TF_REGISTRY_FUNCTION(SdfSpecTypeRegistration) {
48 /// SdfSpecTypeRegistration::RegisterSpecType<MyPrimSpec>();
49 /// }
50 ///
51 /// For an abstract spec type that has no corresponding SdfSpecType:
52 /// TF_REGISTRY_FUNCTION(SdfSpecTypeRegistration) {
53 /// SdfSpecTypeRegistration::RegisterAbstractSpecType<MyPropertySpec>();
54 /// }
55 ///
57 {
58 public:
59  /// Registers the C++ type T as a concrete spec class.
60  template <class SchemaType, class SpecType>
61  static void RegisterSpecType(SdfSpecType specTypeEnum) {
62  _RegisterSpecType(
63  typeid(SpecType), specTypeEnum, typeid(SchemaType));
64  }
65 
66  /// Registers the C++ type T as an abstract spec class.
67  template <class SchemaType, class SpecType>
68  static void RegisterAbstractSpecType() {
69  _RegisterSpecType(
70  typeid(SpecType), SdfSpecTypeUnknown, typeid(SchemaType));
71  }
72 
73 private:
74  SDF_API
75  static void _RegisterSpecType(
76  const std::type_info& specCPPType,
77  SdfSpecType specEnumType,
78  const std::type_info& schemaType);
79 };
80 
81 // This class holds type information for specs. It associates a
82 // spec type with the corresponding TfType.
83 class Sdf_SpecType {
84 public:
85  // If \p spec can be represented by the C++ spec class \p to, returns
86  // the TfType for \p to. This includes verifying that \p spec's schema
87  // matches the schema associated with \p to.
88  static TfType Cast(const SdfSpec& spec, const std::type_info& to);
89 
90  // Returns whether the \p spec can be represented by the C++ spec
91  // class \p to. This includes verifying that \p spec's schema matches
92  // the schema associated with \p to.
93  static bool CanCast(const SdfSpec& spec, const std::type_info& to);
94 
95  // Returns whether a spec with spec type \p from can be represented by
96  // the C++ spec class \p to, regardless of schema.
97  static bool CanCast(SdfSpecType from, const std::type_info& to);
98 };
99 
101 
102 #endif // PXR_USD_SDF_SPEC_TYPE_H
Definition: spec.h:49
static void RegisterSpecType(SdfSpecType specTypeEnum)
Registers the C++ type T as a concrete spec class.
Definition: specType.h:61
#define SDF_API
Definition: api.h:40
static void RegisterAbstractSpecType()
Registers the C++ type T as an abstract spec class.
Definition: specType.h:68
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
SdfSpecType
Definition: types.h:85
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Definition: type.h:64
static bool CanCast(const SdfSpec &spec, const std::type_info &to)
static TfType Cast(const SdfSpec &spec, const std::type_info &to)