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

This is an abstract class that all classes which use TypeHandle, and also provide virtual functions to support polymorphism, should inherit from. More...

Inheritance diagram for TypedObject:
CallbackData CollisionRecorder Datagram EventHandler GeoMipTerrain LoaderFileType MeshDrawer MeshDrawer2D SavedContext SocketIP TypedReferenceCount TypedWritable OdeBody OdeGeom OdeJoint OdeJointGroup OdeSpace OdeSurfaceParameters OdeWorld TypedSkel

Public Member Functions

TypeHandle getType ()
 
int getTypeIndex ()
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool isExactType (TypeHandle handle)
 Returns true if the current object is the indicated type exactly. More...
 
bool isOfType (TypeHandle handle)
 Returns true if the current object is or derives from the indicated type. More...
 

Static Public Member Functions

static TypeHandle getClassType ()
 

Public Attributes

TypeHandle type
 Returns the TypeHandle representing this object's type. More...
 

Detailed Description

This is an abstract class that all classes which use TypeHandle, and also provide virtual functions to support polymorphism, should inherit from.

Each derived class should define get_type(), which should return the specific type of the derived class. Inheriting from this automatically provides support for is_of_type() and is_exact_type().

All classes that inherit directly or indirectly from TypedObject should redefine get_type() and force_init_type(), as shown below. Some classes that do not inherit from TypedObject may still declare TypeHandles for themselves by defining methods called get_class_type() and init_type(). Classes such as these may serve as base classes, but the dynamic type identification system will be limited. Classes that do not inherit from TypedObject need not define the virtual functions get_type() and force_init_type() (or any other virtual functions).

There is a specific layout for defining the overrides from this class. Keeping the definitions formatted just like these examples will allow someone in the future to use a sed (or similar) script to make global changes, if necessary. Avoid rearranging the braces or the order of the functions unless you're ready to change them in every file all at once.

What follows are some examples that can be used in new classes that you create.

In the class definition (.h file):
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
\<\<\<BaseClassOne\>\>\>::init_type();
\<\<\<BaseClassTwo\>\>\>::init_type();
\<\<\<BaseClassN\>\>\>::init_type();
register_type(_type_handle, "<<<ThisClassStringName>>>",
\<\<\<BaseClassOne\>\>\>::get_class_type(),
\<\<\<BaseClassTwo\>\>\>::get_class_type(),
\<\<\<BaseClassN\>\>\>::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
In the class .cxx file:
TypeHandle \<\<\<ThisClassStringName\>\>\>::_type_handle;
In the class config_<<<PackageName>>>.cxx file:
ConfigureFn(config_\<\<\<PackageName\>\>\>) {
\<\<\<ClassOne\>\>\>::init_type();
\<\<\<ClassTwo\>\>\>::init_type();
\<\<\<ClassN\>\>\>::init_type();
}

Member Function Documentation

◆ getClassType()

static TypeHandle getClassType ( )
static

◆ getType()

TypeHandle getType ( )

◆ getTypeIndex()

int getTypeIndex ( )

Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

This is equivalent to get_type().get_index().

◆ isExactType()

bool isExactType ( TypeHandle  handle)

Returns true if the current object is the indicated type exactly.

◆ isOfType()

bool isOfType ( TypeHandle  handle)

Returns true if the current object is or derives from the indicated type.

Member Data Documentation

◆ type

TypeHandle type

Returns the TypeHandle representing this object's type.