cae  0.0.0
Cross-API graphics engine
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, const std::string_view &pluginPrefix="")
 Load a plugin of type T.
 

Static Private Member Functions

static SharedLib loadLibrary (const std::string &path)
 Load a shared library.
 
static EntryPointFn getEntryPoint (SharedLib &lib, const std::string &path)
 
static void validatePluginPath (const std::filesystem::path &path, const std::string_view &pluginPrefix)
 Validate the plugin 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 86 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()

static EntryPointFn utl::PluginLoader::getEntryPoint ( SharedLib & lib,
const std::string & path )
inlinestaticprivate
Parameters
libLoaded SharedLib
pathPath to the dynamic library
Returns
EntryPoint function pointer

Definition at line 186 of file PluginLoader.hpp.

References utl::SharedLib::handle.

Referenced by loadPlugin().

+ Here is the caller graph for this function:

◆ loadLibrary()

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

Load a shared library.

Parameters
pathPath to the dynamic library
Returns
Loaded SharedLib

Definition at line 160 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,
const std::string_view & pluginPrefix = "" )
inline

Load a plugin of type T.

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

Definition at line 105 of file PluginLoader.hpp.

References getEntryPoint(), loadLibrary(), m_handles, m_mutex, m_plugins, PLUGINS_PREFIX, and validatePluginPath().

+ Here is the call graph for this function:

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ validatePluginPath()

static void utl::PluginLoader::validatePluginPath ( const std::filesystem::path & path,
const std::string_view & pluginPrefix )
inlinestaticprivate

Validate the plugin path.

Parameters
pathPath to the dynamic library
pluginPrefixExpected prefix for plugin filenames

Definition at line 206 of file PluginLoader.hpp.

Referenced by loadPlugin().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_handles

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

Definition at line 152 of file PluginLoader.hpp.

Referenced by loadPlugin().

◆ m_mutex

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

Definition at line 151 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 153 of file PluginLoader.hpp.

Referenced by loadPlugin().


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