로딩중...
검색중...
일치하는것 없음
by::dlib 클래스 참조

Dynamic library loading and management class 더 자세히 ...

#include <dlib.hpp>

Public 멤버 함수

 dlib (const char *path)
 
 dlib (const std::string &path)
 
 dlib (const me &rhs)
 
me & operator= (const me &rhs)
 
const std::string & getPath () const
 
void setPath (const std::string &path)
 
void setPath (const std::string *it) BY_SIDE_FUNC(setPath)
 
tmay< std::string > load ()
 Loads dynamic library into memory
 
nbool isLoaded () const
 
template<typename F >
tmayFunc< FaccessFunc (const std::string &name)
 Accesses function by name and returns typed function pointer
 
template<typename F >
tmayFunc< FaccessFunc (const std::string *it) BY_SIDE_FUNC(accessFunc< F >)
 
template<typename F >
tmayFunc< FaccessFunc (const nchar *name)
 
void rel ()
 

상세한 설명

Dynamic library loading and management class

Abbreviation for "dynamic loading for library". Handles platform-independent dynamic loading. Can load libraries into memory and find functions to convert them into function pointers.

Usage follows these steps:

  1. Create dlib object
  2. Specify the location of the library to load
  3. Find desired function by name and get it as function pointer
Remarks
Requires familiarity with tmay Uses tmay, so it's recommended to familiarize yourself with tmay beforehand.
RAII idiom dlib is implemented using RAII idiom. When the instance is destroyed, function pointers returned externally become unusable.

Usage

Example showing the complete process of loading a dynamic library and calling a function. Note that rel() explicitly releases resources. When an error occurs, the comma operator (rel(), false) is used to clean up the dlib object before returning:

dlib lib = dlib(path); // Performs steps 1 and 2 simultaneously
auto res = lib.load(); // `res` evaluated as true when it has an error
WHEN(res).err("couldn't open %s pod: %d", path, res.get())
.ret((rel(), false));
// Release resources with rel() first, then return false via comma operator
typedef void (*entrypointFunc)(bicontainable*);
constexpr const nchar* ENTRYPOINT_NAME = "byeol_bridge_cpp_entrypoint";
auto info = lib.accessFunc<entrypointFunc>(ENTRYPOINT_NAME); // Result as tmay
WHEN(!info.has()) // Checking result with tmay's has()
.err("couldn't access entrypoint of %s pod: %d", path, info.getErr())
.ret((rel(), false));
(*info)(&tray); // If function is successfully retrieved, it can be called
// Memory is automatically released when lib is destroyed
Dynamic library loading and management class
Definition dlib.hpp:63
Rich logging support with polymorphic type conversion
Definition richLog.hpp:34

멤버 함수 문서화

◆ accessFunc()

template<typename F >
tmayFunc< F > by::dlib::accessFunc ( const std::string & name)
inline

Accesses function by name and returns typed function pointer

반환값
tres containing function pointer on success, or error message on failure
주의
Library must be loaded first. Uses GetProcAddress on Windows, dlsym on POSIX. Automatically calls rel() on failure.

◆ load()

tmay< std::string > by::dlib::load ( )

Loads dynamic library into memory

반환값
Empty tmay on success, or error message on failure
주의
Uses LoadLibraryA on Windows, dlopen(RTLD_LAZY) on POSIX. Automatically calls rel() on failure.

이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: