Classes | |
struct | create_hook |
create_hook is a helper object factory for the factory_mgr API. More... | |
class | aliaser |
A helper class to alias one token to another. More... | |
class | factory_mgr |
The factory_mgr class is essentially a static classloader, capable of loading classes by using registered factories for a given set of keys (e.g., class names). More... | |
Namespaces | |
namespace | Detail |
Functions | |
template<typename InterfaceT> | |
factory_mgr < InterfaceT, std::string > & | factory () |
Returns factory_mgr<InterfaceT, std::string>::instance(). | |
template<typename InterfaceT> | |
void | register_factory (const std::string &classname, InterfaceT *(*factory_function)()) |
Registers classname with InterfaceT using the given factory. | |
template<typename InterfaceT> | |
void | register_factory (const std::string &classname) |
Registers classname with InterfaceT using a default factory: create_hook<InterfaceT,ImplT>::create(). | |
template<typename InterfaceT, typename ImplT> | |
void | register_subtype (const std::string &classname) |
Registers a factory creating ImplT objects with the InterfaceT classloader using a default factory. | |
template<typename InterfaceT> | |
void | register_abstract (const std::string &classname) |
Registers a no-op factory for the given name and InterfaceT. | |
template<typename InterfaceT> | |
InterfaceT * | create (const std::string &classname) |
Returns the same as factory<InterfaceT>().create( classname ). |
This code should not be considered to be part of the public APIs: use the s11n::cl API for your factory-related needs unless absolutely necessary. Unfortunately, classloading can be intrusive enough that this API might sometimes need to be leaked into client- or non-core library code. The example which immediately comes to mind is clients which want to get a list of all registered factories: this can only be done by querying the factory itself for them.
The factory manager layer acts as a registration point for factories for near-arbitrary classes. Classes compatible with this layer must currently meet the following requirements:
InterfaceT* s11n::fac::create | ( | const std::string & | classname | ) | [inline] |
Returns the same as factory<InterfaceT>().create( classname ).
Definition at line 590 of file factory.hpp.
Referenced by s11n::cl::classloader_register_subtype(), s11n::node_traits< NodeT >::create(), s11n::serialize_to_subnode_unary_f< NodeType, BinaryFunctorT >::operator()(), s11n::serialize_to_subnode_f< BinaryFunctorT >::operator()(), s11n::fac::factory_mgr< InterfaceT, KeyType >::operator()(), and s11n::fac::create_hook< T, SubT >::operator()().
factory_mgr<InterfaceT, std::string>& s11n::fac::factory | ( | ) | [inline] |
Returns factory_mgr<InterfaceT, std::string>::instance().
All s11n-internal factory_mgr operations operate on one of these objects.
Definition at line 517 of file factory.hpp.
References s11nlite::instance().
void s11n::fac::register_abstract | ( | const std::string & | classname | ) | [inline] |
Registers a no-op factory for the given name and InterfaceT.
The factory will always return 0.
Definition at line 578 of file factory.hpp.
References register_factory().
void s11n::fac::register_factory | ( | const std::string & | classname | ) | [inline] |
Registers classname with InterfaceT using a default factory: create_hook<InterfaceT,ImplT>::create().
If ImplT is abstract then this function will fail unless create_hook is specialized to not create an object.
Definition at line 542 of file factory.hpp.
References register_factory().
void s11n::fac::register_factory | ( | const std::string & | classname, | |
InterfaceT *(*)() | factory_function | |||
) | [inline] |
Registers classname with InterfaceT using the given factory.
Definition at line 528 of file factory.hpp.
Referenced by register_abstract(), register_factory(), and register_subtype().
void s11n::fac::register_subtype | ( | const std::string & | classname | ) | [inline] |
Registers a factory creating ImplT objects with the InterfaceT classloader using a default factory.
ImplT may not be abstract unless create_hook<InterfaceT,ImplT> is specialized such that it's create() function simply returns 0 (or otherwise does not call: new ImplT).
Definition at line 556 of file factory.hpp.
References register_factory().