#include <Factory.h>
Inheritance diagram for Factory:
The factory maintains an instance of each type that can be produced by the factory. This instance is called the prototype. There are two requirements on the type that can be handled by the factory. First that it has a member function name()
that returns a std::string
for its name. The name does not have to be the class name. And second that it has a member function clone
() to make a copy of itself.
In most cases, a derived class of Factory need only supply the a way to initialize list of prototypes. Most of the implementation is in this template class.
Definition at line 43 of file Factory.h.
Public Member Functions | |
void | add (Type *) |
Adds a prototype object to the list of prototypes. | |
Type * | create (const std::string &name) |
Creates a new object from a prototype named name. | |
bool | exists (const std::string &name) const |
Returns true if prototype with name name exists in the factory, otherwise returns false. | |
const std::vector< std::string > & | names () const |
Returns the list of available prototype names. | |
Type * | prototype (const std::string &name) const |
Returns a pointer to a prototype with name name. | |
void | remove (const std::string &name) |
Removes the named prototype object from the list of prototypes. | |
Protected Member Functions | |
Factory () | |
The default constructor. | |
virtual | ~Factory () |
The destructor. | |
Protected Attributes | |
std::vector< std::string > | m_names |
The list of available types by names. | |
std::map< std::string, Type * > | m_types |
A list of available types. | |
Private Member Functions | |
Factory (const Factory< Type > &) | |
A private copy constructor to prevent copying. |
Factory | ( | ) | [inline, protected] |
~Factory | ( | ) | [inline, protected, virtual] |
void add | ( | Type * | ) | [inline] |
Adds a prototype object to the list of prototypes.
Definition at line 116 of file Factory.h.
References Factory::m_types.
Type * create | ( | const std::string & | name | ) | [inline] |
Creates a new object from a prototype named name.
If found, returns a new object by invoking the clone() member function of the prototype. If not found, throws a FactoryException object with the name not found.
Definition at line 160 of file Factory.h.
References Factory::prototype().
Referenced by CutController::createCut(), DataRepController::createDataRep(), PointRepXML::createObject(), BinsBaseXML::createObject(), BinnerAxisXML::createObject(), PlotterBaseXML::createPlotter(), DisplayController::createTextDataRep(), Hist1DProjImp::Hist1DProjImp(), Hist2DProjImp::Hist2DProjImp(), and Profile2DProjector::Profile2DProjector().
bool exists | ( | const std::string & | name | ) | const [inline] |
const std::vector< std::string > & names | ( | ) | const [inline] |
Returns the list of available prototype names.
Definition at line 170 of file Factory.h.
References Factory::m_names, and Factory::m_types.
Referenced by DisplayController::getTextTypes().
Type * prototype | ( | const std::string & | name | ) | const [inline] |
Returns a pointer to a prototype with name name.
If a prototype with name doesn't exit, throws a FactoryException object with the name not found.
Definition at line 148 of file Factory.h.
References Factory::m_types.
Referenced by DataRepController::bindingOptions(), Factory::create(), DisplayController::createDisplay(), and DisplayController::isCompatible().
void remove | ( | const std::string & | name | ) | [inline] |
std::vector< std::string > m_names [mutable, protected] |
The list of available types by names.
This list should be identical to the list of m_types
keys. It is updated when the member function names is called.
Definition at line 58 of file Factory.h.
Referenced by Factory::names().
std::map< std::string, Type * > m_types [protected] |
A list of available types.
Definition at line 53 of file Factory.h.
Referenced by Factory::add(), Factory::names(), and Factory::prototype().