Frobby 0.10.0
Loading...
Searching...
No Matches
NameFactory< AbstractProduct > Class Template Reference

#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

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.

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.

Member Function Documentation

◆ create()

template<class AbstractProduct>
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.

◆ createNoThrow()

template<class AbstractProduct>
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.

◆ empty()

template<class AbstractProduct>
bool NameFactory< AbstractProduct >::empty ( ) const

Returns true if no names have been registered.

◆ 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.


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