10#ifndef LIBRARY_LOADER_H
11#define LIBRARY_LOADER_H
24 template <
typename T,
typename = std::enable_if_t<std::is_function_v<T>>>
27 return reinterpret_cast<T *
>(this->p);
47 if (this->
handle !=
nullptr) {
59 return this->
error.has_value();
69 return this->
error.value_or(
"No error");
106 void *
GetSymbol(
const std::string &symbol_name);
108 std::optional<std::string>
error = {};
A function loaded from a library.
std::string GetLastError()
Get the last error that occurred while loading the library or a function.
bool HasError()
Check whether an error occurred while loading the library or a function.
std::optional< std::string > error
The last error that occurred, if set.
Function GetFunction(const std::string &symbol_name)
Get a function from a loaded library.
void * OpenLibrary(const std::string &filename)
Open the library with the given filename.
void * handle
Handle to the library.
~LibraryLoader()
Close the library.
LibraryLoader(const std::string &filename)
Load a library with the given filename.
void * GetSymbol(const std::string &symbol_name)
Get a symbol from the library.
void CloseLibrary()
Close the library.