Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Factory< Type > Class Template Reference

#include <Factory.h>

Inheritance diagram for Factory< Type >:

Inheritance graph
[legend]
Collaboration diagram for Factory< Type >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class Type>
class Factory< Type >

The base class for singleton factory classes.

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.

Author:
Paul F. Kunz <Paul_Kunz@slac.stanford.edu>

Definition at line 41 of file Factory.h.

Public Member Functions

void add (Type *)
 Adds a prototype object to the list of prototypes.
Typecreate (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 ()
 Returns the list of available prototype names.
Typeprototype (const std::string &name) const
 Returns a pointer to a prototype with name name.

Protected Member Functions

 Factory ()
 The default constructor.
virtual ~Factory ()
 The destructor.

Protected Attributes

std::vector< std::stringm_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.


Constructor & Destructor Documentation

template<class Type>
Factory< Type >::Factory const Factory< Type > &   )  [private]
 

A private copy constructor to prevent copying.

template<class Type>
Factory< Type >::Factory  )  [protected]
 

The default constructor.

Since this constructor is protected, only derived classes of Factory can be created.

Definition at line 93 of file Factory.h.

template<class Type>
Factory< Type >::~Factory  )  [protected, virtual]
 

The destructor.

It is responsible for deleting the prototype objects.

Definition at line 98 of file Factory.h.

References Factory< Type >::m_types.


Member Function Documentation

template<class Type>
void Factory< Type >::add Type  ) 
 

Adds a prototype object to the list of prototypes.

Definition at line 110 of file Factory.h.

References Factory< Type >::m_types.

template<class Type>
Type * Factory< Type >::create const std::string name  ) 
 

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 142 of file Factory.h.

References Factory< Type >::prototype().

Referenced by CutController::createCut(), DataRepController::createDataRep(), PointRepXML::createObject(), BinsBaseXML::createObject(), BinnerAxisXML::createObject(), PlotterBaseXML::createPlotter(), DisplayController::createTextDataRep(), FunctionProjector::FunctionProjector(), Hist1DProjImp::Hist1DProjImp(), Hist2DProjImp::Hist2DProjImp(), and Profile2DProjector::Profile2DProjector().

template<class Type>
bool Factory< Type >::exists const std::string name  )  const
 

Returns true if prototype with name name exists in the factory, otherwise returns false.

Definition at line 118 of file Factory.h.

template<class Type>
const std::vector< std::string > & Factory< Type >::names  ) 
 

Returns the list of available prototype names.

Definition at line 153 of file Factory.h.

References Factory< Type >::m_names, and Factory< Type >::m_types.

Referenced by DisplayController::getTextTypes().

template<class Type>
Type * Factory< Type >::prototype const std::string name  )  const
 

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 130 of file Factory.h.

References Factory< Type >::m_types.

Referenced by DataRepController::bindingOptions(), Factory< Type >::create(), DisplayController::createDisplay(), and DisplayController::isCompatible().


Member Data Documentation

template<class Type>
std::vector< std::string > Factory< Type >::m_names [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 56 of file Factory.h.

Referenced by Factory< Type >::names().

template<class Type>
std::map< std::string, Type * > Factory< Type >::m_types [protected]
 

A list of available types.

Definition at line 51 of file Factory.h.

Referenced by Factory< Type >::add(), Factory< Type >::names(), Factory< Type >::prototype(), and Factory< Type >::~Factory().


The documentation for this class was generated from the following file:
Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3