Loading...
Searching...
No Matches
specType.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_SPEC_TYPE_H
8#define PXR_USD_SDF_SPEC_TYPE_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/types.h"
14
15#include <typeinfo>
16#include <vector>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
20class SdfSpec;
21class TfType;
22
40{
41public:
43 template <class SchemaType, class SpecType>
44 static void RegisterSpecType(SdfSpecType specTypeEnum) {
45 _RegisterSpecType(
46 typeid(SpecType), specTypeEnum, typeid(SchemaType));
47 }
48
50 template <class SchemaType, class SpecType>
52 _RegisterSpecType(
53 typeid(SpecType), SdfSpecTypeUnknown, typeid(SchemaType));
54 }
55
56private:
57 SDF_API
58 static void _RegisterSpecType(
59 const std::type_info& specCPPType,
60 SdfSpecType specEnumType,
61 const std::type_info& schemaType);
62};
63
64// This class holds type information for specs. It associates a
65// spec type with the corresponding TfType.
66class Sdf_SpecType {
67public:
68 // If \p spec can be represented by the C++ spec class \p to, returns
69 // the TfType for \p to. This includes verifying that \p spec's schema
70 // matches the schema associated with \p to.
71 static TfType Cast(const SdfSpec& spec, const std::type_info& to);
72
73 // Returns whether the \p spec can be represented by the C++ spec
74 // class \p to. This includes verifying that \p spec's schema matches
75 // the schema associated with \p to.
76 static bool CanCast(const SdfSpec& spec, const std::type_info& to);
77
78 // Returns whether a spec with spec type \p from can be represented by
79 // the C++ spec class \p to, regardless of schema.
80 static bool CanCast(SdfSpecType from, const std::type_info& to);
81};
82
83PXR_NAMESPACE_CLOSE_SCOPE
84
85#endif // PXR_USD_SDF_SPEC_TYPE_H
Base class for all Sdf spec classes.
Definition: spec.h:33
Provides functions to register spec types with the runtime typing system used to cast between C++ spe...
Definition: specType.h:40
static void RegisterAbstractSpecType()
Registers the C++ type T as an abstract spec class.
Definition: specType.h:51
static void RegisterSpecType(SdfSpecType specTypeEnum)
Registers the C++ type T as a concrete spec class.
Definition: specType.h:44
TfType represents a dynamic runtime type.
Definition: type.h:48
Basic Sdf data types.
SdfSpecType
An enum that specifies the type of an object.
Definition: types.h:68