Panda3D
|
A Factory can be used to create an instance of a particular subclass of some general base class. More...
#include "factory.h"
Public Types | |
typedef TypedObject * | BaseCreateFunc (const FactoryParams ¶ms) |
typedef Type * | CreateFunc (const FactoryParams ¶ms) |
Public Member Functions | |
void | add_preferred (TypeHandle handle) |
Adds the indicated type to the end of the list of preferred types. | |
void | clear_preferred () |
Empties the list of preferred types. | |
TypeHandle | find_registered_type (TypeHandle handle) |
Returns the TypeHandle given, if it is a registered type, or if it is not registered, searches for the nearest ancestor of the indicated type that is registered and returns it. | |
int | get_num_preferred () const |
Returns the number of types added to the preferred-type list. | |
int | get_num_types () const |
Returns the number of different types the Factory knows how to create. | |
TypeHandle | get_preferred (int n) const |
Returns the nth type added to the preferred-type list. | |
TypeHandle | get_type (int n) const |
Returns the nth type the Factory knows how to create. | |
Type * | make_instance (const string &type_name, const FactoryParams ¶ms=FactoryParams()) |
Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. | |
Type * | make_instance (TypeHandle handle, const FactoryParams ¶ms=FactoryParams()) |
Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. | |
Type * | make_instance_more_general (const string &type_name, const FactoryParams ¶ms=FactoryParams()) |
Attempts to create an instance of the type requested, or some base type of the type requested. | |
Type * | make_instance_more_general (TypeHandle handle, const FactoryParams ¶ms=FactoryParams()) |
Attempts to create an instance of the type requested, or some base type of the type requested. | |
void | register_factory (TypeHandle handle, BaseCreateFunc *func) |
Registers a new kind of thing the Factory will be able to create. | |
void | register_factory (TypeHandle handle, CreateFunc *func) |
Registers a new kind of thing the Factory will be able to create. | |
void | write_types (ostream &out, int indent_level=0) const |
Writes a list of all known types the Factory can create to the indicated output stream, one per line. |
A Factory can be used to create an instance of a particular subclass of some general base class.
Each subclass registers itself with the Factory, supplying a function that will construct an instance of that subclass; the Factory can later choose a suitable subclass and return a newly-constructed pointer to an object of that type on the user's demand. This is used, for instance, to manage the set of GraphicsPipes available to the user.
This is a thin template wrapper around FactoryBase. All it does is ensure the types are correctly cast. All of its methods are inline, and it has no data members, so it is not necessary to export the class from the DLL.
void FactoryBase::add_preferred | ( | TypeHandle | handle | ) | [inherited] |
Adds the indicated type to the end of the list of preferred types.
On the next call to make_instance(), if the exact type requested cannot be created, the preferred types are first tried in the order specified.
Definition at line 213 of file factoryBase.cxx.
References TypeHandle::none().
void FactoryBase::clear_preferred | ( | ) | [inherited] |
Empties the list of preferred types.
Definition at line 199 of file factoryBase.cxx.
TypeHandle FactoryBase::find_registered_type | ( | TypeHandle | handle | ) | [inherited] |
Returns the TypeHandle given, if it is a registered type, or if it is not registered, searches for the nearest ancestor of the indicated type that is registered and returns it.
If no ancestor of the indicated type is registered, returns TypeHandle::none().
Definition at line 119 of file factoryBase.cxx.
References TypeHandle::get_num_parent_classes(), TypeHandle::get_parent_class(), and TypeHandle::none().
int FactoryBase::get_num_preferred | ( | ) | const [inherited] |
Returns the number of types added to the preferred-type list.
Definition at line 225 of file factoryBase.cxx.
Referenced by FactoryBase::get_preferred().
int FactoryBase::get_num_types | ( | ) | const [inherited] |
Returns the number of different types the Factory knows how to create.
Definition at line 164 of file factoryBase.cxx.
Referenced by FactoryBase::get_type().
TypeHandle FactoryBase::get_preferred | ( | int | n | ) | const [inherited] |
Returns the nth type added to the preferred-type list.
Definition at line 236 of file factoryBase.cxx.
References FactoryBase::get_num_preferred(), and TypeHandle::none().
TypeHandle FactoryBase::get_type | ( | int | n | ) | const [inherited] |
Returns the nth type the Factory knows how to create.
This is not a terribly efficient function; it's included primarily for debugging output. Normally you wouldn't need to traverse the list of the Factory's types.
Definition at line 178 of file factoryBase.cxx.
References FactoryBase::get_num_types(), and TypeHandle::none().
Type * Factory< Type >::make_instance | ( | const string & | type_name, |
const FactoryParams & | params = FactoryParams() |
||
) | [inline] |
Attempts to create a new instance of some class of the indicated type, or some derivative if necessary.
If an instance of the exact type cannot be created, the specified preferred will specify which derived class will be preferred.
This flavor of make_instance() accepts a string name that indicates the desired type. It must be the name of some already-registered type.
Reimplemented from FactoryBase.
Definition at line 45 of file factory.I.
References FactoryBase::make_instance().
Type * Factory< Type >::make_instance | ( | TypeHandle | handle, |
const FactoryParams & | params = FactoryParams() |
||
) | [inline] |
Attempts to create a new instance of some class of the indicated type, or some derivative if necessary.
If an instance of the exact type cannot be created, the specified preferred will specify which derived class will be preferred.
Reimplemented from FactoryBase.
Definition at line 26 of file factory.I.
References FactoryBase::make_instance().
Type * Factory< Type >::make_instance_more_general | ( | const string & | type_name, |
const FactoryParams & | params = FactoryParams() |
||
) | [inline] |
Attempts to create an instance of the type requested, or some base type of the type requested.
Returns the new instance created, or NULL if the instance could not be created.
This flavor of make_instance_more_general() accepts a string name that indicates the desired type. It must be the name of some already-registered type.
Reimplemented from FactoryBase.
Definition at line 77 of file factory.I.
References FactoryBase::make_instance_more_general().
Type * Factory< Type >::make_instance_more_general | ( | TypeHandle | handle, |
const FactoryParams & | params = FactoryParams() |
||
) | [inline] |
Attempts to create an instance of the type requested, or some base type of the type requested.
Returns the new instance created, or NULL if the instance could not be created.
Reimplemented from FactoryBase.
Definition at line 59 of file factory.I.
References FactoryBase::make_instance_more_general().
void FactoryBase::register_factory | ( | TypeHandle | handle, |
BaseCreateFunc * | func | ||
) | [inherited] |
Registers a new kind of thing the Factory will be able to create.
Definition at line 151 of file factoryBase.cxx.
References TypeHandle::none().
Referenced by Factory< Type >::register_factory().
void Factory< Type >::register_factory | ( | TypeHandle | handle, |
CreateFunc * | func | ||
) | [inline] |
Registers a new kind of thing the Factory will be able to create.
Definition at line 90 of file factory.I.
References FactoryBase::register_factory().
Referenced by RecorderTable::register_with_read_factory(), RecorderHeader::register_with_read_factory(), RecorderFrame::register_with_read_factory(), MouseRecorder::register_with_read_factory(), BamCacheRecord::register_with_read_factory(), BamCacheIndex::register_with_read_factory(), SwitchNode::register_with_read_factory(), Spotlight::register_with_read_factory(), SequenceNode::register_with_read_factory(), PointLight::register_with_read_factory(), LODNode::register_with_read_factory(), FadeLODNode::register_with_read_factory(), DirectionalLight::register_with_read_factory(), CallbackNode::register_with_read_factory(), AmbientLight::register_with_read_factory(), UvScrollNode::register_with_read_factory(), TransparencyAttrib::register_with_read_factory(), TransformState::register_with_read_factory(), TextureAttrib::register_with_read_factory(), TexProjectorEffect::register_with_read_factory(), TexMatrixAttrib::register_with_read_factory(), TexGenAttrib::register_with_read_factory(), StencilAttrib::register_with_read_factory(), ShowBoundsEffect::register_with_read_factory(), ShadeModelAttrib::register_with_read_factory(), ScissorEffect::register_with_read_factory(), ScissorAttrib::register_with_read_factory(), RescaleNormalAttrib::register_with_read_factory(), RenderState::register_with_read_factory(), RenderModeAttrib::register_with_read_factory(), RenderEffects::register_with_read_factory(), PortalNode::register_with_read_factory(), PolylightNode::register_with_read_factory(), PlaneNode::register_with_read_factory(), PandaNode::register_with_read_factory(), ModelRoot::register_with_read_factory(), ModelNode::register_with_read_factory(), MaterialAttrib::register_with_read_factory(), LightRampAttrib::register_with_read_factory(), LightAttrib::register_with_read_factory(), LensNode::register_with_read_factory(), GeomNode::register_with_read_factory(), FogAttrib::register_with_read_factory(), Fog::register_with_read_factory(), DepthWriteAttrib::register_with_read_factory(), DepthTestAttrib::register_with_read_factory(), DepthOffsetAttrib::register_with_read_factory(), DecalEffect::register_with_read_factory(), CullFaceAttrib::register_with_read_factory(), CullBinAttrib::register_with_read_factory(), CompassEffect::register_with_read_factory(), ColorWriteAttrib::register_with_read_factory(), ColorScaleAttrib::register_with_read_factory(), ColorBlendAttrib::register_with_read_factory(), ColorAttrib::register_with_read_factory(), ClipPlaneAttrib::register_with_read_factory(), Camera::register_with_read_factory(), BillboardEffect::register_with_read_factory(), AuxBitplaneAttrib::register_with_read_factory(), AudioVolumeAttrib::register_with_read_factory(), AntialiasAttrib::register_with_read_factory(), AlphaTestAttrib::register_with_read_factory(), SheetNode::register_with_read_factory(), RopeNode::register_with_read_factory(), NurbsCurve::register_with_read_factory(), HermiteCurve::register_with_read_factory(), CubicCurveseg::register_with_read_factory(), UserVertexTransform::register_with_read_factory(), UserVertexSlider::register_with_read_factory(), TransformTable::register_with_read_factory(), TransformBlendTable::register_with_read_factory(), TextureStage::register_with_read_factory(), Texture::register_with_read_factory(), SliderTable::register_with_read_factory(), PerspectiveLens::register_with_read_factory(), OrthographicLens::register_with_read_factory(), MatrixLens::register_with_read_factory(), Material::register_with_read_factory(), InternalName::register_with_read_factory(), GeomVertexFormat::register_with_read_factory(), GeomVertexData::register_with_read_factory(), GeomVertexArrayFormat::register_with_read_factory(), GeomVertexArrayData::register_with_read_factory(), GeomTristrips::register_with_read_factory(), GeomTrifans::register_with_read_factory(), GeomTriangles::register_with_read_factory(), GeomPoints::register_with_read_factory(), GeomLinestrips::register_with_read_factory(), GeomLines::register_with_read_factory(), Geom::register_with_read_factory(), EventStoreValue< Type >::register_with_read_factory(), ButtonEventList::register_with_read_factory(), DataNodeTransmit::register_with_read_factory(), CollisionTube::register_with_read_factory(), CollisionSphere::register_with_read_factory(), CollisionSegment::register_with_read_factory(), CollisionRay::register_with_read_factory(), CollisionPolygon::register_with_read_factory(), CollisionPlane::register_with_read_factory(), CollisionParabola::register_with_read_factory(), CollisionNode::register_with_read_factory(), CollisionLine::register_with_read_factory(), CollisionInvSphere::register_with_read_factory(), CollisionFloorMesh::register_with_read_factory(), CollisionDSSolid::register_with_read_factory(), CollisionBox::register_with_read_factory(), JointVertexTransform::register_with_read_factory(), CharacterVertexSlider::register_with_read_factory(), CharacterSlider::register_with_read_factory(), CharacterJointEffect::register_with_read_factory(), CharacterJointBundle::register_with_read_factory(), CharacterJoint::register_with_read_factory(), Character::register_with_read_factory(), PartGroup::register_with_read_factory(), PartBundle::register_with_read_factory(), MovingPartScalar::register_with_read_factory(), MovingPartMatrix::register_with_read_factory(), AnimPreloadTable::register_with_read_factory(), AnimGroup::register_with_read_factory(), AnimChannelScalarTable::register_with_read_factory(), AnimChannelScalarDynamic::register_with_read_factory(), AnimChannelMatrixXfmTable::register_with_read_factory(), AnimChannelMatrixFixed::register_with_read_factory(), AnimChannelMatrixDynamic::register_with_read_factory(), AnimBundleNode::register_with_read_factory(), AnimBundle::register_with_read_factory(), and CFDoCullCommand::register_with_read_factory().
void FactoryBase::write_types | ( | ostream & | out, |
int | indent_level = 0 |
||
) | const [inherited] |
Writes a list of all known types the Factory can create to the indicated output stream, one per line.
Definition at line 248 of file factoryBase.cxx.