|
template<typename Derived = Base> |
std::shared_ptr< Derived > | create (const std::string &name, bool print_error=true) const |
| Create a shared instance of the desired object. More...
|
|
const std::unordered_map< std::string, std::shared_ptr< Base > > & | getObjectMap () const |
|
bool | hasObject (const std::string &name) |
| Check if a specified object (name) has been registered. More...
|
|
void | printObjects () const |
| Print registered object names to console. More...
|
|
bool | registerObject (const std::string &name, std::shared_ptr< Base > object_type) |
| Register a new object. More...
|
|
template<typename Base>
class corbo::Factory< Base >
Generic factory object.
A factory is used to create objects based on a known identifier (which is a string in this case). This facilitates the dynamic creation of specific interface implementations without including their actual declaration. Registration of objects is deferred from the library to the linker stage of the executable. This factory is implemented using the Singleton design pattern in order to facilitate the dynamic creation of objects wherever required without the need of sharing the factory among multiple classes and modules.
A macro for a convenient object registration is provided which can be invoked in the header file of the particular interface implementation. Hence, the source of the execuable only needs to include the particular header (containing the macro).
Note, interfaces must define a method of prototype:
virtual std::shared_ptr<Base> getInstance() = 0;
This method must be implemented in all subclasses in order to return a valid instance of the related subclass. Furthermore, the default constructure most not be deleted.
- Author
- Christoph Rösmann (chris.nosp@m.toph.nosp@m..roes.nosp@m.mann.nosp@m.@tu-d.nosp@m.ortm.nosp@m.und.d.nosp@m.e)
Definition at line 68 of file factory.h.