HDK
|
#include <type.h>
Classes | |
struct | Bases |
class | FactoryBase |
Base class of all factory types. More... | |
Public Types | |
enum | LegacyFlags { ABSTRACT = 0x01, CONCRETE = 0x02, MANUFACTURABLE = 0x08 } |
using | DefinitionCallback = void(*)(TfType) |
Callback invoked when a declared type needs to be defined. More... | |
Public Member Functions | |
TF_API | TfType () |
bool | operator== (const TfType &t) const |
bool | operator!= (const TfType &t) const |
bool | operator< (const TfType &t) const |
Comparison operator. More... | |
bool | operator> (const TfType &t) const |
bool | operator<= (const TfType &t) const |
bool | operator>= (const TfType &t) const |
Pointer casts | |
TF_API void * | CastToAncestor (TfType ancestor, void *addr) const |
const void * | CastToAncestor (TfType ancestor, const void *addr) const |
TF_API void * | CastFromAncestor (TfType ancestor, void *addr) const |
const void * | CastFromAncestor (TfType ancestor, const void *addr) const |
Instantiation / Manufacturing | |
TF_API void | SetFactory (std::unique_ptr< FactoryBase > factory) const |
template<class T > | |
void | SetFactory (std::unique_ptr< T > &factory) const |
template<class T > | |
void | SetFactory () const |
const TfType & | Factory (std::unique_ptr< FactoryBase > factory) const |
template<class T > | |
const TfType & | Factory (std::unique_ptr< T > &factory) const |
template<class T > | |
const TfType & | Factory () const |
template<class T > | |
T * | GetFactory () const |
Static Public Member Functions | |
static TF_API TfType const & | GetUnknownType () |
Friends | |
template<typename TypeVector > | |
struct | Tf_AddBases |
struct | _TypeInfo |
class | Tf_TypeRegistry |
template<class HashState > | |
void | TfHashAppend (HashState &h, TfType const &type) |
Finding types | |
TF_API TfType const & | FindDerivedByName (const std::string &name) const |
template<typename T > | |
static TfType const & | Find () |
template<typename T > | |
static TfType const & | Find (const T &obj) |
static TfType const & | Find (const std::type_info &t) |
static TfType const & | FindByTypeid (const std::type_info &t) |
static TF_API TfType const & | FindByName (const std::string &name) |
template<typename BASE > | |
static TfType const & | FindDerivedByName (const std::string &name) |
Type queries | |
typedef TfType::_TypeInfo *TfType::* | UnspecifiedBoolType |
TF_API const std::string & | GetTypeName () const |
TF_API const std::type_info & | GetTypeid () const |
TF_API std::vector< std::string > | GetAliases (TfType derivedType) const |
TF_API std::vector< TfType > | GetBaseTypes () const |
TF_API size_t | GetNBaseTypes (TfType *out, size_t maxBases) const |
TF_API std::vector< TfType > | GetDirectlyDerivedTypes () const |
TF_API TfType const & | GetCanonicalType () const |
Return the canonical type for this type. More... | |
TF_API void | GetAllDerivedTypes (std::set< TfType > *result) const |
TF_API void | GetAllAncestorTypes (std::vector< TfType > *result) const |
TF_API bool | IsA (TfType queryType) const |
template<typename T > | |
bool | IsA () const |
bool | IsUnknown () const |
operator UnspecifiedBoolType () const | |
bool | operator! () const |
bool | IsRoot () const |
TF_API bool | IsEnumType () const |
TF_API bool | IsPlainOldDataType () const |
TF_API size_t | GetSizeof () const |
static TF_API TfType const & | GetRoot () |
static TF_API std::string | GetCanonicalTypeName (const std::type_info &) |
Registering new types | |
TF_API void | AddAlias (TfType base, const std::string &name) const |
const TfType & | Alias (TfType base, const std::string &name) const |
static TF_API TfType const & | Declare (const std::string &typeName) |
static TF_API TfType const & | Declare (const std::string &typeName, const std::vector< TfType > &bases, DefinitionCallback definitionCallback=nullptr) |
template<typename T , typename BaseTypes = TfType::Bases<>> | |
static TfType const & | Declare () |
template<typename T , typename B > | |
static TfType const & | Define () |
template<typename T > | |
static TfType const & | Define () |
template<typename Base , typename Derived > | |
static void | AddAlias (const std::string &name) |
TfType represents a dynamic runtime type.
TfTypes are created and discovered at runtime, rather than compile time.
Features:
std::type_info
.std::map
key using TfType::DefinitionCallback = void (*)(TfType) |
typedef TfType::_TypeInfo*TfType::* TfType::UnspecifiedBoolType |
enum TfType::LegacyFlags |
TF_API TfType::TfType | ( | ) |
Construct an TfType representing an unknown type.
To actually register a new type with the TfType system, see TfType::Declare().
Note that this always holds true:
|
inlinestatic |
TF_API void TfType::AddAlias | ( | TfType | base, |
const std::string & | name | ||
) | const |
Add an alias name for this type under the given base type.
Aliases are similar to typedefs in C++: they provide an alternate name for a type. The alias is defined with respect to the given base
type. Aliases must be unique with respect to both other aliases beneath that base type and names of derived types of that base.
|
inline |
Convenience method to add an alias and return *this.
Cast addr
, which pointed to the ancestor type ancestor
, to the type of *this
.
This function is the opposite of CastToAncestor()
; the assumption is that addr
was a pointer to the type corresponding to ancestor
, and was then reinterpret-cast to void*
, but now you wish to turn cast the pointer to the type corresponding to *this
. While the fact that addr
was a pointer of type ancestor
is taken on faith, a runtime check is performed to verify that the underlying object pointed to by addr
is of type *this
(or derived from *this
).
Cast addr
to the address corresponding to the type ancestor
.
(This is a dangerous function; there's probably a much better way to do whatever it is you're trying to do.)
With multiple inheritance, you can't do a reinterpret_cast back to an ancestor type; this function figures out how to cast addr to the address corresponding to the type ancestor if in fact ancestor is really an ancestor of the type corresponding to *this
.
In order for this function to work correctly, addr
must have been a pointer of type corresponding to *this
, which was cast to void; and of course the type of ancestor
must be an ancestor of the type of *this
.
Cast addr
to the address corresponding to the type ancestor
.
(This is a dangerous function; there's probably a much better way to do whatever it is you're trying to do.)
With multiple inheritance, you can't do a reinterpret_cast back to an ancestor type; this function figures out how to cast addr to the address corresponding to the type ancestor if in fact ancestor is really an ancestor of the type corresponding to *this
.
In order for this function to work correctly, addr
must have been a pointer of type corresponding to *this
, which was cast to void; and of course the type of ancestor
must be an ancestor of the type of *this
.
Cast addr
to the address corresponding to the type ancestor
.
(This is a dangerous function; there's probably a much better way to do whatever it is you're trying to do.)
With multiple inheritance, you can't do a reinterpret_cast back to an ancestor type; this function figures out how to cast addr to the address corresponding to the type ancestor if in fact ancestor is really an ancestor of the type corresponding to *this
.
In order for this function to work correctly, addr
must have been a pointer of type corresponding to *this
, which was cast to void; and of course the type of ancestor
must be an ancestor of the type of *this
.
|
static |
Declare a TfType with the given typeName
, but no base type information. This just establishes the minimal stub for the type to exist, prior to it being fleshed out with more declarations (specifying base types) or a definition.
|
static |
Declare a TfType with the given typeName
and bases
. If the bases vector is empty, the type will be marked as deriving from the root TfType (see TfType::GetRootType()). The definitionCallback
, if given, will be invoked later to define the type when needed.
It is ok to redeclare a type that has already been declared. The given bases will supplement any existing bases. An example use of this is the Plugin system, where only a single base may be known in the plugin metadata, but when the code is loaded later, a full set of bases is specified.
It is an error to redeclare a type's definitionCallback.
|
static |
Declares a TfType with the given C++ type T and C++ base types Bases. Each of the base types will be declared (but not defined) as TfTypes if they have not already been. See the other Declare() methods for more details.
Definition at line 65 of file type_Impl.h.
|
static |
Define a TfType with the given C++ type T and C++ base types B. Each of the base types will be declared (but not defined) as TfTypes if they have not already been.
The typeName of the created TfType will be the canonical demangled RTTI type name, as defined by GetCanonicalTypeName().
It is an error to attempt to define a type that has already been defined.
Definition at line 77 of file type_Impl.h.
|
static |
Define a TfType with the given C++ type T and no bases. See the other Define() template for more details.
Definition at line 102 of file type_Impl.h.
|
inline |
Sets the factory object for this type. A type's factory typically has methods to instantiate the type given various arguments and must inherit from FactoryBase
. The factory cannot be changed once set.
Sets the factory object for this type. A type's factory typically has methods to instantiate the type given various arguments and must inherit from FactoryBase
. The factory cannot be changed once set.
|
inline |
|
inlinestatic |
Retrieve the TfType
corresponding to type T
.
The type T
must have been declared or defined in the type system or the TfType
corresponding to an unknown type is returned.
Retrieve the TfType
corresponding to obj
.
The TfType
corresponding to the actual object represented by obj
is returned; this may not be the object returned by TfType::Find<T>()
if T
is a polymorphic type.
This works for Python subclasses of the C++ type T
as well, as long as T
has been wrapped using TfPyPolymorphic.
Of course, the object's type must have been declared or defined in the type system or the TfType
corresponding to an unknown type is returned.
|
inlinestatic |
|
static |
Retrieve the TfType
corresponding to the given name
.
Every type defined in the TfType system has a unique, implementation independent name. In addition, aliases can be added to identify a type underneath a specific base type; see TfType::AddAlias(). The given name will first be tried as an alias under the root type, and subsequently as a typename.
This method is equivalent to:
For any object obj
,
|
inlinestatic |
TF_API TfType const& TfType::FindDerivedByName | ( | const std::string & | name | ) | const |
|
inlinestatic |
Retrieve the TfType
that derives from BASE and has the given alias or typename.
This is a convenience method, and is equivalent to:
TF_API std::vector<std::string> TfType::GetAliases | ( | TfType | derivedType | ) | const |
Returns a vector of the aliases registered for the derivedType under this, the base type.
Build a vector of all ancestor types inherited by this type. The starting type is itself included, as the first element of the results vector.
Types are given in "C3" resolution order, as used for new-style classes starting in Python 2.3. This algorithm is more complicated than a simple depth-first traversal of base classes, in order to prevent some subtle errors with multiple-inheritance. See the references below for more background.
Return the set of all types derived (directly or indirectly) from this type.
Return a vector of types from which this type was derived.
|
static |
Return the canonical typeName used for a given std::type_info.
Exactly how the canonical name is generated is left undefined, but in practice it is likely to be the demangled RTTI name of the type_info, stripped of namespaces. The real answer is implemented by this method.
Return a vector of types derived directly from this type.
|
inline |
Returns the factory object for this type as a T*
, or NULL
if there is no factory or the factory is not or is not derived from T
. Clients can check if a factory is set using GetFactory<TfType::FactoryBase>()
.
Copy the first maxBases
base types of this
type to out
, or all the base types if this type has maxBases
or fewer base types. Return this
type's number of base types.
Note that it is supported to change a TfType to its first base type by calling this function. For example:
Return the root type of the type hierarchy.
All known types derive (directly or indirectly) from the root. If a type is specified with no bases, it is implicitly considered to derive from the root type.
TF_API size_t TfType::GetSizeof | ( | ) | const |
Return the size required to hold an instance of this type on the stack (does not include any heap allocated memory the instance uses).
This is what the C++ sizeof operator returns for the type, so this value is not very useful for Python types (it will always be sizeof(hboost::python::object)).
TF_API const std::type_info& TfType::GetTypeid | ( | ) | const |
Return a C++ RTTI type_info for this type.
If this type is unknown or has not yet had a C++ type defined, typeid(void)
will be returned.
TF_API const std::string& TfType::GetTypeName | ( | ) | const |
Return an empty TfType, representing the unknown type.
This is equivalento the default constructor, TfType(). This form exists as a clearer way to express intent in code explicitly dealing with unknown types.
Return true if this type is the same as or derived from queryType
. If queryType
is unknown, this always returns false
.
|
inline |
TF_API bool TfType::IsEnumType | ( | ) | const |
Return true if this is an enum type.
TF_API bool TfType::IsPlainOldDataType | ( | ) | const |
Return true if this is a plain old data type, as defined by C++.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Equality operator.
TF_API void TfType::SetFactory | ( | std::unique_ptr< FactoryBase > | factory | ) | const |
Sets the factory object for this type. A type's factory typically has methods to instantiate the type given various arguments and must inherit from FactoryBase
. The factory cannot be changed once set.
Sets the factory object for this type. A type's factory typically has methods to instantiate the type given various arguments and must inherit from FactoryBase
. The factory cannot be changed once set.
|
inline |
|
friend |