OpenTTD Source 20241224-master-gf74b0cf984
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.

Definition at line 37 of file library_loader.h.

References handle, and OpenLibrary().

◆ ~LibraryLoader()

LibraryLoader::~LibraryLoader ( )
inline

Close the library.

Definition at line 45 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 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().

Field Documentation

◆ error

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

The last error that occurred, if set.

Definition at line 108 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 109 of file library_loader.h.

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


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