OpenTTD Source  20240919-master-gdf0233f4c2
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. More...
 
std::string GetLastError ()
 Get the last error that occurred while loading the library or a function. More...
 
Function GetFunction (const std::string &symbol_name)
 Get a function from a loaded library. More...
 

Private Member Functions

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

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.

Member Function Documentation

◆ 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 78 of file library_loader.h.

References error, and GetSymbol().

Referenced by VideoDriver_Win32Base::GetDPIScale(), and Win32StringContains().

◆ 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 67 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.

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 57 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.

Definition at line 39 of file library_loader_unix.cpp.

References error.

Referenced by LibraryLoader().


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