Represents a symbol loaded from a dynamic library.
More...
#include <siplasplas/utility/dynamiclibrary.hpp>
|
const std::string & | name () const |
| Returns the name of the symbol. More...
|
|
void * | handle () |
| Returns the raw address of the loaded symbol. More...
|
|
const void * | handle () const |
| Returns the raw address of the loaded symbol. More...
|
|
template<typename T > |
T | get () |
| Returns the symbol converted to the required type. More...
|
|
template<typename T > |
T & | getObject () |
| Returns the symbol interpreted as a reference to an object. More...
|
|
template<typename T > |
const T & | getObject () const |
| Returns the symbol interpreted as a const reference to an object. More...
|
|
Represents a symbol loaded from a dynamic library.
This class provides access to a loaded symbol from an external library. The class wraps the raw pointer to the loaded symbol returned from the OS-specific API. You can access the loaded symbol address directly or use the convenient get() and getObject() functions that already apply type conversions to the symbol. Symbols are associated with a DynamicLibrary instanced. When its parent dynamic library goes out of scope symbols are invalidated and accessing them has undefined behavior.
auto externalFunction = DynamicLibrary::Symbol::load(myLib, "external_function");
auto fptr = externalFunction.get<void(int)>();
fptr(42);
template<typename T >
T cpp::DynamicLibrary::Symbol::get |
( |
| ) |
|
|
inline |
Returns the symbol converted to the required type.
- Template Parameters
-
T | Type to convert the symbol to. Must be a pointer type. |
- Returns
- Symbol value converted to
T
.
template<typename T >
T& cpp::DynamicLibrary::Symbol::getObject |
( |
| ) |
|
|
inline |
Returns the symbol interpreted as a reference to an object.
This function is useful when loading variables from the shared library. Loading objects with automatic or dynamic storage duration has undefined behavior.
- Template Parameters
-
T | Value type to convert the symbol to. |
- Returns
- Lvalue reference of type
T
to the symbol.
auto myLibGlobalVariable = myLibrary.getSymbol("my_lib_global_variable");
std::cout << "myLib::my_lib_global_variable: " << myLibGlobalVariable.getObject<int>();
template<typename T >
const T& cpp::DynamicLibrary::Symbol::getObject |
( |
| ) |
const |
|
inline |
Returns the symbol interpreted as a const reference to an object.
This function is useful when loading variables from the shared library. Loading objects with automatic or dynamic storage duration has undefined behavior.
- Template Parameters
-
T | Value type to convert the symbol to. |
- Returns
- Lvalue const reference of type
T
to the symbol.
auto myLibGlobalVariable = myLibrary.getSymbol("my_lib_global_variable");
std::cout << "myLib::my_lib_global_variable: " << myLibGlobalVariable.getObject<int>();
void* cpp::DynamicLibrary::Symbol::handle |
( |
| ) |
|
Returns the raw address of the loaded symbol.
- Returns
- Pointer to the symbol.
const void* cpp::DynamicLibrary::Symbol::handle |
( |
| ) |
const |
Returns the raw address of the loaded symbol.
- Returns
- Const pointer to the symbol.
const std::string& cpp::DynamicLibrary::Symbol::name |
( |
| ) |
const |
Returns the name of the symbol.
- Returns
- std::string containing the name of the symbol.
The documentation for this class was generated from the following file: