Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Friends

TypeHandle Class Reference

TypeHandle is the identifier used to differentiate C++ class types. More...

#include "typeHandle.h"

List of all members.

Public Types

enum  MemoryClass {
  MC_singleton, MC_array, MC_deleted_chain_active, MC_deleted_chain_inactive,
  MC_limit
}

Public Member Functions

 TypeHandle ()
 The default constructor must do nothing, because we can't guarantee ordering of static initializers.
 TypeHandle (const TypeHandle &copy)
int compare_to (const TypeHandle &other) const
 Sorts TypeHandles arbitrarily (according to <, >, etc.).
void dec_memory_usage (MemoryClass, int)
int get_best_parent_from_Set (const std::set< int > &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.
size_t get_hash () const
 Returns a hash code suitable for phash_map.
int get_index () const
 Returns the integer index associated with this TypeHandle.
int get_memory_usage (MemoryClass) const
string get_name (TypedObject *object=(TypedObject *) NULL) const
 Returns the name of the type.
int get_num_child_classes (TypedObject *object=(TypedObject *) NULL) const
 Returns the number of child classes that this type is known to have.
int get_num_parent_classes (TypedObject *object=(TypedObject *) NULL) const
 Returns the number of parent classes that this type is known to have.
TypeHandle get_parent_class (int index) const
 Returns the nth parent class of this type.
TypeHandle get_parent_towards (TypeHandle ancestor, TypedObject *object=(TypedObject *) NULL) const
 Returns the parent class that is in a direct line of inheritance to the indicated ancestor class.
void inc_memory_usage (MemoryClass, int)
bool is_derived_from (TypeHandle parent, TypedObject *object=(TypedObject *) NULL) const
 Returns true if this type is derived from the indicated type, false otherwise.
bool operator!= (const TypeHandle &other) const
bool operator< (const TypeHandle &other) const
bool operator<= (const TypeHandle &other) const
bool operator== (const TypeHandle &other) const
bool operator> (const TypeHandle &other) const
bool operator>= (const TypeHandle &other) const
void output (ostream &out) const

Static Public Member Functions

static TypeHandle none ()
 Returns a special zero-valued TypeHandle that is used to indicate no type.

Friends

class TypeRegistry

Detailed Description

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 90 of file typeHandle.h.


Constructor & Destructor Documentation

TypeHandle::TypeHandle ( ) [inline]

The default constructor must do nothing, because we can't guarantee ordering of static initializers.

If the constructor tried to initialize its value, it might happen after the value had already been set previously by another static initializer!

Definition at line 26 of file typeHandle.I.


Member Function Documentation

int TypeHandle::compare_to ( const TypeHandle other) const [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 107 of file typeHandle.I.

int TypeHandle::get_best_parent_from_Set ( const std::set< int > &  legal_vals) const [inline]

Return the Index of the BEst fit Classs from a set.

Definition at line 283 of file typeHandle.I.

References get_best_parent_from_Set(), get_num_parent_classes(), and get_parent_class().

Referenced by get_best_parent_from_Set().

TypeHandle TypeHandle::get_child_class ( int  index) const [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 214 of file typeHandle.I.

References TypeRegistry::get_child_class(), and TypeRegistry::ptr().

size_t TypeHandle::get_hash ( ) const [inline]

Returns a hash code suitable for phash_map.

Definition at line 117 of file typeHandle.I.

int TypeHandle::get_index ( ) const [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 253 of file typeHandle.I.

Referenced by RenderEffect::compare_to(), RenderAttrib::compare_to(), GeomMunger::compare_to(), GeomMunger::geom_compare_to(), RenderAttribRegistry::get_slot(), TypedObject::get_type_index(), RenderAttribRegistry::register_slot(), and BamWriter::write_handle().

string TypeHandle::get_name ( TypedObject object = (TypedObject *)NULL) const [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 132 of file typeHandle.I.

References TypeRegistry::get_name(), none(), and TypeRegistry::ptr().

Referenced by CInterval::check_started(), CInterval::check_stopped(), AnimGroup::complete_pointers(), XFileDataObject::get_type_name(), TypedObject::is_exact_type(), and BamWriter::write_handle().

int TypeHandle::get_num_child_classes ( TypedObject object = (TypedObject *)NULL) const [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 202 of file typeHandle.I.

References TypeRegistry::get_num_child_classes(), and TypeRegistry::ptr().

int TypeHandle::get_num_parent_classes ( TypedObject object = (TypedObject *)NULL) const [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 173 of file typeHandle.I.

References TypeRegistry::get_num_parent_classes(), and TypeRegistry::ptr().

Referenced by FactoryBase::find_registered_type(), get_best_parent_from_Set(), FactoryBase::make_instance_more_general(), and BamWriter::write_handle().

TypeHandle TypeHandle::get_parent_class ( int  index) const [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 185 of file typeHandle.I.

References TypeRegistry::get_parent_class(), and TypeRegistry::ptr().

Referenced by FactoryBase::find_registered_type(), get_best_parent_from_Set(), FactoryBase::make_instance_more_general(), and BamWriter::write_handle().

TypeHandle TypeHandle::get_parent_towards ( TypeHandle  ancestor,
TypedObject object = (TypedObject *)NULL 
) const [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 237 of file typeHandle.I.

References TypeRegistry::get_parent_towards(), and TypeRegistry::ptr().

Referenced by BamReader::read_handle().

bool TypeHandle::is_derived_from ( TypeHandle  parent,
TypedObject object = (TypedObject *)NULL 
) const [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 152 of file typeHandle.I.

References TypeRegistry::is_derived_from(), and TypeRegistry::ptr().

Referenced by GraphicsPipeSelection::add_pipe_type(), TypedObject::is_of_type(), and BulletGhostNode::parents_changed().

TypeHandle TypeHandle::none ( ) [inline, static]

The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations