24 #ifndef PXR_BASE_TF_TYPE_H
25 #define PXR_BASE_TF_TYPE_H
29 #include "pxr/base/tf/api.h"
37 #include <type_traits>
41 PXR_NAMESPACE_OPEN_SCOPE
43 #ifdef PXR_PYTHON_SUPPORT_ENABLED
45 #endif // PXR_PYTHON_SUPPORT_ENABLED
86 #ifdef PXR_PYTHON_SUPPORT_ENABLED
89 struct PyPolymorphicBase
92 TF_API
virtual ~PyPolymorphicBase();
94 #endif // PXR_PYTHON_SUPPORT_ENABLED
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
246 #endif // PXR_PYTHON_SUPPORT_ENABLED
297 #ifdef PXR_PYTHON_SUPPORT_ENABLED
308 #endif // 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;
439 Declare(
const std::string & typeName );
457 Declare(
const std::string & typeName,
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
497 #endif // PXR_PYTHON_SUPPORT_ENABLED
504 template <
typename Base,
typename Derived>
556 const void* addr)
const {
578 const void* addr)
const {
591 void SetFactory(std::unique_ptr<FactoryBase> factory)
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));
691 #endif // PXR_PYTHON_SUPPORT_ENABLED
693 bool _IsAImpl(
TfType queryType)
const;
695 typedef void *(*_CastFunction)(
void *,
bool derivedToBase);
697 template <
typename TypeVector>
698 friend struct Tf_AddBases;
699 friend struct _TypeInfo;
700 friend class Tf_TypeRegistry;
703 template <
class HashState>
705 TfHashAppend(HashState &h,
TfType const &type) {
706 h.Append(type._info);
710 explicit TfType(_TypeInfo *info) : _info(info) {}
714 const std::vector<TfType> &bases,
715 std::vector<std::string> *errorToEmit)
const;
719 void _AddCppCastFunc(
720 const std::type_info &baseTypeInfo, _CastFunction)
const;
724 void _DefineCppType(
const std::type_info &,
727 bool isEnumType)
const;
730 void _ExecuteDefinitionCallback()
const;
735 static TfType const& _FindByTypeid(
const std::type_info &);
747 template <
typename T>
749 static const size_t value =
sizeof(T);
753 static const size_t value = 0;
757 static const size_t value = 0;
761 static const size_t value = 0;
765 static const size_t value = 0;
768 PXR_NAMESPACE_CLOSE_SCOPE
771 #include "pxr/base/tf/type_Impl.h"
773 #endif // PXR_BASE_TF_TYPE_H
TF_API const std::string & GetTypeName() const
Return the machine-independent name for this type.
const TfType & Factory() const
Sets the factory object for this type to be a T.
static TF_API TfType const & GetUnknownType()
Return an empty TfType, representing the unknown type.
const TfType & Alias(TfType base, const std::string &name) const
Convenience method to add an alias and return *this.
static TfType const & Find(const std::type_info &t)
Retrieve the TfType corresponding to an obj with the given type_info.
TF_API void GetAllAncestorTypes(std::vector< TfType > *result) const
Build a vector of all ancestor types inherited by this type.
static TfType const & Declare()
Declares a TfType with the given C++ type T and C++ base types Bases.
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.
static TfType const & Find()
Retrieve the TfType corresponding to type T.
TF_API bool IsEnumType() const
Return true if this is an enum type.
bool operator<(const TfType &t) const
Comparison operator.
Base class of all factory types.
TF_API void * CastFromAncestor(TfType ancestor, void *addr) const
Cast addr, which pointed to the ancestor type ancestor, to the type of *this.
void SetFactory(std::unique_ptr< T > &factory) const
Sets the factory object for this 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...
static TfType const & Find(const T &obj)
Retrieve the TfType corresponding to obj.
void(*)(TfType) DefinitionCallback
Callback invoked when a declared type needs to be defined.
static TF_API std::string GetCanonicalTypeName(const std::type_info &)
Return the canonical typeName used for a given std::type_info.
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.
A type-list of C++ base types.
TF_API std::vector< TfType > GetDirectlyDerivedTypes() const
Return a vector of types derived directly from this type.
Metafunction returning sizeof(T) for a type T (or 0 if T is a void type).
static TfType const & FindByTypeid(const std::type_info &t)
Retrieve the TfType corresponding to an obj with the given type_info.
const TfType & Factory(std::unique_ptr< T > &factory) const
Sets the factory object for this type.
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 TfType const & FindDerivedByName(const std::string &name) const
Retrieve the TfType that derives from this type and has the given alias or typename.
TF_API void * CastToAncestor(TfType ancestor, void *addr) const
Cast addr to the address corresponding to the type ancestor.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
static TfType const & Define()
Define a TfType with the given C++ type T and C++ base types B.
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...
Boost Python object wrapper.
bool IsUnknown() const
Return true if this is the unknown type, representing a type unknown to the TfType system...
bool operator==(const TfType &t) const
Equality operator.
TF_API bool IsPlainOldDataType() const
Return true if this is a plain old data type, as defined by C++.
static TF_API TfType const & GetRoot()
Return the root type of the type hierarchy.
TF_API const std::type_info & GetTypeid() const
Return a C++ RTTI type_info for this type.
const TfType & Factory(std::unique_ptr< FactoryBase > factory) const
Sets the factory object for this type.
TfType represents a dynamic runtime type.
Implements assorted functions based on compile-time type information.
TF_API TfType const & GetCanonicalType() const
Return the canonical type for this type.
bool IsA() const
Return true if this type is the same as or derived from T.
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 & FindDerivedByName(const std::string &name)
Retrieve the TfType that derives from BASE and has the given alias or typename.
bool operator!() const
Boolean not operator – return true if this type is unknown, false otherwise.
TF_API TfType()
Construct an TfType representing an unknown type.
Manufacturable type (implies concrete)
Abstract (unmanufacturable and unclonable)