7#ifndef PXR_BASE_TF_TYPE_H
8#define PXR_BASE_TF_TYPE_H
12#include "pxr/base/tf/api.h"
24PXR_NAMESPACE_OPEN_SCOPE
26#ifdef PXR_PYTHON_SUPPORT_ENABLED
69#ifdef PXR_PYTHON_SUPPORT_ENABLED
72 struct PyPolymorphicBase
75 TF_API
virtual ~PyPolymorphicBase();
82 template <
class ... Args>
116 inline bool operator !=(
const TfType& t)
const {
return _info != t._info; }
120 inline bool operator >(
const TfType& t)
const {
return _info > t._info; }
121 inline bool operator <=(
const TfType& t)
const {
return _info <= t._info; }
122 inline bool operator >=(
const TfType& t)
const {
return _info >= t._info; }
135 template <
typename T>
137 return Find(
typeid(T));
155 template <
typename T>
162 return _FindImpl(rawPtr);
170 return _FindByTypeid(t);
177 return _FindByTypeid(t);
217 template <
typename BASE>
223#ifdef PXR_PYTHON_SUPPORT_ENABLED
283#ifdef PXR_PYTHON_SUPPORT_ENABLED
365 template <
typename T>
366 bool IsA()
const {
return IsA(Find<T>()); }
376 typedef TfType::_TypeInfo * (
TfType::*UnspecifiedBoolType);
380 operator UnspecifiedBoolType()
const {
381 return IsUnknown() ? NULL : &TfType::_info;
444 const std::vector<TfType> & bases,
452 template <
typename T,
typename BaseTypes = TfType::Bases<>>
465 template <
typename T,
typename B>
475 template <
typename T>
478#ifdef PXR_PYTHON_SUPPORT_ENABLED
490 template <
typename Base,
typename Derived>
542 const void* addr)
const {
564 const void* addr)
const {
584 SetFactory(std::unique_ptr<FactoryBase>(std::move(factory)));
606 SetFactory(std::unique_ptr<FactoryBase>(std::move(factory)));
614 SetFactory(std::unique_ptr<FactoryBase>(
new T));
623 T *
GetFactory()
const {
return dynamic_cast<T*
>(_GetFactory()); }
629 FactoryBase* _GetFactory()
const;
631#ifdef PXR_PYTHON_SUPPORT_ENABLED
633 static TfType const &_FindImplPyPolymorphic(PyPolymorphicBase
const *ptr);
637 _FindImpl(PyPolymorphicBase
const *rawPtr) {
638 return _FindImplPyPolymorphic(rawPtr);
644 _FindImpl(T
const *rawPtr) {
645 if constexpr (std::is_polymorphic<T>::value) {
646 if (
auto ptr =
dynamic_cast<PyPolymorphicBase
const *
>(rawPtr)) {
647 return _FindImplPyPolymorphic(ptr);
650 return Find(
typeid(*rawPtr));
654 return Find(
typeid(T));
660 _FindImpl(T
const *rawPtr) {
661 return Find(
typeid(*rawPtr));
667 bool _IsAImplNoLock(
TfType queryType)
const;
669 typedef void *(*_CastFunction)(
void *,
bool derivedToBase);
671 template <
typename TypeVector>
672 friend struct Tf_AddBases;
673 friend struct _TypeInfo;
674 friend class Tf_TypeRegistry;
677 template <
class HashState>
679 TfHashAppend(HashState &h,
TfType const &type) {
680 h.Append(type._info);
684 explicit TfType(_TypeInfo *info) : _info(info) {}
688 void _AddBasesNoLock(
689 const std::vector<TfType> &bases,
690 std::vector<std::string> *errorToEmit)
const;
694 void _AddCppCastFunc(
695 const std::type_info &baseTypeInfo, _CastFunction)
const;
699 void _DefineCppType(
const std::type_info &,
702 bool isEnumType)
const;
705 static TfType const &_DeclareImpl(
706 const std::type_info &thisTypeInfo,
707 const std::type_info **baseTypeInfos,
708 size_t numBaseTypes);
711 static TfType const &_DefineImpl(
712 const std::type_info &thisTypeInfo,
713 const std::type_info **baseTypeInfos,
714 _CastFunction *castFunctions,
716 size_t sizeofThisType,
bool isPod,
bool isEnum);
719 void _ExecuteDefinitionCallback()
const;
724 static TfType const& _FindByTypeid(
const std::type_info &);
738 static const size_t value =
sizeof(T);
742 static const size_t value = 0;
746 static const size_t value = 0;
750 static const size_t value = 0;
754 static const size_t value = 0;
757PXR_NAMESPACE_CLOSE_SCOPE
760#include "pxr/base/tf/type_Impl.h"
Boost Python object wrapper.
Base class of all factory types.
TfType represents a dynamic runtime type.
const TfType & Alias(TfType base, const std::string &name) const
Convenience method to add an alias and return *this.
static TF_API TfType const & GetUnknownType()
Return an empty TfType, representing the unknown type.
TF_API std::vector< std::string > GetAliases(TfType derivedType) const
Returns a vector of the aliases registered for the derivedType under this, the base type.
TF_API std::vector< TfType > GetBaseTypes() const
Return a vector of types from which this type was derived.
TF_API void AddAlias(TfType base, const std::string &name) const
Add an alias name for this type under the given base type.
static TfType const & Define()
Define a TfType with the given C++ type T and no bases.
const TfType & Factory(std::unique_ptr< T > &factory) const
Sets the factory object for this type.
const TfType & Factory(std::unique_ptr< FactoryBase > factory) const
Sets the factory object for this type.
bool operator==(const TfType &t) const
Equality operator.
TF_API void DefinePythonClass(const TfPyObjWrapper &classObj) const
Define the Python class object corresponding to this TfType.
@ MANUFACTURABLE
Manufacturable type (implies concrete)
@ ABSTRACT
Abstract (unmanufacturable and unclonable)
static TF_API TfType const & FindByName(const std::string &name)
Retrieve the TfType corresponding to the given name.
static void AddAlias(const std::string &name)
Add an alias for DERIVED beneath BASE.
TF_API bool IsA(TfType queryType) const
Return true if this type is the same as or derived from queryType.
TF_API std::vector< TfType > GetDirectlyDerivedTypes() const
Return a vector of types derived directly from this type.
bool operator<(const TfType &t) const
Comparison operator.
TF_API bool IsEnumType() const
Return true if this is an enum type.
static TF_API TfType const & GetRoot()
Return the root type of the type hierarchy.
static TF_API TfType const & FindByPythonClass(const TfPyObjWrapper &classObj)
Retrieve the TfType corresponding to an obj with the given Python class classObj.
bool operator!() const
Boolean not operator – return true if this type is unknown, false otherwise.
bool IsA() const
Return true if this type is the same as or derived from T.
TF_API void SetFactory(std::unique_ptr< FactoryBase > factory) const
Sets the factory object for this type.
static TfType const & Find(const std::type_info &t)
Retrieve the TfType corresponding to an obj with the given type_info.
TF_API size_t GetSizeof() const
Return the size required to hold an instance of this type on the stack (does not include any heap all...
const TfType & Factory() const
Sets the factory object for this type to be a T.
TF_API void * CastToAncestor(TfType ancestor, void *addr) const
Cast addr to the address corresponding to the type ancestor.
static TF_API TfType const & Declare(const std::string &typeName)
Declare a TfType with the given typeName, but no base type information.
static TF_API TfType const & Declare(const std::string &typeName, const std::vector< TfType > &bases, DefinitionCallback definitionCallback=nullptr)
Declare a TfType with the given typeName and bases.
TF_API const std::string & GetTypeName() const
Return the machine-independent name for this type.
static TfType const & Define()
Define a TfType with the given C++ type T and C++ base types B.
static TfType const & Find()
Retrieve the TfType corresponding to type T.
TF_API void * CastFromAncestor(TfType ancestor, void *addr) const
Cast addr, which pointed to the ancestor type ancestor, to the type of *this.
TF_API void GetAllDerivedTypes(std::set< TfType > *result) const
Return the set of all types derived (directly or indirectly) from this type.
void SetFactory() const
Sets the factory object for this type to be a T.
static TfType const & Declare()
Declares a TfType with the given C++ type T and C++ base types Bases.
void(*)(TfType) DefinitionCallback
Callback invoked when a declared type needs to be defined.
TF_API void GetAllAncestorTypes(std::vector< TfType > *result) const
Build a vector of all ancestor types inherited by this type.
static TfType const & FindDerivedByName(const std::string &name)
Retrieve the TfType that derives from BASE and has the given alias or typename.
static TfType const & Find(const T &obj)
Retrieve the TfType corresponding to obj.
TF_API const std::type_info & GetTypeid() const
Return a C++ RTTI type_info for this type.
bool IsUnknown() const
Return true if this is the unknown type, representing a type unknown to the TfType system.
TF_API TfPyObjWrapper GetPythonClass() const
Return the Python class object for this type.
TF_API TfType const & FindDerivedByName(const std::string &name) const
Retrieve the TfType that derives from this type and has the given alias or typename.
T * GetFactory() const
Returns the factory object for this type as a T*, or NULL if there is no factory or the factory is no...
bool IsRoot() const
Return true if this is the root type.
TF_API size_t GetNBaseTypes(TfType *out, size_t maxBases) const
Copy the first maxBases base types of this type to out, or all the base types if this type has maxBas...
TF_API TfType const & GetCanonicalType() const
Return the canonical type for this type.
static TF_API std::string GetCanonicalTypeName(const std::type_info &)
Return the canonical typeName used for a given std::type_info.
void SetFactory(std::unique_ptr< T > &factory) const
Sets the factory object for this type.
TF_API TfType()
Construct an TfType representing an unknown type.
static TfType const & FindByTypeid(const std::type_info &t)
Retrieve the TfType corresponding to an obj with the given type_info.
TF_API bool IsPlainOldDataType() const
Return true if this is a plain old data type, as defined by C++.
A type-list of C++ base types.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Metafunction returning sizeof(T) for a type T (or 0 if T is a void type).
Implements assorted functions based on compile-time type information.