Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
TypeHandle Class Reference

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. More...

Public Types

enum  MemoryClass {
  MC_singleton = 0, MC_array = 1, MC_deleted_chain_active = 2, MC_deleted_chain_inactive = 3,
  MC_limit = 4
}
 

Public Member Functions

 __init__ ()
 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! More...
 
 __init__ (const TypeHandle copy)
 
int compareTo (const TypeHandle other)
 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. More...
 
 decMemoryUsage (TypeHandle::MemoryClass memory_class, int size)
 
int getBestParentFromSet (const SetInt legal_vals)
 Return the Index of the BEst fit Classs from a set. More...
 
TypeHandle getChildClass (int index)
 Returns the nth child class of this type. The index should be in the range 0 <= index < get_num_child_classes(). More...
 
size_t getHash ()
 Returns a hash code suitable for phash_map. More...
 
int getIndex ()
 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. More...
 
int getMemoryUsage (TypeHandle::MemoryClass memory_class)
 
str getName (TypedObject object)
 Returns the name of the type. More...
 
int getNumChildClasses (TypedObject object)
 Returns the number of child classes that this type is known to have. This may then be used to index into get_child_class(). More...
 
int getNumParentClasses (TypedObject object)
 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. More...
 
TypeHandle getParentClass (int index)
 Returns the nth parent class of this type. The index should be in the range 0 <= index < get_num_parent_classes(). More...
 
TypeHandle getParentTowards (TypeHandle ancestor, TypedObject object)
 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. More...
 
 incMemoryUsage (TypeHandle::MemoryClass memory_class, int size)
 
bool isDerivedFrom (TypeHandle parent, TypedObject object)
 Returns true if this type is derived from the indicated type, false otherwise. More...
 
bool operator!= (const TypeHandle other)
 
bool operator< (const TypeHandle other)
 
bool operator<= (const TypeHandle other)
 
bool operator== (const TypeHandle other)
 
bool operator> (const TypeHandle other)
 
bool operator>= (const TypeHandle other)
 
 output (Ostream out)
 

Static Public Member Functions

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

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.

Member Enumeration Documentation

◆ MemoryClass

Enumerator
MC_singleton 
MC_array 
MC_deleted_chain_active 
MC_deleted_chain_inactive 
MC_limit 

Not a real value, just a placeholder for the maximum enum value.

Member Function Documentation

◆ __init__() [1/2]

__init__ ( )

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!

◆ __init__() [2/2]

__init__ ( const TypeHandle  copy)

◆ compareTo()

int compareTo ( const TypeHandle  other)

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.

◆ decMemoryUsage()

decMemoryUsage ( TypeHandle::MemoryClass  memory_class,
int  size 
)

◆ getBestParentFromSet()

int getBestParentFromSet ( const SetInt  legal_vals)

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

◆ getChildClass()

TypeHandle getChildClass ( int  index)

Returns the nth child class of this type. The index should be in the range 0 <= index < get_num_child_classes().

◆ getHash()

size_t getHash ( )

Returns a hash code suitable for phash_map.

◆ getIndex()

int getIndex ( )

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.

◆ getMemoryUsage()

int getMemoryUsage ( TypeHandle::MemoryClass  memory_class)

◆ getName()

str getName ( TypedObject  object)

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.

◆ getNumChildClasses()

int getNumChildClasses ( TypedObject  object)

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.

◆ getNumParentClasses()

int getNumParentClasses ( TypedObject  object)

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.

◆ getParentClass()

TypeHandle getParentClass ( int  index)

Returns the nth parent class of this type. The index should be in the range 0 <= index < get_num_parent_classes().

◆ getParentTowards()

TypeHandle getParentTowards ( TypeHandle  ancestor,
TypedObject  object 
)

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.

◆ incMemoryUsage()

incMemoryUsage ( TypeHandle::MemoryClass  memory_class,
int  size 
)

◆ isDerivedFrom()

bool isDerivedFrom ( TypeHandle  parent,
TypedObject  object 
)

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.

◆ make()

static TypeHandle make ( PyTypeObject  classobj)
static

◆ none()

static TypeHandle none ( )
static

Returns a special zero-valued TypeHandle that is used to indicate no type.

◆ operator!=()

bool operator!= ( const TypeHandle  other)

◆ operator<()

bool operator< ( const TypeHandle  other)

◆ operator<=()

bool operator<= ( const TypeHandle  other)

◆ operator==()

bool operator== ( const TypeHandle  other)

◆ operator>()

bool operator> ( const TypeHandle  other)

◆ operator>=()

bool operator>= ( const TypeHandle  other)

◆ output()

output ( Ostream  out)