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
TypeRegistrystores 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.
enumerator MC_singleton = 0
enumerator MC_array = 1
enumerator MC_deleted_chain_active = 2
enumerator MC_deleted_chain_inactive = 3
enumerator MC_limit = 4
Not a real value, just a placeholder for the maximum enum value.
- enumerator MC_singleton = 0
TypeHandle(void) noexcept = default
TypeHandle(TypeHandle const&) = default
Private constructor for initializing a
TypeHandlefrom an index, used by
none()and by from_index().
int compare_to(TypeHandle const &other) const
TypeHandlesarbitrarily (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.
void dec_memory_usage(TypeHandle::MemoryClass memory_class, std::size_t size)
Subtracts the indicated amount from the record for the total allocated memory for objects of this type.
int get_best_parent_from_Set(set<int> const &legal_vals) const
Return the Index of the BEst fit Classs from a set
TypeHandle get_child_class(int index) const
Returns the nth child class of this type. The index should be in the range 0 <= index <
std::size_t get_hash(void) const
Returns a hash code suitable for phash_map.
int get_index(void) const
Returns the integer index associated with this
TypeHandle. Each different
TypeHandlewill have a different index. However, you probably shouldn’t be using this method; you should just treat the
TypeHandlesas opaque classes. This is provided for the convenience of non-C++ scripting languages to build a hashtable of
std::size_t get_memory_usage(TypeHandle::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.
std::string get_name(TypedObject *object = nullptr) const
Returns the name of the type.
int get_num_child_classes(TypedObject *object = nullptr) const
Returns the number of child classes that this type is known to have. This may then be used to index into
int get_num_parent_classes(TypedObject *object = nullptr) const
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.
TypeHandle get_parent_class(int index) const
Returns the nth parent class of this type. The index should be in the range 0 <= index <
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. 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.
void inc_memory_usage(TypeHandle::MemoryClass memory_class, std::size_t size)
Adds the indicated amount to the record for the total allocated memory for objects of this type.
bool is_derived_from(TypeHandle parent, TypedObject *object = nullptr) const
Returns true if this type is derived from the indicated type, false otherwise.
void output(std::ostream &out) const
- enum MemoryClass