OpenTTD Source 20260218-master-g2123fca5ea
LibraryLoader Class Reference

Data Structures

class  Function
 A function loaded from a library. More...

Public Member Functions

 LibraryLoader (const std::string &filename)
 Load a library with the given filename.
 ~LibraryLoader ()
 Close the library.
bool HasError ()
 Check whether an error occurred while loading the library or a function.
std::string GetLastError ()
 Get the last error that occurred while loading the library or a function.
Function GetFunction (const std::string &symbol_name)
 Get a function from a loaded library.

Private Member Functions

void * OpenLibrary (const std::string &filename)
 Open the library with the given filename.
void CloseLibrary ()
 Close the library.
void * GetSymbol (const std::string &symbol_name)
 Get a symbol from the library.

Private Attributes

std::optional< std::string > error = {}
 The last error that occurred, if set.
void * handle = nullptr
 Handle to the library.

Detailed Description

Definition at line 13 of file library_loader.h.

Constructor & Destructor Documentation

◆ LibraryLoader()

LibraryLoader::LibraryLoader ( const std::string & filename)
inlineexplicit

Load a library with the given filename.

Parameters
filenameThe library to open.

Definition at line 38 of file library_loader.h.

References handle, and OpenLibrary().

◆ ~LibraryLoader()

LibraryLoader::~LibraryLoader ( )
inline

Close the library.

Definition at line 46 of file library_loader.h.

References CloseLibrary(), and handle.

Member Function Documentation

◆ CloseLibrary()

void LibraryLoader::CloseLibrary ( )
private

Close the library.

Definition at line 49 of file library_loader_unix.cpp.

References handle.

Referenced by ~LibraryLoader().

◆ GetFunction()

Function LibraryLoader::GetFunction ( const std::string & symbol_name)
inline

Get a function from a loaded library.

Parameters
symbol_nameThe name of the function to get.
Returns
The function. Check HasError() before using.

Definition at line 79 of file library_loader.h.

References error, and GetSymbol().

◆ GetLastError()

std::string LibraryLoader::GetLastError ( )
inline

Get the last error that occurred while loading the library or a function.

Returns
The error message.

Definition at line 68 of file library_loader.h.

References error.

◆ GetSymbol()

void * LibraryLoader::GetSymbol ( const std::string & symbol_name)
private

Get a symbol from the library.

Should set error if any error occurred.

Parameters
symbol_nameThe name of the symbol to get.
Returns
The loaded symbol, or nullptr when no symbol was loaded.

Definition at line 54 of file library_loader_unix.cpp.

References error, and handle.

Referenced by GetFunction().

◆ HasError()

bool LibraryLoader::HasError ( )
inline

Check whether an error occurred while loading the library or a function.

Returns
Whether an error occurred.

Definition at line 58 of file library_loader.h.

References error.

◆ OpenLibrary()

void * LibraryLoader::OpenLibrary ( const std::string & filename)
private

Open the library with the given filename.

Should set error if any error occurred.

Parameters
filenameThe filename of the library to open.
Returns
Handle to the opened library.

Definition at line 39 of file library_loader_unix.cpp.

References error.

Referenced by LibraryLoader().

Field Documentation

◆ error

std::optional<std::string> LibraryLoader::error = {}
private

The last error that occurred, if set.

Definition at line 111 of file library_loader.h.

Referenced by GetFunction(), GetLastError(), GetSymbol(), HasError(), and OpenLibrary().

◆ handle

void* LibraryLoader::handle = nullptr
private

Handle to the library.

Definition at line 112 of file library_loader.h.

Referenced by CloseLibrary(), GetSymbol(), LibraryLoader(), and ~LibraryLoader().


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