45 explicit DLHandler(
const char *filename,
int flags = RTLD_NOW) {
47 static_cast<void>(flags);
48 HMODULE dl = LoadLibrary(filename);
50 throw std::runtime_error(
"LoadLibrary - error: " + GetLastError());
51 handle.reset(dl, FreeLibrary);
52#elif defined(__APPLE__) || defined(__linux__) || defined(__unix)
53 void *dl = ::dlopen(filename, flags);
55 throw std::runtime_error(::dlerror());
56 handle.reset(dl, ::dlclose);
58#error("Unsupported operating system")
65 explicit DLHandler(
const std::string &filename,
int flags = RTLD_NOW)
71 explicit DLHandler(
const std::filesystem::path &filename,
81 throw std::runtime_error(
82 "An error occurred while accessing the dynamic library");
86 *(
void **)(&symbol) = (
void *)GetProcAddress(handle.get(), name);
87#elif defined(__APPLE__) || defined(__linux__) || defined(__unix)
88 *(
void **)(&symbol) = ::dlsym(handle.get(), name);
91 throw std::runtime_error(
92 "An error occurred while getting the symbol from the dynamic library");
98 operator bool()
const {
return (
bool)handle; }
103 std::shared_ptr<std::remove_pointer<HMODULE>::type> handle;
104#elif defined(__APPLE__) || defined(__linux__) || defined(__unix)
105 std::shared_ptr<void> handle;
115 std::map<std::string, std::shared_ptr<DLHandler>>
libraries;
Dynamic library handler.
Definition dlloader.hpp:34
DLHandler(const char *filename, int flags=RTLD_NOW)
Constructor from file.
Definition dlloader.hpp:45
DLHandler()=delete
Default constructor deleted.
DLHandler(const DLHandler &)=delete
DLHandler(const std::filesystem::path &filename, int flags=RTLD_NOW)
Provides the DLHandler operation.
Definition dlloader.hpp:71
DLHandler(const std::string &filename, int flags=RTLD_NOW)
Provides the DLHandler operation.
Definition dlloader.hpp:65
void * getSymbol(const char *name) const
Gets symbol from dynamic library.
Definition dlloader.hpp:79
DLHandler(DLHandler &&)=delete
Dynamic library loader.
Definition dlloader.hpp:112
std::map< std::string, std::shared_ptr< DLHandler > > libraries
List of dynamic libraries.
Definition dlloader.hpp:115
Full qualified name descriptor.
Definition fqn.hpp:22