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

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

#include "typedObject.h"

Inheritance diagram for TypedObject:
MemoryBase CallbackData Configurable Datagram EggBackPointer EventHandler GeoMipTerrain IffInputFile LoaderFileType MeshDrawer MeshDrawer2D OdeBody OdeGeom OdeJoint OdeJointGroup OdeSpace OdeSurfaceParameters OdeWorld PhysxContactPoint PortalClipper SampleClass SavedContext Socket_IP TexturePoolFilter TypedReferenceCount TypedSkel TypedWritable XFileNode

Public Member Functions

 TypedObject (const TypedObject &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
virtual TypeHandle force_init_type ()=0
 
int get_best_parent_from_Set (const std::set< int > &) const
 
virtual TypeHandle get_type () const =0
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
TypedObjectoperator= (const TypedObject &copy)=default
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96. More...
 

Public Attributes

 get_type
 

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:
In the class config_<<>>.cxx file:
ConfigureFn(config_<<<PackageName>>>) {
<<<ClassOne>>>::init_type();
<<<ClassTwo>>>::init_type();
<<<ClassN>>>::init_type();
}

Definition at line 88 of file typedObject.h.

Member Function Documentation

◆ as_typed_object() [1/2]

TypedObject * TypedObject::as_typed_object ( )
inline

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 58 of file typedObject.I.

◆ as_typed_object() [2/2]

const TypedObject * TypedObject::as_typed_object ( ) const
inline

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 66 of file typedObject.I.

◆ get_type_index()

int TypedObject::get_type_index ( ) const
inline

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

Definition at line 20 of file typedObject.I.

◆ init_type()

void TypedObject::init_type ( )
static

This function is declared non-inline to work around a compiler bug in g++ 2.96.

Making it inline seems to cause problems in the optimizer.

Definition at line 44 of file typedObject.cxx.

References register_type().

Referenced by init_libexpress(), and init_libputil().

◆ is_exact_type()

bool TypedObject::is_exact_type ( TypeHandle  handle) const
inline

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

Definition at line 38 of file typedObject.I.

Referenced by PortalNode::combine_with(), GeomNode::combine_with(), Character::combine_with(), PandaNode::combine_with(), SpeedTreeNode::combine_with(), and PT().

◆ is_of_type()

bool TypedObject::is_of_type ( TypeHandle  handle) const
inline

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

Definition at line 28 of file typedObject.I.

References TypeHandle::is_derived_from().

Referenced by EggSliderData::add_back_pointer(), XFileNode::add_child(), EggGroupNode::apply_first_attribute(), EggGroupNode::apply_last_attribute(), DeferredNodeProperty::apply_to_node(), EggGroupNode::clear_connected_shading(), EggBase::convert_paths(), VirtualFileSimple::copy_file(), GeomTextGlyph::count_geom(), XFile::find_data_object(), XFile::find_template(), EggMaterialCollection::find_used_materials(), EggTextureCollection::find_used_textures(), EggGroupNode::force_filenames(), WindowFramework::get_aspect_2d(), EggGroupUniquifier::get_category(), EggPoolUniquifier::get_category(), EggGroupNode::get_connected_shading(), get_textures_by_filename(), EggGroupNode::has_absolute_pathnames(), PandaFramework::hide_collision_solids(), EggNode::parse_egg(), EggGroupNode::post_apply_flat_attribute(), EggBinner::prepare_node(), PortalClipper::prepare_portal(), PT(), EggMatrixTablePointer::quantize_channels(), ParametricCurveCollection::r_add_curves(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::remove_invalid_primitives(), EggGroupNode::remove_unused_vertices(), VirtualFileSimple::rename_file(), EggMaterialCollection::replace_materials(), EggTextureCollection::replace_textures(), EggGroupNode::reverse_vertex_ordering(), PandaFramework::show_collision_solids(), EggGroupNode::strip_normals(), DataGraphTraverser::traverse(), EggGroupNode::triangulate_polygons(), EggGroupNode::unify_attributes(), EggNameUniquifier::uniquify(), NodeCullCallbackData::upcall(), and EggToDXFLayer::write_entities().


The documentation for this class was generated from the following files: