|
Frobby 0.10.0
|
#include <NameFactory.h>
Public Types | |
| typedef unique_ptr< AbstractProduct >(* | FactoryFunction) () |
Public Member Functions | |
| NameFactory (const char *abstractName) | |
| void | registerProduct (const string &name, FactoryFunction function) |
| unique_ptr< AbstractProduct > | createNoThrow (const string &name) const |
| unique_ptr< AbstractProduct > | create (const string &name) const |
| void | getNamesWithPrefix (const string &prefix, vector< string > &names) const |
| bool | empty () const |
| string | getAbstractProductName () const |
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.
|
inline |
| abstractName | The name for those things that are being generated in general. Used for error messages. |
| unique_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.
| unique_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.
| bool NameFactory< AbstractProduct >::empty | ( | ) | const |
Returns true if no names have been registered.
| 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.