7#ifndef PXR_BASE_TF_TYPE_IMPL_H
8#define PXR_BASE_TF_TYPE_IMPL_H
10PXR_NAMESPACE_OPEN_SCOPE
12template <
class DERIVED,
class BASE>
14Tf_CastToParent(
void* addr,
bool derivedToBase);
16template <
typename TypeVector>
17struct Tf_BaseTypeInfos;
20struct Tf_BaseTypeInfos<
TfType::Bases<>>
22 static const size_t NumBases = 0;
23 std::type_info
const **baseTypeInfos =
nullptr;
26template <
typename... Bases>
27struct Tf_BaseTypeInfos<
TfType::Bases<Bases...>>
29 static const size_t NumBases =
sizeof...(Bases);
30 std::type_info
const *baseTypeInfos[NumBases] = { &
typeid(Bases)... };
33template <
class Derived,
typename TypeVector>
34struct Tf_TypeCastFunctions;
36template <
class Derived>
37struct Tf_TypeCastFunctions<Derived,
TfType::Bases<>>
39 using CastFunction =
void *(*)(
void *,
bool);
40 CastFunction *castFunctions =
nullptr;
43template <
class Derived,
typename... Bases>
44struct Tf_TypeCastFunctions<Derived,
TfType::Bases<Bases...>>
46 using CastFunction =
void *(*)(
void *,
bool);
47 CastFunction castFunctions[
sizeof...(Bases)] = {
48 &Tf_CastToParent<Derived, Bases>... };
51template <
class T,
class BaseTypes>
55 Tf_BaseTypeInfos<BaseTypes> btis;
56 return _DeclareImpl(
typeid(T), btis.baseTypeInfos, btis.NumBases);
59template <
typename T,
typename BaseTypes>
63 Tf_BaseTypeInfos<BaseTypes> btis;
64 Tf_TypeCastFunctions<T, BaseTypes> tcfs;
66 typeid(T), btis.baseTypeInfos, tcfs.castFunctions, btis.NumBases,
74 return Define<T, Bases<>>();
79template <
class DERIVED,
class BASE>
81Tf_CastToParent(
void* addr,
bool derivedToBase)
85 DERIVED* derived =
reinterpret_cast<DERIVED*
>(addr);
90 BASE* base =
reinterpret_cast<BASE*
>(addr);
91 DERIVED* derived =
static_cast<DERIVED*
>(base);
96PXR_NAMESPACE_CLOSE_SCOPE
TfType represents a dynamic runtime type.
static TfType const & Define()
Define a TfType with the given C++ type T and C++ base types B.
static TfType const & Declare()
Declares a TfType with the given C++ type T and C++ base types Bases.
Metafunction returning sizeof(T) for a type T (or 0 if T is a void type).