#include <rutz/factory.h>
Public Types | |
typedef factory_base::fallback_t | fallback_t |
typedef T | base_t |
Public Member Functions | |
factory (const char *keydescr="object type", bool nocase=false) | |
Default constructor. | |
virtual | ~factory () throw () |
Virtual no-throw destructor. | |
const char * | register_creator (rutz::creator_base< base_t > *creator, const char *name) |
Registers a creation object with the factory. | |
template<class derived_t> | |
const char * | register_creator (derived_t(*func)(), const char *key=0) |
Registers a creation function with the factory. | |
void | register_alias (const char *orig_key, const char *alias_key) |
Introduces an alternate key for an existing key. | |
bool | is_valid_key (const char *key) const |
Query whether a given key is a valid, known key in the factory. | |
rutz::fstring | get_known_keys (const char *sep) const |
Get a list of known keys, separated by sep. | |
base_t | new_object (const rutz::fstring &type) const |
Returns a new object of a given type. | |
base_t | new_checked_object (const rutz::fstring &type) const |
Returns a new object of a given type. | |
void | set_fallback (rutz::shared_ptr< factory_fallback > f) |
Change the fallback object. | |
void | set_fallback (fallback_t *fptr) |
Change the fallback function. | |
Protected Member Functions | |
rutz::creator_base< base_t > * | find_creator (const rutz::fstring &key) const |
Find a creator for the given key; otherwise return null. |
rutz::factory can create objects of different types associated with different 'key' strings. rutz::factory maintains a mapping from key strings to rutz::creator_base's, and so given a key can call the create() function of the associated creator_base. All of the product types of a factory must be derived from factory::base_t. The recommended usage is for factories for specific types to be implemented as singleton classes derived from rutz::factory.
rutz::factory uses an internal mutex so that all of its member functions can safely be called in a multithreaded program without external locking.
Definition at line 155 of file factory.h.
rutz::factory< T >::factory | ( | const char * | keydescr = "object type" , |
|
bool | nocase = false | |||
) | [inline] |
Default constructor.
key_descr | a human-readable description of what this factory's keys represent; this is used in error messages, e.g. if descr is "frobnicator", then error messages would include "unknown frobnicator" | |
nocase | true if the factory should use case-insensitive string comparisons (default is false, giving normal case-sensitive string comparisons) |
const char* rutz::factory< T >::register_creator | ( | rutz::creator_base< base_t > * | creator, | |
const char * | name | |||
) | [inline] |
const char* rutz::factory< T >::register_creator | ( | derived_t(*)() | func, | |
const char * | key = 0 | |||
) | [inline] |
void rutz::factory< T >::register_alias | ( | const char * | orig_key, | |
const char * | alias_key | |||
) | [inline] |
base_t rutz::factory< T >::new_object | ( | const rutz::fstring & | type | ) | const [inline] |
base_t rutz::factory< T >::new_checked_object | ( | const rutz::fstring & | type | ) | const [inline] |
Returns a new object of a given type.
If the given type has not been registered with the factory, an exception is thrown.
Definition at line 300 of file factory.h.
Referenced by nub::obj_mgr::new_obj().