|
gfactory
|
Factory registry and dynamic-library manager for run-time creation of plugin objects. More...
#include <gfactory.h>
Public Member Functions | |
| GManager (const std::shared_ptr< GOptions > &gopt) | |
| Construct a manager instance. | |
| GManager (const GManager &)=delete | |
| No copy – the manager owns unique resources (factory objects and loaded libraries). | |
| GManager & | operator= (const GManager &)=delete |
| GManager (GManager &&) noexcept=default | |
| Allow move for container support. | |
| GManager & | operator= (GManager &&) noexcept=default |
| ~GManager () override | |
| Destructor. | |
| template<class Derived > | |
| void | RegisterObjectFactory (std::string_view name) |
| Register a concrete factory under a string key. | |
| template<class Derived > | |
| void | RegisterObjectFactory (std::string_view name, const std::shared_ptr< GOptions > &gopts) |
| Register a concrete factory under a string key using a specific options object. | |
| template<class Base > | |
| Base * | CreateObject (std::string_view name) const |
| Create an instance of a previously registered factory. | |
| template<class T > | |
| std::shared_ptr< T > | LoadAndRegisterObjectFromLibrary (std::string_view name, const std::shared_ptr< GOptions > &gopts) |
| Load a plugin library and instantiate an object from it. | |
| void | clearDLMap () noexcept |
| Release all loaded dynamic libraries. | |
Public Member Functions inherited from GBase< GManager > | |
| GBase (const std::shared_ptr< GOptions > &gopt, std::string logger_name="") | |
| GBase (const std::shared_ptr< GLogger > &logger) | |
| GBase (const GBase &)=default | |
| GBase (GBase &&) noexcept=default | |
| virtual | ~GBase () |
| GBase & | operator= (const GBase &)=default |
| GBase & | operator= (GBase &&) noexcept=default |
Additional Inherited Members | |
Protected Attributes inherited from GBase< GManager > | |
| std::shared_ptr< GLogger > | log |
GManager provides two related services:
"triangle").<name>.gplugin) into the process.dlsym inside the product type).std::shared_ptr<T> ensures:std::shared_ptr<DynamicLib>).If a factory key is unknown or a library cannot be loaded, the manager logs an error using its logger. The exact policy after logging depends on the logger configuration (e.g., may abort, throw, or continue).
Definition at line 121 of file gfactory.h.
|
inlineexplicit |
| gopt | Shared options object used to configure the base logger and behavior. |
PLUGIN_LOGGER channel for plugin-related output. Definition at line 131 of file gfactory.h.
|
delete |
|
defaultnoexcept |
|
inlineoverride |
Calls clearDLMap() to release any loaded libraries.
Definition at line 147 of file gfactory.h.
|
inlinenoexcept |
This is safe to call multiple times.
Definition at line 226 of file gfactory.h.
| Base * GManager::CreateObject | ( | std::string_view | name | ) | const |
| Base | Base type to cast the created object to. |
| name | Factory key. |
Base.Definition at line 257 of file gfactory.h.
| std::shared_ptr< T > GManager::LoadAndRegisterObjectFromLibrary | ( | std::string_view | name, |
| const std::shared_ptr< GOptions > & | gopts ) |
The product type T must provide a static method instantiate(dlhandle, std::shared_ptr<GOptions>) that performs the symbol lookup and returns a raw pointer.
| T | Product base type. |
| name | Plugin name (used to form <name>.gplugin). |
| gopts | Options to pass to the instantiated object. |
std::shared_ptr<T> owning the created object; its deleter also retains the library. Definition at line 270 of file gfactory.h.
| void GManager::RegisterObjectFactory | ( | std::string_view | name | ) |
| Derived | Concrete type to instantiate. |
| name | Factory key used later by CreateObject(). |
Definition at line 244 of file gfactory.h.
| void GManager::RegisterObjectFactory | ( | std::string_view | name, |
| const std::shared_ptr< GOptions > & | gopts ) |
| Derived | Concrete type to instantiate. |
| name | Factory key used later by CreateObject(). |
| gopts | Options forwarded to the factory and then to constructed objects. |
Definition at line 251 of file gfactory.h.