siplasplas
A library for C++ reflection and introspection
|
Provides a cross-platform interface to load symbols from shared libraries at runtime. More...
#include <siplasplas/utility/dynamiclibrary.hpp>
Classes | |
class | Symbol |
Represents a symbol loaded from a dynamic library. More... | |
Public Member Functions | |
Symbol & | getSymbol (const std::string &name) |
Loads a symbol from this shared library. More... | |
void * | handle () const |
OS-specific shared library handle. More... | |
const std::string & | path () const |
Shared library path. See DynamicLibrary::load(). More... | |
Static Public Member Functions | |
static DynamicLibrary | load (const std::string &libraryPath) |
Loads a shared library. More... | |
Provides a cross-platform interface to load symbols from shared libraries at runtime.
DynamicLibrary is a RAII abstraction over a OS-specific shared library handle. The library handle is refcounted and automatically released when there are no more DynamicLibrary instances referencing it. Symbols can be loaded from the library using getSymbol() function.
Symbol& cpp::DynamicLibrary::getSymbol | ( | const std::string & | name | ) |
Loads a symbol from this shared library.
Library loaded symbols are cached by DynamicLibrary instances to avoid invoking the OS API again on an already loaded symbol. First call to getSymbol(<symbol name>) invokes DynamicLibrary::Symbol::loadSymbol() using *this as first argument. Consecuent calls read symbols from the cache.
name | Name of the symbol to load. |
void* cpp::DynamicLibrary::handle | ( | ) | const |
OS-specific shared library handle.
void*
pointer representing the OS-specific library handle.
|
static |
Loads a shared library.
This function loads a shared library from the given path. It follows the path conventions of the underlying OS API, no special path handling is done from siplasplas side. On linux, after loading the library the dlinfo() API is invoked to get the right path to the library. DynamicLibrary class can only be instanced through this factory function.
libraryPath | Path to the shared library. Can be relative to the executable working directory or absolute. The given path could not be the same registred into the DynamicLibrary instance (See details). |
std::runtime_error
exception.const std::string& cpp::DynamicLibrary::path | ( | ) | const |
Shared library path. See DynamicLibrary::load().