Arcade architecture
Loader::LibLoader Class Reference

A class for dynamically loading and managing modules. More...

#include <LibLoader.hpp>

Public Member Functions

Loader::ModuleType_t getModuleType () const
 Get the type of the loaded module. More...
 
const char * getModulePath () const
 Get the path of the loaded module. More...
 
template<class T >
T * initEntryPoint ()
 Initializes and retrieves an instance of a class from a dynamically loaded library. More...
 
void closeLib ()
 Closes the currently loaded library. More...
 
void openLib (const std::string &path)
 Opens a shared library from the specified file path. More...
 
 LibLoader ()=default
 Constructor for the LibLoader class. More...
 
 ~LibLoader ()
 Destructor for the LibLoader class. More...
 

Protected Types

typedef Loader::ModuleType_t(* GetModuleTypeFct) ()
 

Protected Attributes

void * _moduleHandle = nullptr
 
std::string _modulePath
 
Loader::ModuleType_t _moduleType = Loader::ModuleType_t::TYPE_COUNT
 
GetModuleTypeFct _getModuleType = nullptr
 

Detailed Description

A class for dynamically loading and managing modules.

The LibLoader class is responsible for loading dynamic libraries (modules) at runtime. It provides methods to retrieve module type, path, and name, and to create instances of display modules.

Member Typedef Documentation

◆ GetModuleTypeFct

typedef Loader::ModuleType_t(* Loader::LibLoader::GetModuleTypeFct) ()
protected

Function pointer to retrieve module type.

Constructor & Destructor Documentation

◆ LibLoader()

Loader::LibLoader::LibLoader ( )
default

Constructor for the LibLoader class.

Initializes the LibLoader object

◆ ~LibLoader()

Loader::LibLoader::~LibLoader ( )

Destructor for the LibLoader class.

Cleans up resources and unloads the module if it is loaded.

Member Function Documentation

◆ closeLib()

void Loader::LibLoader::closeLib ( )

Closes the currently loaded library.

This function is responsible for properly unloading and releasing any resources associated with the dynamically loaded library. It ensures that the library is no longer in use and prevents resource leaks.

◆ getModulePath()

const char * Loader::LibLoader::getModulePath ( ) const
inline

Get the path of the loaded module.

Returns
The path of the module as a C-style string.

◆ getModuleType()

Loader::ModuleType_t Loader::LibLoader::getModuleType ( ) const
inline

Get the type of the loaded module.

Returns
The type of the module as a Loader::ModuleType_t.

◆ initEntryPoint()

template<class T >
T * Loader::LibLoader::initEntryPoint ( )
inline

Initializes and retrieves an instance of a class from a dynamically loaded library.

This template function attempts to locate and invoke the "getClass" function from a dynamically loaded library. The "getClass" function is expected to return a pointer to an instance of the specified class type T. If the function cannot be found or invoked, an exception is thrown.

Template Parameters
TThe type of the class to be instantiated.
Returns
T* A pointer to an instance of the specified class type T.
Exceptions
DllExceptionIf the "getClass" function cannot be retrieved or invoked.

◆ openLib()

void Loader::LibLoader::openLib ( const std::string &  path)

Opens a shared library from the specified file path.

This function attempts to load a shared library located at the given file path. It is typically used to dynamically load external libraries at runtime.

Parameters
pathThe file path to the shared library to be loaded. It should be a valid path to a shared library file.
Exceptions
std::runtime_errorIf the library cannot be opened or loaded.

Member Data Documentation

◆ _getModuleType

GetModuleTypeFct Loader::LibLoader::_getModuleType = nullptr
protected

Pointer to the function that retrieves module type.

◆ _moduleHandle

void* Loader::LibLoader::_moduleHandle = nullptr
protected

Handle to the loaded module.

◆ _modulePath

std::string Loader::LibLoader::_modulePath
protected

Path to the module file.

◆ _moduleType

Loader::ModuleType_t Loader::LibLoader::_moduleType = Loader::ModuleType_t::TYPE_COUNT
protected

Type of the module.


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