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

TypeHandle is the identifier used to differentiate C++ class types. 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__ ()
 
 __init__ (const TypeHandle)
 
int compareTo (const TypeHandle other)
 Sorts TypeHandles arbitrarily (according to <, >, etc.). More...
 
 decMemoryUsage (TypeHandle::MemoryClass memory_class, int size)
 Subtracts the indicated amount from the record for the total allocated memory for objects of this type. More...
 
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. More...
 
int getHash ()
 Returns a hash code suitable for phash_map. More...
 
int getIndex ()
 Returns the integer index associated with this TypeHandle. More...
 
int getMemoryUsage (TypeHandle::MemoryClass memory_class)
 Returns the total allocated memory used by objects of this type, for the indicated memory class. More...
 
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. More...
 
int getNumParentClasses (TypedObject object)
 Returns the number of parent classes that this type is known to have. More...
 
TypeHandle getParentClass (int index)
 Returns the nth parent class of this type. More...
 
TypeHandle getParentTowards (TypeHandle ancestor, TypedObject object)
 Returns the parent class that is in a direct line of inheritance to the indicated ancestor class. More...
 
 incMemoryUsage (TypeHandle::MemoryClass memory_class, int size)
 Adds the indicated amount to the record for the total allocated memory for objects of this type. More...
 
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 ()
 

Public Attributes

TypeHandle child_classes []
 
int index
 Returns the integer index associated with this TypeHandle. More...
 
String name
 Returns the name of the type. More...
 
TypeHandle parent_classes []
 

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__ ( )

◆ __init__() [2/2]

__init__ ( const  TypeHandle)

◆ 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 
)

Subtracts the indicated amount from the record for the total allocated memory for objects of this type.

◆ 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()

int 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)

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.

◆ 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 
)

Adds the indicated amount to the record for the total allocated memory for objects of this type.

◆ 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

◆ 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)

Member Data Documentation

◆ child_classes

TypeHandle child_classes[]

◆ index

int index

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.

◆ name

String name

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.

◆ parent_classes

TypeHandle parent_classes[]