
#include <rutz/factory.h>
Collaboration diagram for rutz::factory< T >:

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.
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. | |
|
||||||||||||||||
|
Default constructor.
|
|
|||||||||
|
Virtual no-throw destructor.
|
|
||||||||||
|
Find a creator for the given key; otherwise return null.
|
|
||||||||||
|
Get a list of known keys, separated by sep.
|
|
||||||||||
|
Query whether a given key is a valid, known key in the factory.
|
|
||||||||||
|
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(). |
|
||||||||||
|
Returns a new object of a given type. If the given type has not been registered with the factory, a null pointer is returned. |
|
||||||||||||||||
|
Introduces an alternate key for an existing key. There must already have been a creation function registered for the original key. |
|
||||||||||||||||||||
|
Registers a creation function with the factory. The default key associated with the creation function will be given by the type's actual C++ name. The function returns the actual key that was paired with the creation function. |
|
||||||||||||||||
|
Registers a creation object with the factory. The function returns the actual key that was paired with the creation function. |
|
||||||||||
|
Change the fallback function.
|
|
||||||||||
|
Change the fallback object.
|
1.4.4