24#ifndef PXR_BASE_TF_TYPE_H
25#define PXR_BASE_TF_TYPE_H
29#include "pxr/base/tf/api.h"
41PXR_NAMESPACE_OPEN_SCOPE
43#ifdef PXR_PYTHON_SUPPORT_ENABLED
86#ifdef PXR_PYTHON_SUPPORT_ENABLED
89 struct PyPolymorphicBase
92 TF_API
virtual ~PyPolymorphicBase();
99 template <
class ... Args>
133 inline bool operator !=(
const TfType& t)
const {
return _info != t._info; }
137 inline bool operator >(
const TfType& t)
const {
return _info > t._info; }
138 inline bool operator <=(
const TfType& t)
const {
return _info <= t._info; }
139 inline bool operator >=(
const TfType& t)
const {
return _info >= t._info; }
152 template <
typename T>
154 return Find(
typeid(T));
172 template <
typename T>
179 return _FindImpl(rawPtr);
187 return _FindByTypeid(t);
194 return _FindByTypeid(t);
234 template <
typename BASE>
240#ifdef PXR_PYTHON_SUPPORT_ENABLED
297#ifdef PXR_PYTHON_SUPPORT_ENABLED
379 template <
typename T>
380 bool IsA()
const {
return IsA(Find<T>()); }
390 typedef TfType::_TypeInfo * (
TfType::*UnspecifiedBoolType);
394 operator UnspecifiedBoolType()
const {
395 return IsUnknown() ? NULL : &TfType::_info;
458 const std::vector<TfType> & bases,
466 template <
typename T,
typename BaseTypes = TfType::Bases<>>
479 template <
typename T,
typename B>
489 template <
typename T>
492#ifdef PXR_PYTHON_SUPPORT_ENABLED
504 template <
typename Base,
typename Derived>
556 const void* addr)
const {
578 const void* addr)
const {
598 SetFactory(std::unique_ptr<FactoryBase>(std::move(factory)));
620 SetFactory(std::unique_ptr<FactoryBase>(std::move(factory)));
628 SetFactory(std::unique_ptr<FactoryBase>(
new T));
637 T *
GetFactory()
const {
return dynamic_cast<T*
>(_GetFactory()); }
643 FactoryBase* _GetFactory()
const;
645#ifdef PXR_PYTHON_SUPPORT_ENABLED
647 static TfType const &_FindImplPyPolymorphic(PyPolymorphicBase
const *ptr);
651 static typename std::enable_if<
652 std::is_base_of<PyPolymorphicBase, T>::value,
TfType const &>::type
653 _FindImpl(T
const *rawPtr) {
654 return _FindImplPyPolymorphic(
655 static_cast<PyPolymorphicBase
const *
>(rawPtr));
660 static typename std::enable_if<
661 std::is_polymorphic<T>::value &&
662 !std::is_base_of<PyPolymorphicBase, T>::value,
TfType const &>::type
663 _FindImpl(T
const *rawPtr) {
664 if (
auto ptr =
dynamic_cast<PyPolymorphicBase
const *
>(rawPtr))
665 return _FindImplPyPolymorphic(ptr);
666 return Find(
typeid(*rawPtr));
670 static typename std::enable_if<
671 !std::is_polymorphic<T>::value,
TfType const &>::type
672 _FindImpl(T
const *rawPtr) {
673 return Find(
typeid(T));
678 static typename std::enable_if<
679 std::is_polymorphic<T>::value,
TfType const &>::type
680 _FindImpl(T
const *rawPtr) {
681 return Find(
typeid(*rawPtr));
685 static typename std::enable_if<
686 !std::is_polymorphic<T>::value,
TfType const &>::type
687 _FindImpl(T
const *rawPtr) {
688 return Find(
typeid(T));
694 bool _IsAImplNoLock(
TfType queryType)
const;
696 typedef void *(*_CastFunction)(
void *,
bool derivedToBase);
698 template <
typename TypeVector>
699 friend struct Tf_AddBases;
700 friend struct _TypeInfo;
701 friend class Tf_TypeRegistry;
704 template <
class HashState>
706 TfHashAppend(HashState &h,
TfType const &type) {
707 h.Append(type._info);
711 explicit TfType(_TypeInfo *info) : _info(info) {}
715 void _AddBasesNoLock(
716 const std::vector<TfType> &bases,
717 std::vector<std::string> *errorToEmit)
const;
721 void _AddCppCastFunc(
722 const std::type_info &baseTypeInfo, _CastFunction)
const;
726 void _DefineCppType(
const std::type_info &,
729 bool isEnumType)
const;
732 void _ExecuteDefinitionCallback()
const;
737 static TfType const& _FindByTypeid(
const std::type_info &);
751 static const size_t value =
sizeof(T);
755 static const size_t value = 0;
759 static const size_t value = 0;
763 static const size_t value = 0;
767 static const size_t value = 0;
770PXR_NAMESPACE_CLOSE_SCOPE
773#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.