DynamicLibrary

class DynamicLibrary

Dynamically loadable library.

This provides capabilities to load a shared library (also known as dynamic library) and obtain C-functions that can be then called.

Public Functions

explicit DynamicLibrary(String lib_name)

Construct a dynamic library instance.

Parameters:

lib_name – Library name (the part after lib on Unix-based systems, without the file extension). For example, if your library is named libExt.so, you would provide Ext here.

void load()

Load the library.

void unload()

Unload the library.

template<typename SIGNATURE>
inline auto get_symbol(const char *symbol_name)

Get symbol as a function delegate.

Usage:

DynamicLibrary dll(<name>);
dll.load();
auto add = dll.get_symbol<double(double, double)>("add");
double res = add.invoke(10, 20);

Template Parameters:

SIGNATURE – function signature

Parameters:

symbol_name – symbol in the library

Returns:

Delegate that can call the function

Public Static Functions

static void add_search_path(const std::filesystem::path &new_path)

Add a new path that will be searched for extensions to load.

Parameters:

new_path – New path to search for extensions

static void clear_search_paths()

Remove all search paths.

static const std::vector<std::filesystem::path> &get_search_paths()

Get search path.

template<typename SIGNATURE>
class Delegate
template<typename RET, typename ...ARGS>
class Delegate<RET(ARGS...)>

Delegate class for calling C functions.

Template Parameters:
  • RET – Return type

  • ARGS – Function arguments

Public Functions

template<typename SIGNATURE>
inline auto bind(SIGNATURE *fn) -> void

Bind this delegate to a C function.

Template Parameters:

SIGNATURE – Function signature

Parameters:

fn – Pointer to the C function to bind