Panda3D
Public Types | Public Member Functions | List of all members
Factory< Type > Class Template Reference

A Factory can be used to create an instance of a particular subclass of some general base class. More...

#include "factory.h"

Inheritance diagram for Factory< Type >:
FactoryBase

Public Types

typedef Type * CreateFunc(const FactoryParams &params)
 
- Public Types inherited from FactoryBase
typedef TypedObjectBaseCreateFunc(const FactoryParams &params)
 

Public Member Functions

Type * make_instance (TypeHandle handle, const FactoryParams &params=FactoryParams())
 Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. More...
 
Type * make_instance (const std::string &type_name, const FactoryParams &params=FactoryParams())
 Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. More...
 
Type * make_instance_more_general (TypeHandle handle, const FactoryParams &params=FactoryParams())
 Attempts to create an instance of the type requested, or some base type of the type requested. More...
 
Type * make_instance_more_general (const std::string &type_name, const FactoryParams &params=FactoryParams())
 Attempts to create an instance of the type requested, or some base type of the type requested. More...
 
void register_factory (TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
 Registers a new kind of thing the Factory will be able to create. More...
 
- Public Member Functions inherited from FactoryBase
 FactoryBase (const FactoryBase &copy)=delete
 
void add_preferred (TypeHandle handle)
 Adds the indicated type to the end of the list of preferred types. More...
 
void clear_preferred ()
 Empties the list of preferred types. More...
 
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. More...
 
size_t get_num_preferred () const
 Returns the number of types added to the preferred-type list. More...
 
size_t get_num_types () const
 Returns the number of different types the Factory knows how to create. More...
 
TypeHandle get_preferred (size_t n) const
 Returns the nth type added to the preferred-type list. More...
 
TypeHandle get_type (size_t n) const
 Returns the nth type the Factory knows how to create. More...
 
TypedObjectmake_instance (TypeHandle handle, const FactoryParams &params)
 Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. More...
 
TypedObjectmake_instance (const std::string &type_name, const FactoryParams &params)
 Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. More...
 
TypedObjectmake_instance_more_general (TypeHandle handle, const FactoryParams &params)
 Attempts to create an instance of the type requested, or some base type of the type requested. More...
 
TypedObjectmake_instance_more_general (const std::string &type_name, const FactoryParams &params)
 Attempts to create an instance of the type requested, or some base type of the type requested. More...
 
FactoryBaseoperator= (const FactoryBase &copy)=delete
 
void register_factory (TypeHandle handle, BaseCreateFunc *func, void *user_data=nullptr)
 Registers a new kind of thing the Factory will be able to create. More...
 
void write_types (std::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. More...
 

Detailed Description

template<class Type>
class Factory< Type >

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.

Definition at line 34 of file factory.h.

Member Function Documentation

◆ make_instance() [1/2]

template<class Type >
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.

Definition at line 22 of file factory.I.

References FactoryBase::make_instance().

◆ make_instance() [2/2]

template<class Type >
Type * Factory< Type >::make_instance ( const std::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.

Definition at line 37 of file factory.I.

References FactoryBase::make_instance().

◆ make_instance_more_general() [1/2]

template<class Type >
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.

Definition at line 48 of file factory.I.

References FactoryBase::make_instance_more_general().

◆ make_instance_more_general() [2/2]

template<class Type >
Type * Factory< Type >::make_instance_more_general ( const std::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.

Definition at line 63 of file factory.I.

References FactoryBase::make_instance_more_general().

◆ register_factory()

template<class Type >
void Factory< Type >::register_factory ( TypeHandle  handle,
CreateFunc *  func,
void *  user_data = nullptr 
)
inline

Registers a new kind of thing the Factory will be able to create.

Definition at line 73 of file factory.I.

References FactoryBase::register_factory().

Referenced by BamReader::register_factory(), DecalEffect::register_with_read_factory(), FfmpegVideo::register_with_read_factory(), ParamNodePath::register_with_read_factory(), RecorderHeader::register_with_read_factory(), CharacterVertexSlider::register_with_read_factory(), CollisionLine::register_with_read_factory(), ShowBoundsEffect::register_with_read_factory(), MovingPartScalar::register_with_read_factory(), AmbientLight::register_with_read_factory(), ParamTextureSampler::register_with_read_factory(), MovingPartMatrix::register_with_read_factory(), BulletConvexHullShape::register_with_read_factory(), CharacterJointBundle::register_with_read_factory(), CharacterSlider::register_with_read_factory(), PerspectiveLens::register_with_read_factory(), AnimChannelMatrixFixed::register_with_read_factory(), GeomTristripsAdjacency::register_with_read_factory(), BulletConvexPointCloudShape::register_with_read_factory(), OrthographicLens::register_with_read_factory(), SequenceNode::register_with_read_factory(), AnimBundleNode::register_with_read_factory(), BulletConeShape::register_with_read_factory(), BulletSphereShape::register_with_read_factory(), GeomLinestripsAdjacency::register_with_read_factory(), RecorderFrame::register_with_read_factory(), JointVertexTransform::register_with_read_factory(), GeomTextGlyph::register_with_read_factory(), DataNodeTransmit::register_with_read_factory(), GeomLinestrips::register_with_read_factory(), BulletHeightfieldShape::register_with_read_factory(), BulletMultiSphereShape::register_with_read_factory(), BulletCylinderShape::register_with_read_factory(), ButtonEventList::register_with_read_factory(), BulletBoxShape::register_with_read_factory(), GeomTristrips::register_with_read_factory(), AnimBundle::register_with_read_factory(), BulletPlaneShape::register_with_read_factory(), BulletCapsuleShape::register_with_read_factory(), AnimChannelScalarTable::register_with_read_factory(), DepthTestAttrib::register_with_read_factory(), UserVertexSlider::register_with_read_factory(), FogAttrib::register_with_read_factory(), BamCacheIndex::register_with_read_factory(), RecorderTable::register_with_read_factory(), MaterialAttrib::register_with_read_factory(), CullBinAttrib::register_with_read_factory(), AlphaTestAttrib::register_with_read_factory(), BulletTriangleMeshShape::register_with_read_factory(), UvScrollNode::register_with_read_factory(), UserVertexTransform::register_with_read_factory(), ColorWriteAttrib::register_with_read_factory(), DepthWriteAttrib::register_with_read_factory(), ModelRoot::register_with_read_factory(), CollisionInvSphere::register_with_read_factory(), SwitchNode::register_with_read_factory(), SphereLight::register_with_read_factory(), CharacterJointEffect::register_with_read_factory(), FadeLODNode::register_with_read_factory(), AnimChannelScalarDynamic::register_with_read_factory(), MatrixLens::register_with_read_factory(), CollisionRay::register_with_read_factory(), AnimGroup::register_with_read_factory(), ModelNode::register_with_read_factory(), RectangleLight::register_with_read_factory(), AnimPreloadTable::register_with_read_factory(), CallbackNode::register_with_read_factory(), ShaderBuffer::register_with_read_factory(), LensNode::register_with_read_factory(), ColorAttrib::register_with_read_factory(), AnimChannelMatrixDynamic::register_with_read_factory(), TransparencyAttrib::register_with_read_factory(), MouseRecorder::register_with_read_factory(), AnimChannelMatrixXfmTable::register_with_read_factory(), CollisionSegment::register_with_read_factory(), RescaleNormalAttrib::register_with_read_factory(), ColorScaleAttrib::register_with_read_factory(), CollisionParabola::register_with_read_factory(), LightRampAttrib::register_with_read_factory(), LogicOpAttrib::register_with_read_factory(), OccluderNode::register_with_read_factory(), DirectionalLight::register_with_read_factory(), BulletTriangleMesh::register_with_read_factory(), CharacterJoint::register_with_read_factory(), CollisionPlane::register_with_read_factory(), AuxBitplaneAttrib::register_with_read_factory(), CompassEffect::register_with_read_factory(), PointLight::register_with_read_factory(), ComputeNode::register_with_read_factory(), TransformTable::register_with_read_factory(), Fog::register_with_read_factory(), CollisionSphere::register_with_read_factory(), CollisionFloorMesh::register_with_read_factory(), CollisionNode::register_with_read_factory(), SheetNode::register_with_read_factory(), Spotlight::register_with_read_factory(), SliderTable::register_with_read_factory(), PlaneNode::register_with_read_factory(), NurbsCurve::register_with_read_factory(), CubicCurveseg::register_with_read_factory(), ParamTextureImage::register_with_read_factory(), BamCacheRecord::register_with_read_factory(), PartGroup::register_with_read_factory(), TexGenAttrib::register_with_read_factory(), PolylightNode::register_with_read_factory(), ParamValue< Type >::register_with_read_factory(), BulletDebugNode::register_with_read_factory(), TransformBlendTable::register_with_read_factory(), Camera::register_with_read_factory(), CollisionCapsule::register_with_read_factory(), PortalNode::register_with_read_factory(), ClipPlaneAttrib::register_with_read_factory(), ColorBlendAttrib::register_with_read_factory(), InternalName::register_with_read_factory(), CollisionPolygon::register_with_read_factory(), LightAttrib::register_with_read_factory(), BulletRigidBodyNode::register_with_read_factory(), Character::register_with_read_factory(), HermiteCurve::register_with_read_factory(), CollisionBox::register_with_read_factory(), StencilAttrib::register_with_read_factory(), GeomVertexArrayFormat::register_with_read_factory(), Material::register_with_read_factory(), RenderEffects::register_with_read_factory(), FfmpegVideoCursor::register_with_read_factory(), GeomNode::register_with_read_factory(), LODNode::register_with_read_factory(), GeomVertexArrayData::register_with_read_factory(), PartBundle::register_with_read_factory(), RopeNode::register_with_read_factory(), TextureStage::register_with_read_factory(), GeomVertexFormat::register_with_read_factory(), SpeedTreeNode::register_with_read_factory(), RenderState::register_with_read_factory(), Geom::register_with_read_factory(), GeomVertexData::register_with_read_factory(), Shader::register_with_read_factory(), PandaNode::register_with_read_factory(), and Texture::register_with_read_factory().


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