MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
mxvm::Function< R(Args...)> Class Template Reference

RAII wrapper for dynamically loaded functions via dlopen/dlsym. More...

#include <function.hpp>

Public Types

using Fn = R (*)(Args...)

Public Member Functions

 Function (char const *lib, char const *name)
 Load a function from a named shared library.
 Function (char const *name)
 Load a function from the main program's symbol table.
 ~Function ()
 Function (const Function &)=delete
Functionoperator= (const Function &)=delete
 Function (Function &&other) noexcept
Functionoperator= (Function &&other) noexcept
operator() (Args... args) const
 Invoke the loaded function.

Private Attributes

void * handle = nullptr
 dlopen library handle
Fn fn = nullptr
 resolved function pointer

Detailed Description

template<typename R, typename... Args>
class mxvm::Function< R(Args...)>

RAII wrapper for dynamically loaded functions via dlopen/dlsym.

Template Parameters
RReturn type of the loaded function
ArgsParameter types of the loaded function

Loads a shared library and resolves a function symbol at construction time. The library handle is automatically closed on destruction. Move-only.

Definition at line 25 of file function.hpp.

Member Typedef Documentation

◆ Fn

template<typename R, typename... Args>
using mxvm::Function< R(Args...)>::Fn = R (*)(Args...)

Definition at line 27 of file function.hpp.

Constructor & Destructor Documentation

◆ Function() [1/4]

template<typename R, typename... Args>
mxvm::Function< R(Args...)>::Function ( char const * lib,
char const * name )
inline

Load a function from a named shared library.

Parameters
libPath to the shared library
nameSymbol name to resolve
Exceptions
std::runtime_errorif dlopen or dlsym fails

Definition at line 35 of file function.hpp.

References fn, and handle.

Referenced by Function(), Function(), operator=(), and operator=().

◆ Function() [2/4]

template<typename R, typename... Args>
mxvm::Function< R(Args...)>::Function ( char const * name)
inline

Load a function from the main program's symbol table.

Parameters
nameSymbol name to resolve (via dlopen(nullptr, ...))
Exceptions
std::runtime_errorif dlsym fails

Definition at line 52 of file function.hpp.

References fn, and handle.

◆ ~Function()

template<typename R, typename... Args>
mxvm::Function< R(Args...)>::~Function ( )
inline

Definition at line 64 of file function.hpp.

References handle.

◆ Function() [3/4]

template<typename R, typename... Args>
mxvm::Function< R(Args...)>::Function ( const Function< R(Args...)> & )
delete

References Function().

◆ Function() [4/4]

template<typename R, typename... Args>
mxvm::Function< R(Args...)>::Function ( Function< R(Args...)> && other)
inlinenoexcept

Definition at line 72 of file function.hpp.

References Function(), fn, and handle.

Member Function Documentation

◆ operator()()

template<typename R, typename... Args>
R mxvm::Function< R(Args...)>::operator() ( Args... args) const
inline

Invoke the loaded function.

Definition at line 89 of file function.hpp.

References fn.

◆ operator=() [1/2]

template<typename R, typename... Args>
Function & mxvm::Function< R(Args...)>::operator= ( const Function< R(Args...)> & )
delete

References Function().

◆ operator=() [2/2]

template<typename R, typename... Args>
Function & mxvm::Function< R(Args...)>::operator= ( Function< R(Args...)> && other)
inlinenoexcept

Definition at line 76 of file function.hpp.

References Function(), fn, and handle.

Member Data Documentation

◆ fn

template<typename R, typename... Args>
Fn mxvm::Function< R(Args...)>::fn = nullptr
private

resolved function pointer

Definition at line 97 of file function.hpp.

Referenced by Function(), Function(), Function(), operator()(), and operator=().

◆ handle

template<typename R, typename... Args>
void* mxvm::Function< R(Args...)>::handle = nullptr
private

dlopen library handle

Definition at line 96 of file function.hpp.

Referenced by Function(), Function(), Function(), ~Function(), and operator=().


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