r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
utl::PluginLoader Class Reference

Modern, type-safe plugin loader. More...

#include <PluginLoader.hpp>

+ Collaboration diagram for utl::PluginLoader:

Public Member Functions

 PluginLoader ()=default
 
 ~PluginLoader ()=default
 
 PluginLoader (const PluginLoader &)=delete
 
PluginLoaderoperator= (const PluginLoader &)=delete
 
 PluginLoader (PluginLoader &&)=delete
 
PluginLoaderoperator= (PluginLoader &&)=delete
 
template<std::derived_from< IPlugin > T>
std::shared_ptr< T > loadPlugin (const std::string &path)
 Load a plugin of type T.
 

Private Member Functions

SharedLib loadLibrary (const std::string &path)
 
EntryPointFn getEntryPoint (SharedLib &lib, const std::string &path)
 

Private Attributes

std::mutex m_mutex
 
std::unordered_map< std::string, SharedLibm_handles
 
std::unordered_map< std::string, std::unique_ptr< IPlugin > > m_plugins
 

Detailed Description

Modern, type-safe plugin loader.

Definition at line 85 of file PluginLoader.hpp.

Constructor & Destructor Documentation

◆ PluginLoader() [1/3]

utl::PluginLoader::PluginLoader ( )
default

◆ ~PluginLoader()

utl::PluginLoader::~PluginLoader ( )
default

◆ PluginLoader() [2/3]

utl::PluginLoader::PluginLoader ( const PluginLoader & )
delete

◆ PluginLoader() [3/3]

utl::PluginLoader::PluginLoader ( PluginLoader && )
delete

Member Function Documentation

◆ getEntryPoint()

EntryPointFn utl::PluginLoader::getEntryPoint ( SharedLib & lib,
const std::string & path )
inlineprivate

Definition at line 163 of file PluginLoader.hpp.

References utl::SharedLib::handle.

Referenced by loadPlugin().

+ Here is the caller graph for this function:

◆ loadLibrary()

SharedLib utl::PluginLoader::loadLibrary ( const std::string & path)
inlineprivate

Definition at line 137 of file PluginLoader.hpp.

Referenced by loadPlugin().

+ Here is the caller graph for this function:

◆ loadPlugin()

template<std::derived_from< IPlugin > T>
std::shared_ptr< T > utl::PluginLoader::loadPlugin ( const std::string & path)
inline

Load a plugin of type T.

Template Parameters
TExpected plugin interface (must derive from IPlugin)
Parameters
pathPath to the dynamic library
Returns
shared_ptr<T> instance

Definition at line 102 of file PluginLoader.hpp.

References getEntryPoint(), utl::INFO, loadLibrary(), utl::Logger::log(), m_handles, m_mutex, and m_plugins.

Referenced by cli::Client::Client().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [1/2]

PluginLoader & utl::PluginLoader::operator= ( const PluginLoader & )
delete

◆ operator=() [2/2]

PluginLoader & utl::PluginLoader::operator= ( PluginLoader && )
delete

Member Data Documentation

◆ m_handles

std::unordered_map<std::string, SharedLib> utl::PluginLoader::m_handles
private

Definition at line 134 of file PluginLoader.hpp.

Referenced by loadPlugin().

◆ m_mutex

std::mutex utl::PluginLoader::m_mutex
private

Definition at line 133 of file PluginLoader.hpp.

Referenced by loadPlugin().

◆ m_plugins

std::unordered_map<std::string, std::unique_ptr<IPlugin> > utl::PluginLoader::m_plugins
private

Definition at line 135 of file PluginLoader.hpp.

Referenced by loadPlugin().


The documentation for this class was generated from the following file: