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 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 &);
749 template <
typename T>
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;
770 PXR_NAMESPACE_CLOSE_SCOPE
773 #include "pxr/base/tf/type_Impl.h" 775 #endif // PXR_BASE_TF_TYPE_H static TF_API TfType const & GetUnknownType()
Return an empty TfType, representing the unknown type.
TF_API void GetAllDerivedTypes(std::set< TfType > *result) const
Return the set of all types derived (directly or indirectly) from this type.
static TfType const & Find(const std::type_info &t)
Retrieve the TfType corresponding to an obj with the given type_info.
bool IsA() const
Return true if this type is the same as or derived from T.
void SetFactory(std::unique_ptr< T > &factory) const
Sets the factory object for this type.
TF_API void DefinePythonClass(const TfPyObjWrapper &classObj) const
Define the Python class object corresponding to this TfType.
bool operator !() const
Boolean not operator – return true if this type is unknown, false otherwise.
static TF_API TfType const & FindByName(const std::string &name)
Retrieve the TfType corresponding to the given name.
bool operator==(const TfType &t) const
Equality operator.
static void AddAlias(const std::string &name)
Add an alias for DERIVED beneath BASE.
TF_API TfPyObjWrapper GetPythonClass() const
Return the Python class object for this type.
static TfType const & Find()
Retrieve the TfType corresponding to type T.
const TfType & Factory(std::unique_ptr< FactoryBase > factory) const
Sets the factory object for this 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 TfType const & GetCanonicalType() const
Return the canonical type for this type.
Base class of all factory types.
TF_API const std::string & GetTypeName() const
Return the machine-independent name for this type.
static TfType const & Find(const T &obj)
Retrieve the TfType corresponding to obj.
TF_API bool IsEnumType() const
Return true if this is an enum type.
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.
A type-list of C++ base types.
void SetFactory() const
Sets the factory object for this type to be a T.
TF_API void * CastFromAncestor(TfType ancestor, void *addr) const
Cast addr, which pointed to the ancestor type ancestor, to the type of *this.
Metafunction returning sizeof(T) for a type T (or 0 if T is a void type).
static TF_API TfType const & FindByPythonClass(const TfPyObjWrapper &classObj)
Retrieve the TfType corresponding to an obj with the given Python class classObj.
static TfType const & FindByTypeid(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 & Alias(TfType base, const std::string &name) const
Convenience method to add an alias and return *this.
static TfType const & Define()
Define a TfType with the given C++ type T and C++ base types B.
TF_API const std::type_info & GetTypeid() const
Return a C++ RTTI type_info for this type.
TF_API std::vector< TfType > GetDirectlyDerivedTypes() const
Return a vector of types derived directly from this type.
TF_API void GetAllAncestorTypes(std::vector< TfType > *result) const
Build a vector of all ancestor types inherited by this type.
const TfType & Factory() const
Sets the factory object for this type to be a T.
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 & Declare()
Declares a TfType with the given C++ type T and C++ base types Bases.
bool IsRoot() const
Return true if this is the root type.
Boost Python object wrapper.
TF_API void * CastToAncestor(TfType ancestor, void *addr) const
Cast addr to the address corresponding to the type ancestor.
TF_API std::vector< TfType > GetBaseTypes() const
Return a vector of types from which this type was derived.
static TF_API TfType const & GetRoot()
Return the root type of the type hierarchy.
TfType represents a dynamic runtime type.
Implements assorted functions based on compile-time type information.
TF_API bool IsPlainOldDataType() const
Return true if this is a plain old data type, as defined by C++.
bool IsUnknown() const
Return true if this is the unknown type, representing a type unknown to the TfType system.
TF_API std::ostream & operator<<(std::ostream &out, const TfType &t)
Output a TfType, using the machine-independent type name.
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 TfType &t) const
Comparison operator.
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...
const TfType & Factory(std::unique_ptr< T > &factory) const
Sets the factory object for this type.
TF_API TfType()
Construct an TfType representing an unknown type.
Manufacturable type (implies concrete)
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.
Abstract (unmanufacturable and unclonable)