dylib Class Reference

Kynema API: kynema::util::dylib Class Reference
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches

#include <dylib.hpp>

Classes

class  exception
 
struct  filename_components
 
class  load_error
 
class  symbol_error
 

Public Types

using native_handle_type = DYLIB_WIN_OTHER(HINSTANCE, void *)
 
using native_symbol_type = DYLIB_WIN_OTHER(FARPROC, void *)
 

Public Member Functions

 dylib (const dylib &)=delete
 
dyliboperator= (const dylib &)=delete
 
 dylib (dylib &&other) noexcept
 
dyliboperator= (dylib &&other) noexcept
 
 ~dylib ()
 
native_symbol_type get_symbol (const char *symbol_name) const
 
native_symbol_type get_symbol (const std::string &symbol_name) const
 
template<typename T >
T * get_function (const char *symbol_name) const
 
template<typename T >
T * get_function (const std::string &symbol_name) const
 
template<typename T >
T & get_variable (const char *symbol_name) const
 
template<typename T >
T & get_variable (const std::string &symbol_name) const
 
bool has_symbol (const char *symbol_name) const noexcept
 
bool has_symbol (const std::string &symbol) const noexcept
 
native_handle_type native_handle () noexcept
 
 dylib (const char *dir_path, const char *lib_name, bool decorations=add_filename_decorations)
 
 dylib (const std::string &dir_path, const std::string &lib_name, bool decorations=add_filename_decorations)
 
 dylib (const std::string &dir_path, const char *lib_name, bool decorations=add_filename_decorations)
 
 dylib (const char *dir_path, const std::string &lib_name, bool decorations=add_filename_decorations)
 
 dylib (const std::string &lib_name, bool decorations=add_filename_decorations)
 
 dylib (const char *lib_name, bool decorations=add_filename_decorations)
 

Static Public Attributes

static constexpr bool add_filename_decorations = true
 
static constexpr bool no_filename_decorations = false
 

Static Protected Member Functions

static native_handle_type open (const char *path) noexcept
 
static native_symbol_type locate_symbol (native_handle_type lib, const char *name) noexcept
 
static void close (native_handle_type lib) noexcept
 
static std::string get_error_description ()
 

Protected Attributes

native_handle_type m_handle {nullptr}
 

Detailed Description

The dylib class represents a single dynamic library instance, allowing the access of symbols like functions or global variables

Member Typedef Documentation

◆ native_handle_type

◆ native_symbol_type

Constructor & Destructor Documentation

◆ dylib() [1/8]

kynema::util::dylib::dylib ( const dylib )
delete

◆ dylib() [2/8]

kynema::util::dylib::dylib ( dylib &&  other)
inlinenoexcept

◆ dylib() [3/8]

kynema::util::dylib::dylib ( const char *  dir_path,
const char *  lib_name,
bool  decorations = add_filename_decorations 
)
inline

Loads a dynamic library

Exceptions
`dylib::load_error`if the library could not be opened (including the case of the library file not being found)
`std::invalid_argument`if the arguments are null
Parameters
dir_paththe directory path where the dynamic library is located
lib_namethe name of the dynamic library to load
decorationsadds OS-specific decorations to the library name

◆ dylib() [4/8]

kynema::util::dylib::dylib ( const std::string &  dir_path,
const std::string &  lib_name,
bool  decorations = add_filename_decorations 
)
inline

◆ dylib() [5/8]

kynema::util::dylib::dylib ( const std::string &  dir_path,
const char *  lib_name,
bool  decorations = add_filename_decorations 
)
inline

◆ dylib() [6/8]

kynema::util::dylib::dylib ( const char *  dir_path,
const std::string &  lib_name,
bool  decorations = add_filename_decorations 
)
inline

◆ dylib() [7/8]

kynema::util::dylib::dylib ( const std::string &  lib_name,
bool  decorations = add_filename_decorations 
)
inlineexplicit

◆ dylib() [8/8]

kynema::util::dylib::dylib ( const char *  lib_name,
bool  decorations = add_filename_decorations 
)
inlineexplicit

◆ ~dylib()

kynema::util::dylib::~dylib ( )
inline

Member Function Documentation

◆ close()

static void kynema::util::dylib::close ( native_handle_type  lib)
inlinestaticprotectednoexcept

◆ get_error_description()

static std::string kynema::util::dylib::get_error_description ( )
inlinestaticprotected

◆ get_function() [1/2]

template<typename T >
T * kynema::util::dylib::get_function ( const char *  symbol_name) const
inline

Get a function from the currently loaded dynamic library

Exceptions
`dylib::symbol_error`if the function could not be found
`std::invalid_argument`if the argument is null
Template Parameters
Tthe function type, e.g., double(int, int)
Parameters
symbol_namethe function name to lookup
Returns
a pointer to the requested function

◆ get_function() [2/2]

template<typename T >
T * kynema::util::dylib::get_function ( const std::string &  symbol_name) const
inline

◆ get_symbol() [1/2]

native_symbol_type kynema::util::dylib::get_symbol ( const char *  symbol_name) const
inline

Get a symbol from the currently loaded dynamic library

Exceptions
`dylib::symbol_error`if the symbol could not be found
`std::invalid_argument`if the argument or library handle is null
Parameters
symbol_namethe symbol name to lookup
Returns
a pointer to the requested symbol

◆ get_symbol() [2/2]

native_symbol_type kynema::util::dylib::get_symbol ( const std::string &  symbol_name) const
inline

◆ get_variable() [1/2]

template<typename T >
T & kynema::util::dylib::get_variable ( const char *  symbol_name) const
inline

Get a variable from the currently loaded dynamic library

Exceptions
`dylib::symbol_error`if the variable could not be found
`std::invalid_argument`if the argument is null
Template Parameters
Tthe variable type
Parameters
symbol_namethe variable name to lookup
Returns
a reference to the requested variable

◆ get_variable() [2/2]

template<typename T >
T & kynema::util::dylib::get_variable ( const std::string &  symbol_name) const
inline

◆ has_symbol() [1/2]

bool kynema::util::dylib::has_symbol ( const char *  symbol_name) const
inlinenoexcept

Check if a symbol exists in the currently loaded dynamic library. This method will return false if no dynamic library is currently loaded or if the symbol name is nullptr

Parameters
symbol_namethe symbol name to look for
Returns
true if the symbol exists in the dynamic library, false otherwise

◆ has_symbol() [2/2]

bool kynema::util::dylib::has_symbol ( const std::string &  symbol) const
inlinenoexcept

◆ locate_symbol()

static native_symbol_type kynema::util::dylib::locate_symbol ( native_handle_type  lib,
const char *  name 
)
inlinestaticprotectednoexcept

◆ native_handle()

native_handle_type kynema::util::dylib::native_handle ( )
inlinenoexcept
Returns
the dynamic library handle

◆ open()

static native_handle_type kynema::util::dylib::open ( const char *  path)
inlinestaticprotectednoexcept

◆ operator=() [1/2]

dylib & kynema::util::dylib::operator= ( const dylib )
delete

◆ operator=() [2/2]

dylib & kynema::util::dylib::operator= ( dylib &&  other)
inlinenoexcept

Member Data Documentation

◆ add_filename_decorations

constexpr bool kynema::util::dylib::add_filename_decorations = true
staticconstexpr

◆ m_handle

native_handle_type kynema::util::dylib::m_handle {nullptr}
protected

◆ no_filename_decorations

constexpr bool kynema::util::dylib::no_filename_decorations = false
staticconstexpr

The documentation for this class was generated from the following file:
  • /home/runner/work/kynema/kynema/kynema/src/vendor/dylib/dylib.hpp