TypeHandle is the identifier used to differentiate C++ class types. More...
#include "typeHandle.h"
Public Types | |
enum | MemoryClass { MC_singleton, MC_array, MC_deleted_chain_active, MC_deleted_chain_inactive, MC_limit } |
Public Member Functions | |
void * | allocate_array (size_t size) |
Allocates memory, adding it to the total amount of memory allocated for this type. More... | |
int | compare_to (const TypeHandle &other) const |
Sorts TypeHandles arbitrarily (according to <, >, etc.). More... | |
void | deallocate_array (void *ptr) |
Deallocates memory, subtracting it from the total amount of memory allocated for this type. More... | |
void | dec_memory_usage (MemoryClass memory_class, size_t size) |
Subtracts the indicated amount from the record for the total allocated memory for objects of this type. More... | |
int | get_best_parent_from_Set (const std::set< int > &legal_vals) const |
Return the Index of the BEst fit Classs from a set. More... | |
TypeHandle | get_child_class (int index) const |
size_t | get_hash () const |
Returns a hash code suitable for phash_map. More... | |
int | get_index () const |
size_t | get_memory_usage (MemoryClass memory_class) const |
Returns the total allocated memory used by objects of this type, for the indicated memory class. More... | |
std::string | get_name (TypedObject *object=nullptr) const |
int | get_num_child_classes (TypedObject *object=nullptr) const |
int | get_num_parent_classes (TypedObject *object=nullptr) const |
TypeHandle | get_parent_class (int index) const |
TypeHandle | get_parent_towards (TypeHandle ancestor, TypedObject *object=nullptr) const |
Returns the parent class that is in a direct line of inheritance to the indicated ancestor class. More... | |
void | inc_memory_usage (MemoryClass memory_class, size_t size) |
Adds the indicated amount to the record for the total allocated memory for objects of this type. More... | |
bool | is_derived_from (TypeHandle parent, TypedObject *object=nullptr) const |
Returns true if this type is derived from the indicated type, false otherwise. More... | |
bool | operator != (const TypeHandle &other) const |
bool | operator > (const TypeHandle &other) const |
bool | operator >= (const TypeHandle &other) const |
operator bool () const | |
TypeHandle::none() evaluates to false, everything else evaluates to true. More... | |
bool | operator< (const TypeHandle &other) const |
bool | operator<= (const TypeHandle &other) const |
bool | operator== (const TypeHandle &other) const |
void | output (std::ostream &out) const |
void * | reallocate_array (void *ptr, size_t size) |
Reallocates memory, adjusting the total amount of memory allocated for this type. More... | |
Static Public Member Functions | |
static constexpr TypeHandle | from_index (int index) |
static constexpr TypeHandle | none () |
Public Attributes | |
get_child_class | |
Returns the nth child class of this type. More... | |
get_index | |
Returns the integer index associated with this TypeHandle. More... | |
get_name | |
Returns the name of the type. More... | |
get_num_child_classes | |
Returns the number of child classes that this type is known to have. More... | |
get_num_parent_classes | |
Returns the number of parent classes that this type is known to have. More... | |
get_parent_class | |
Returns the nth parent class of this type. More... | |
Friends | |
class | TypeRegistry |
TypeHandle is the identifier used to differentiate C++ class types.
Any C++ classes that inherit from some base class, and must be differentiated at run time, should store a static TypeHandle object that can be queried through a static member function named get_class_type(). Most of the time, it is also desirable to inherit from TypedObject, which provides some virtual functions to return the TypeHandle for a particular instance.
At its essence, a TypeHandle is simply a unique identifier that is assigned by the TypeRegistry. The TypeRegistry stores a tree of TypeHandles, so that ancestry of a particular type may be queried, and the type name may be retrieved for run-time display.
Definition at line 81 of file typeHandle.h.
void * TypeHandle::allocate_array | ( | size_t | size | ) |
Allocates memory, adding it to the total amount of memory allocated for this type.
Definition at line 88 of file typeHandle.cxx.
|
inline |
Sorts TypeHandles arbitrarily (according to <, >, etc.).
Returns a number less than 0 if this type sorts before the other one, greater than zero if it sorts after, 0 if they are equivalent.
Definition at line 68 of file typeHandle.I.
void TypeHandle::deallocate_array | ( | void * | ptr | ) |
Deallocates memory, subtracting it from the total amount of memory allocated for this type.
Definition at line 141 of file typeHandle.cxx.
void TypeHandle::dec_memory_usage | ( | MemoryClass | memory_class, |
size_t | size | ||
) |
Subtracts the indicated amount from the record for the total allocated memory for objects of this type.
Definition at line 67 of file typeHandle.cxx.
References AtomicAdjustDummyImpl::add(), and TypeRegistry::ptr().
int TypeHandle::get_best_parent_from_Set | ( | const std::set< int > & | legal_vals | ) | const |
Return the Index of the BEst fit Classs from a set.
Definition at line 175 of file typeHandle.cxx.
|
inline |
Returns a hash code suitable for phash_map.
Definition at line 76 of file typeHandle.I.
size_t TypeHandle::get_memory_usage | ( | MemoryClass | memory_class | ) | const |
Returns the total allocated memory used by objects of this type, for the indicated memory class.
This is only updated if track-memory-usage is set true in your Config.prc file.
Definition at line 24 of file typeHandle.cxx.
References AtomicAdjustDummyImpl::get(), and TypeRegistry::ptr().
|
inline |
Returns the parent class that is in a direct line of inheritance to the indicated ancestor class.
This is useful in the presence of multiple inheritance to try to determine what properties an unknown type may have.
The return value is TypeHandle::none() if the type does not inherit from the ancestor. If ancestor is the same as this type, the return value is this type.
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 170 of file typeHandle.I.
References TypeRegistry::get_parent_towards(), and TypeRegistry::ptr().
void TypeHandle::inc_memory_usage | ( | MemoryClass | memory_class, |
size_t | size | ||
) |
Adds the indicated amount to the record for the total allocated memory for objects of this type.
Definition at line 43 of file typeHandle.cxx.
References AtomicAdjustDummyImpl::add(), and TypeRegistry::ptr().
|
inline |
Returns true if this type is derived from the indicated type, false otherwise.
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 105 of file typeHandle.I.
References TypeRegistry::is_derived_from(), and TypeRegistry::ptr().
Referenced by TypedObject::is_of_type().
|
inline |
TypeHandle::none() evaluates to false, everything else evaluates to true.
Definition at line 198 of file typeHandle.I.
void * TypeHandle::reallocate_array | ( | void * | ptr, |
size_t | size | ||
) |
Reallocates memory, adjusting the total amount of memory allocated for this type.
Definition at line 115 of file typeHandle.cxx.
|
inline |
Returns the nth child class of this type.
The index should be in the range 0 <= index < get_num_child_classes().
Definition at line 138 of file typeHandle.h.
|
inline |
Returns the integer index associated with this TypeHandle.
Each different TypeHandle will have a different index. However, you probably shouldn't be using this method; you should just treat the TypeHandles as opaque classes. This is provided for the convenience of non-C++ scripting languages to build a hashtable of TypeHandles.
Definition at line 135 of file typeHandle.h.
Referenced by RenderEffect::compare_to(), get_pipe_type_pandadx9(), get_pipe_type_pandagl(), get_pipe_type_pandagles(), get_pipe_type_pandagles2(), RenderAttribRegistry::get_slot(), and BamWriter::write_handle().
|
inline |
Returns the name of the type.
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 136 of file typeHandle.h.
Referenced by XFileDataObject::get_type_name().
|
inline |
Returns the number of child classes that this type is known to have.
This may then be used to index into get_child_class().
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 138 of file typeHandle.h.
|
inline |
Returns the number of parent classes that this type is known to have.
This may then be used to index into get_parent_class(). The result will be 0 if this class does not inherit from any other classes, 1 if normal, single inheritance is in effect, or greater than one if multiple inheritance is in effect.
The "object" pointer is an optional pointer to the TypedObject class that owns this TypeHandle. It is only used in case the TypeHandle is inadvertantly undefined.
Definition at line 137 of file typeHandle.h.
Referenced by FactoryBase::find_registered_type(), and FactoryBase::make_instance_more_general().
|
inline |
Returns the nth parent class of this type.
The index should be in the range 0 <= index < get_num_parent_classes().
Definition at line 137 of file typeHandle.h.