Frobby  0.9.5
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
NameFactory< AbstractProduct > Class Template Reference

A NameFactory takes a name and then creates an instance of a class that has been previously registered under that name. More...

#include <NameFactory.h>

Public Types

typedef auto_ptr< AbstractProduct >(* FactoryFunction) ()
 

Public Member Functions

 NameFactory (const char *abstractName)
 
void registerProduct (const string &name, FactoryFunction function)
 
auto_ptr< AbstractProduct > createNoThrow (const string &name) const
 Calls the function registered to the parameter name and returns the result. More...
 
auto_ptr< AbstractProduct > create (const string &name) const
 Calls the function registered to the parameter name and returns the result. More...
 
void getNamesWithPrefix (const string &prefix, vector< string > &names) const
 Inserts into names all registered names that have the indicated prefix in lexicographic increasing order. More...
 
bool empty () const
 Returns true if no names have been registered. More...
 
string getAbstractProductName () const
 

Private Types

typedef pair< string, FactoryFunctionPair
 
typedef vector< Pair >::const_iterator const_iterator
 

Private Attributes

vector< Pair_pairs
 
const string _abstractName
 

Detailed Description

template<class AbstractProduct>
class NameFactory< AbstractProduct >

A NameFactory takes a name and then creates an instance of a class that has been previously registered under that name.

This is done in a general way using templates.

None of this is very efficient. However, the interface can be implemented much more efficiently if that becomes necessary.

Definition at line 33 of file NameFactory.h.

Member Typedef Documentation

◆ const_iterator

template<class AbstractProduct >
typedef vector<Pair>::const_iterator NameFactory< AbstractProduct >::const_iterator
private

Definition at line 62 of file NameFactory.h.

◆ FactoryFunction

template<class AbstractProduct >
typedef auto_ptr<AbstractProduct>(* NameFactory< AbstractProduct >::FactoryFunction) ()

Definition at line 39 of file NameFactory.h.

◆ Pair

template<class AbstractProduct >
typedef pair<string, FactoryFunction> NameFactory< AbstractProduct >::Pair
private

Definition at line 61 of file NameFactory.h.

Constructor & Destructor Documentation

◆ NameFactory()

template<class AbstractProduct >
NameFactory< AbstractProduct >::NameFactory ( const char *  abstractName)
inline
Parameters
abstractNameThe name for those things that are being generated in general. Used for error messages.

Definition at line 37 of file NameFactory.h.

Member Function Documentation

◆ create()

template<class AbstractProduct >
auto_ptr< AbstractProduct > NameFactory< AbstractProduct >::create ( const string &  name) const

Calls the function registered to the parameter name and returns the result.

Throws an exception if name has not been registered.

Definition at line 107 of file NameFactory.h.

◆ createNoThrow()

template<class AbstractProduct >
auto_ptr< AbstractProduct > NameFactory< AbstractProduct >::createNoThrow ( const string &  name) const

Calls the function registered to the parameter name and returns the result.

Returns null if name has not been registered. Can still throw an exception for example if out of memory.

Definition at line 98 of file NameFactory.h.

◆ empty()

template<class AbstractProduct >
bool NameFactory< AbstractProduct >::empty

Returns true if no names have been registered.

Definition at line 132 of file NameFactory.h.

◆ getAbstractProductName()

template<class AbstractProduct >
string NameFactory< AbstractProduct >::getAbstractProductName

Definition at line 137 of file NameFactory.h.

◆ getNamesWithPrefix()

template<class AbstractProduct >
void NameFactory< AbstractProduct >::getNamesWithPrefix ( const string &  prefix,
vector< string > &  names 
) const

Inserts into names all registered names that have the indicated prefix in lexicographic increasing order.

Definition at line 123 of file NameFactory.h.

◆ registerProduct()

template<class AbstractProduct >
void NameFactory< AbstractProduct >::registerProduct ( const string &  name,
FactoryFunction  function 
)

Definition at line 117 of file NameFactory.h.

Member Data Documentation

◆ _abstractName

template<class AbstractProduct >
const string NameFactory< AbstractProduct >::_abstractName
private

Definition at line 64 of file NameFactory.h.

◆ _pairs

template<class AbstractProduct >
vector<Pair> NameFactory< AbstractProduct >::_pairs
private

Definition at line 63 of file NameFactory.h.


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