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 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/types.h"
31 
32 #include <typeinfo>
33 #include <vector>
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 class SdfSpec;
38 class TfType;
39 
57 {
58 public:
60  template <class SchemaType, class SpecType>
61  static void RegisterSpecType(SdfSpecType specTypeEnum)
62  {
63  _RegisterSpecType(typeid(SpecType), specTypeEnum, typeid(SchemaType));
64  }
65 
67  template <class SchemaType, class SpecType>
69  {
70  _RegisterAbstractSpecType(typeid(SpecType), typeid(SchemaType));
71  }
72 
73 private:
74  static void _RegisterSpecType(
75  const std::type_info& specCPPType, SdfSpecType specEnumType,
76  const std::type_info& schemaType);
77  static void _RegisterAbstractSpecType(
78  const std::type_info& specCPPType,
79  const std::type_info& schemaType);
80 };
81 
82 // This class holds type information for specs. It associates a
83 // spec type with the corresponding TfType.
84 class Sdf_SpecType {
85 public:
86  // If \p spec can be represented by the C++ spec class \p to, returns
87  // the TfType for \p to. This includes verifying that \p spec's schema
88  // matches the schema associated with \p to.
89  static TfType Cast(const SdfSpec& spec, const std::type_info& to);
90 
91  // Returns whether the \p spec can be represented by the C++ spec
92  // class \p to. This includes verifying that \p spec's schema matches
93  // the schema associated with \p to.
94  static bool CanCast(const SdfSpec& spec, const std::type_info& to);
95 
96  // Returns whether a spec with spec type \p from can be represented by
97  // the C++ spec class \p to, regardless of schema.
98  static bool CanCast(SdfSpecType from, const std::type_info& to);
99 };
100 
101 PXR_NAMESPACE_CLOSE_SCOPE
102 
103 #endif // PXR_USD_SDF_SPEC_TYPE_H
Base class for all Sdf spec classes.
Definition: spec.h:51
Basic Sdf data types.
static void RegisterAbstractSpecType()
Registers the C++ type T as an abstract spec class.
Definition: specType.h:68
Provides functions to register spec types with the runtime typing system used to cast between C++ spe...
Definition: specType.h:56
static void RegisterSpecType(SdfSpecType specTypeEnum)
Registers the C++ type T as a concrete spec class.
Definition: specType.h:61
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:91
TfType represents a dynamic runtime type.
Definition: type.h:64