Frobby
0.9.5
|
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, FactoryFunction > | Pair |
typedef vector< Pair >::const_iterator | const_iterator |
Private Attributes | |
vector< Pair > | _pairs |
const string | _abstractName |
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.
|
private |
Definition at line 62 of file NameFactory.h.
typedef auto_ptr<AbstractProduct>(* NameFactory< AbstractProduct >::FactoryFunction) () |
Definition at line 39 of file NameFactory.h.
|
private |
Definition at line 61 of file NameFactory.h.
|
inline |
abstractName | The name for those things that are being generated in general. Used for error messages. |
Definition at line 37 of file NameFactory.h.
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.
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.
bool NameFactory< AbstractProduct >::empty |
Returns true if no names have been registered.
Definition at line 132 of file NameFactory.h.
string NameFactory< AbstractProduct >::getAbstractProductName |
Definition at line 137 of file NameFactory.h.
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.
void NameFactory< AbstractProduct >::registerProduct | ( | const string & | name, |
FactoryFunction | function | ||
) |
Definition at line 117 of file NameFactory.h.
|
private |
Definition at line 64 of file NameFactory.h.
|
private |
Definition at line 63 of file NameFactory.h.