#include <factoryBase.h>
Inheritance diagram for FactoryBase:
Public Types | |
typedef TypedObject * | BaseCreateFunc (const FactoryParams ¶ms) |
Public Member Functions | |
FactoryBase () | |
~FactoryBase () | |
TypedObject * | make_instance (TypeHandle handle, const FactoryParams ¶ms) |
Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. | |
TypedObject * | make_instance (const string &type_name, const FactoryParams ¶ms) |
Attempts to create a new instance of some class of the indicated type, or some derivative if necessary. | |
TypedObject * | make_instance_more_general (TypeHandle handle, const FactoryParams ¶ms) |
Attempts to create an instance of the type requested, or some base type of the type requested. | |
TypedObject * | make_instance_more_general (const string &type_name, const FactoryParams ¶ms) |
Attempts to create an instance of the type requested, or some base type of the type requested. | |
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. | |
void | register_factory (TypeHandle handle, BaseCreateFunc *func) |
Registers a new kind of thing the Factory will be able to create. | |
int | get_num_types () const |
Returns the number of different types the Factory knows how to create. | |
TypeHandle | get_type (int n) const |
Returns the nth type the Factory knows how to create. | |
void | clear_preferred () |
Empties the list of preferred types. | |
void | add_preferred (TypeHandle handle) |
Adds the indicated type to the end of the list of preferred types. | |
int | get_num_preferred () const |
Returns the number of types added to the preferred-type list. | |
TypeHandle | get_preferred (int n) const |
Returns the nth type added to the preferred-type list. | |
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. | |
Private Types | |
typedef pmap< TypeHandle, BaseCreateFunc * > | Creators |
typedef pvector< TypeHandle > | Preferred |
Private Member Functions | |
FactoryBase (const FactoryBase ©) | |
Don't copy Factories. | |
void | operator= (const FactoryBase ©) |
Don't copy Factories. | |
TypedObject * | make_instance_exact (TypeHandle handle, const FactoryParams ¶ms) |
Attempts to create an instance of the exact type requested by the given handle. | |
TypedObject * | make_instance_more_specific (TypeHandle handle, const FactoryParams ¶ms) |
Attempts to create an instance of some derived type of the type requested by the given handle. | |
Private Attributes | |
Creators | _creators |
Preferred | _preferred |
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.
FactoryBase is the main definition of the thin template class Factory.
Definition at line 62 of file factoryBase.h.
|
Definition at line 64 of file factoryBase.h. |
|
Definition at line 116 of file factoryBase.h. |
|
Definition at line 121 of file factoryBase.h. |
|
Definition at line 34 of file factoryBase.cxx. |
|
Definition at line 45 of file factoryBase.cxx. References make_instance_exact(), make_instance_more_specific(), and NULL. |
|
Don't copy Factories.
Definition at line 334 of file factoryBase.cxx. |
|
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 270 of file factoryBase.cxx. |
|
Empties the list of preferred types.
Definition at line 249 of file factoryBase.cxx. |
|
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 151 of file factoryBase.cxx. References _creators, nassertv, TypeHandle::none(), and NULL. |
|
Returns the number of types added to the preferred-type list.
Definition at line 286 of file factoryBase.cxx. |
|
Returns the number of different types the Factory knows how to create.
Definition at line 204 of file factoryBase.cxx. References _preferred. |
|
Returns the nth type added to the preferred-type list.
Definition at line 301 of file factoryBase.cxx. References _preferred, TypeHandle::is_derived_from(), make_instance_exact(), and NULL. |
|
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 225 of file factoryBase.cxx. References _preferred. |
|
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 priorities 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 in Factory< Type >, and Factory< TypedWritable >. Definition at line 48 of file factoryBase.I. References TypeRegistry::find_type(), INLINE, make_instance_more_general(), nassertr, TypeHandle::none(), NULL, and TypeRegistry::ptr(). |
|
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 in Factory< Type >, and Factory< TypedWritable >. Definition at line 65 of file factoryBase.cxx. Referenced by Factory< Type >::make_instance(). |
|
Attempts to create an instance of the exact type requested by the given handle. Returns the new instance created, or NULL if the instance could not be created. Definition at line 364 of file factoryBase.cxx. Referenced by get_preferred(), and ~FactoryBase(). |
|
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 in Factory< Type >, and Factory< TypedWritable >. Definition at line 79 of file factoryBase.I. |
|
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 in Factory< Type >, and Factory< TypedWritable >. Definition at line 102 of file factoryBase.cxx. References TypedObject::get_type(), and NULL. Referenced by make_instance(), and Factory< Type >::make_instance(). |
|
Attempts to create an instance of some derived type of the type requested by the given handle. Returns the new instance created, or NULL if the instance could not be created. Definition at line 390 of file factoryBase.cxx. Referenced by ~FactoryBase(). |
|
Don't copy Factories.
Definition at line 346 of file factoryBase.cxx. |
|
Registers a new kind of thing the Factory will be able to create.
Definition at line 187 of file factoryBase.cxx. Referenced by Factory< Type >::make_instance_more_general(). |
|
Writes a list of all known types the Factory can create to the indicated output stream, one per line.
Definition at line 317 of file factoryBase.cxx. |
|
Definition at line 119 of file factoryBase.h. Referenced by clear_preferred(), find_registered_type(), and get_num_preferred(). |
|
Definition at line 122 of file factoryBase.h. Referenced by get_num_types(), get_preferred(), and get_type(). |