Loading...
Searching...
No Matches
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
35PXR_NAMESPACE_OPEN_SCOPE
36
37class SdfSpec;
38class TfType;
39
57{
58public:
60 template <class SchemaType, class SpecType>
61 static void RegisterSpecType(SdfSpecType specTypeEnum) {
62 _RegisterSpecType(
63 typeid(SpecType), specTypeEnum, typeid(SchemaType));
64 }
65
67 template <class SchemaType, class SpecType>
69 _RegisterSpecType(
70 typeid(SpecType), SdfSpecTypeUnknown, typeid(SchemaType));
71 }
72
73private:
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.
83class Sdf_SpecType {
84public:
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
100PXR_NAMESPACE_CLOSE_SCOPE
101
102#endif // PXR_USD_SDF_SPEC_TYPE_H
Base class for all Sdf spec classes.
Definition: spec.h:50
Provides functions to register spec types with the runtime typing system used to cast between C++ spe...
Definition: specType.h:57
static void RegisterAbstractSpecType()
Registers the C++ type T as an abstract spec class.
Definition: specType.h:68
static void RegisterSpecType(SdfSpecType specTypeEnum)
Registers the C++ type T as a concrete spec class.
Definition: specType.h:61
TfType represents a dynamic runtime type.
Definition: type.h:65
Basic Sdf data types.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:84