|
TF_API | TfType () |
| Construct an TfType representing an unknown type. More...
|
|
bool | operator== (const TfType &t) const |
| Equality operator. More...
|
|
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 |
|
|
TF_API void * | CastToAncestor (TfType ancestor, void *addr) const |
| Cast addr to the address corresponding to the type ancestor . More...
|
|
const void * | CastToAncestor (TfType ancestor, const void *addr) const |
|
TF_API void * | CastFromAncestor (TfType ancestor, void *addr) const |
| Cast addr , which pointed to the ancestor type ancestor , to the type of *this . More...
|
|
const void * | CastFromAncestor (TfType ancestor, const void *addr) const |
|
|
TF_API void | SetFactory (std::unique_ptr< FactoryBase > factory) const |
| Sets the factory object for this type. More...
|
|
template<class T > |
void | SetFactory (std::unique_ptr< T > &factory) const |
| Sets the factory object for this type. More...
|
|
template<class T > |
void | SetFactory () const |
| Sets the factory object for this type to be a T . More...
|
|
const TfType & | Factory (std::unique_ptr< FactoryBase > factory) const |
| Sets the factory object for this type. More...
|
|
template<class T > |
const TfType & | Factory (std::unique_ptr< T > &factory) const |
| Sets the factory object for this type. More...
|
|
template<class T > |
const TfType & | Factory () const |
| Sets the factory object for this type to be a T . More...
|
|
template<class T > |
T * | GetFactory () const |
| 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 . More...
|
|
|
typedef TfType::_TypeInfo *TfType::* | UnspecifiedBoolType |
|
TF_API const std::string & | GetTypeName () const |
| Return the machine-independent name for this type. More...
|
|
TF_API const std::type_info & | GetTypeid () const |
| Return a C++ RTTI type_info for this type. More...
|
|
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. More...
|
|
TF_API TfPyObjWrapper | GetPythonClass () const |
| Return the Python class object for this type. More...
|
|
TF_API std::vector< TfType > | GetBaseTypes () const |
| Return a vector of types from which this type was derived. More...
|
|
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 maxBases or fewer base types. More...
|
|
TF_API std::vector< TfType > | GetDirectlyDerivedTypes () const |
| Return a vector of types derived directly from this type. More...
|
|
TF_API TfType const & | GetCanonicalType () const |
| Return the canonical type for this type. More...
|
|
TF_API void | GetAllDerivedTypes (std::set< TfType > *result) const |
| Return the set of all types derived (directly or indirectly) from this type. More...
|
|
TF_API void | GetAllAncestorTypes (std::vector< TfType > *result) const |
| Build a vector of all ancestor types inherited by this type. More...
|
|
TF_API bool | IsA (TfType queryType) const |
| Return true if this type is the same as or derived from queryType . More...
|
|
template<typename T > |
bool | IsA () const |
| Return true if this type is the same as or derived from T. More...
|
|
bool | IsUnknown () const |
| Return true if this is the unknown type, representing a type unknown to the TfType system. More...
|
|
| operator UnspecifiedBoolType () const |
| Convert to bool – return true if this type is not unknown, false otherwise. More...
|
|
bool | operator ! () const |
| Boolean not operator – return true if this type is unknown, false otherwise. More...
|
|
bool | IsRoot () const |
| Return true if this is the root type. More...
|
|
TF_API bool | IsEnumType () const |
| Return true if this is an enum type. More...
|
|
TF_API bool | IsPlainOldDataType () const |
| Return true if this is a plain old data type, as defined by C++. More...
|
|
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 allocated memory the instance uses). More...
|
|
static TF_API TfType const & | GetRoot () |
| Return the root type of the type hierarchy. More...
|
|
static TF_API std::string | GetCanonicalTypeName (const std::type_info &) |
| Return the canonical typeName used for a given std::type_info. More...
|
|
|
TF_API void | DefinePythonClass (const TfPyObjWrapper &classObj) const |
| Define the Python class object corresponding to this TfType. More...
|
|
TF_API void | AddAlias (TfType base, const std::string &name) const |
| Add an alias name for this type under the given base type. More...
|
|
const TfType & | Alias (TfType base, const std::string &name) const |
| Convenience method to add an alias and return *this. More...
|
|
static TF_API TfType const & | Declare (const std::string &typeName) |
| Declare a TfType with the given typeName , but no base type information. More...
|
|
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 . More...
|
|
template<typename T , typename BaseTypes = TfType::Bases<>> |
static TfType const & | Declare () |
| Declares a TfType with the given C++ type T and C++ base types Bases. More...
|
|
template<typename T , typename B > |
static TfType const & | Define () |
| Define a TfType with the given C++ type T and C++ base types B. More...
|
|
template<typename T > |
static TfType const & | Define () |
| Define a TfType with the given C++ type T and no bases. More...
|
|
template<typename Base , typename Derived > |
static void | AddAlias (const std::string &name) |
| Add an alias for DERIVED beneath BASE. More...
|
|
TfType represents a dynamic runtime type.
TfTypes are created and discovered at runtime, rather than compile time.
Features:
- unique typename
- safe across DSO boundaries
- can represent C++ types, pure Python types, or Python subclasses of wrapped C++ types
- lightweight value semantics – you can copy and default construct TfType, unlike
std::type_info
.
- totally ordered – can use as a
std::map
key
Definition at line 64 of file type.h.
TF_API void* CastFromAncestor |
( |
TfType |
ancestor, |
|
|
void * |
addr |
|
) |
| const |
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
).
- Warning
- Again, this is dangerous territory, and there's probably something much better than using this function.
TF_API void* CastToAncestor |
( |
TfType |
ancestor, |
|
|
void * |
addr |
|
) |
| const |
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
.
- Warning
- You are warned: this is deadly dangerous stuff, and you shouldn't be doing it!
static TF_API TfType const& Declare |
( |
const std::string & |
typeName, |
|
|
const std::vector< TfType > & |
bases, |
|
|
DefinitionCallback |
definitionCallback = nullptr |
|
) |
| |
|
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.
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 90 of file type_Impl.h.
static TfType const& Find |
( |
const T & |
obj | ) |
|
|
inlinestatic |
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.
- See also
- IsUnknown()
Definition at line 173 of file type.h.
TF_API void GetAllAncestorTypes |
( |
std::vector< TfType > * |
result | ) |
const |
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.
- Note
- This can be expensive; consider caching the results. TfType does not cache this itself since it is not needed internally.
- See also
- Guido van Rossum. "Unifying types and classes in Python 2.2: Method resolution order." http://www.python.org/download/releases/2.2.2/descrintro/#mro
-
Barrett, Cassels, Haahr, Moon, Playford, Withington. "A Monotonic Superclass Linearization for Dylan." OOPSLA 96. http://www.webcom.com/haahr/dylan/linearization-oopsla96.html