24 #ifndef PXR_BASE_TF_TYPE_IMPL_H 25 #define PXR_BASE_TF_TYPE_IMPL_H 29 #include <initializer_list> 31 PXR_NAMESPACE_OPEN_SCOPE
33 template <
class DERIVED,
class BASE>
35 Tf_CastToParent(
void* addr,
bool derivedToBase);
38 template <
typename TypeVector>
41 template <
typename... Bases>
42 struct Tf_AddBases<
TfType::Bases<Bases...>>
46 static std::vector<TfType>
49 return std::vector<TfType> {
56 template <
typename Derived>
58 RegisterCasts(
TfType const* type)
62 const std::type_info *typeInfo;
63 TfType::_CastFunction func;
66 const std::initializer_list<Cast> baseCasts = {
67 { &
typeid(Bases), &Tf_CastToParent<Derived, Bases> }...
70 for (
const Cast &cast : baseCasts) {
71 type->_AddCppCastFunc(*cast.typeInfo, cast.func);
76 template <
class T,
class BaseTypes>
81 std::vector<TfType> baseTfTypes = Tf_AddBases<BaseTypes>::Declare();
83 const std::type_info &typeInfo =
typeid(T);
88 template <
typename T,
typename BaseTypes>
95 std::vector<TfType> baseTfTypes = Tf_AddBases<BaseTypes>::Declare();
98 const std::type_info &typeInfo =
typeid(T);
103 const bool isPodType = std::is_pod<T>::value;
104 const bool isEnumType = std::is_enum<T>::value;
107 newType._DefineCppType(typeInfo, sizeofType, isPodType, isEnumType);
108 Tf_AddBases<BaseTypes>::template RegisterCasts<T>(&newType);
113 template <
typename T>
117 return Define<T, Bases<> >();
122 template <
class DERIVED,
class BASE>
124 Tf_CastToParent(
void* addr,
bool derivedToBase)
128 DERIVED* derived = reinterpret_cast<DERIVED*>(addr);
129 BASE* base = derived;
133 BASE* base = reinterpret_cast<BASE*>(addr);
134 DERIVED* derived = static_cast<DERIVED*>(base);
139 PXR_NAMESPACE_CLOSE_SCOPE
141 #endif // PXR_BASE_TF_TYPE_IMPL_H static TF_API std::string GetCanonicalTypeName(const std::type_info &)
Return the canonical typeName used for a given std::type_info.
Metafunction returning sizeof(T) for a type T (or 0 if T is a void 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.
TfType represents a dynamic runtime type.