fourdst_plugin 0.0.1a
C++ Plugin Manager
|
Central manager for plugin loading and lifecycle management. More...
#include <plugin_manager.h>
Classes | |
struct | Impl |
Public Member Functions | |
PluginManager (const PluginManager &)=delete | |
Copy constructor (deleted) | |
PluginManager & | operator= (const PluginManager &)=delete |
Copy assignment operator (deleted) | |
PluginManager (PluginManager &&)=delete | |
Move constructor (deleted) | |
PluginManager & | operator= (PluginManager &&)=delete |
Move assignment operator (deleted) | |
void | load (const std::filesystem::path &library_path) const |
Load a plugin from the specified library path. | |
void | unload (const std::string &plugin_name) const |
Unload a plugin by name. | |
template<typename T> | |
T * | get (const std::string &plugin_name) |
Get a type-safe pointer to a loaded plugin. | |
Static Public Member Functions | |
static PluginManager & | getInstance () |
Private Member Functions | |
PluginManager () | |
~PluginManager () | |
IPlugin * | get_raw (const std::string &plugin_name) const |
Internal method to get raw plugin pointer without type checking. | |
Private Attributes | |
std::unique_ptr< Impl > | pimpl |
Forward declaration for PIMPL implementation. | |
Central manager for plugin loading and lifecycle management.
The PluginManager class provides a comprehensive interface for working with dynamically loaded plugins. It handles:
The manager uses the PIMPL idiom to hide implementation details and maintain ABI stability. It automatically handles proper cleanup of all loaded plugins when the manager is destroyed.
|
delete |
Copy constructor (deleted)
PluginManager instances cannot be copied due to the nature of shared library handles and plugin instance ownership.
|
delete |
Move constructor (deleted)
PluginManager instances cannot be moved to maintain stability of plugin handles and prevent issues with library cleanup.
|
private |
|
private |
|
inline |
Get a type-safe pointer to a loaded plugin.
Retrieves a plugin by name and attempts to cast it to the specified type. The type must inherit from IPlugin and the plugin must have been loaded and must be compatible with the requested type.
T | The plugin interface type to cast to (must inherit from IPlugin) |
plugin_name | The name of the plugin to retrieve |
fourdst::plugin::exception::PluginNotLoadedError | If no plugin with the given name has been loaded |
fourdst::plugin::exception::PluginTypeError | If the plugin cannot be cast to the requested type T |
Example usage:
|
nodiscardprivate |
Internal method to get raw plugin pointer without type checking.
plugin_name | The name of the plugin to retrieve |
Never | throws |
|
static |
void fourdst::plugin::manager::PluginManager::load | ( | const std::filesystem::path & | library_path | ) | const |
Load a plugin from the specified library path.
Attempts to load a shared library as a plugin. The library must export the required symbols (create_plugin and destroy_plugin) and the plugin must have a unique name within this manager instance.
library_path | Path to the shared library file to load |
fourdst::plugin::exception::PluginLoadError | If the library file cannot be found, opened, or if the plugin factory returns nullptr |
fourdst::plugin::exception::PluginSymbolError | If the required symbols (create_plugin/destroy_plugin) cannot be found in the library |
fourdst::plugin::exception::PluginNameCollisionError | If a plugin with the same name is already loaded |
|
delete |
Copy assignment operator (deleted)
PluginManager instances cannot be copy-assigned due to the nature of shared library handles and plugin instance ownership.
|
delete |
Move assignment operator (deleted)
PluginManager instances cannot be move-assigned to maintain stability of plugin handles and prevent issues with library cleanup.
void fourdst::plugin::manager::PluginManager::unload | ( | const std::string & | plugin_name | ) | const |
Unload a plugin by name.
Removes the specified plugin from the manager, calls its destructor, and closes the associated shared library handle. If no plugin with the given name exists, this operation is a no-op.
plugin_name | The name of the plugin to unload |
Never | throws (safe to call with non-existent plugin names) |
|
private |
Forward declaration for PIMPL implementation.
PIMPL pointer to hide implementation details