libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
library.hpp
1#pragma once
2
3#include "../core/string.hpp"
4#include <functional>
5
6namespace z {
7namespace file {
16class library {
17 void *lib_ptr;
18 void *getRawSymbol(const zpath &symbolName) noexcept;
19
20public:
24 library() noexcept;
25
29 ~library() noexcept;
30
41 bool load(const zpath &fileName, bool autoExtension = true) noexcept;
42
49 bool unload() noexcept;
50
59 bool good() noexcept;
60
69 bool bad() noexcept;
70
83 template <typename T>
84 T *symbol(const zpath &symbolName) noexcept {
85 return reinterpret_cast<T *>(getRawSymbol(symbolName));
86 }
87
110 template <typename T>
111 std::function<T> function(const zpath &symbolName) noexcept {
112 return std::function<T>(reinterpret_cast<T *>(getRawSymbol(symbolName)));
113 }
114};
115} // namespace file
116} // namespace z
A class for loading dynamic libraries.
Definition library.hpp:16
bool unload() noexcept
Unload the dynamic library.
bool good() noexcept
Get whether the library has been loaded.
library() noexcept
Default empty constructor.
bool load(const zpath &fileName, bool autoExtension=true) noexcept
Load a dynamic library with the given file name.
bool bad() noexcept
Get whether the library has not been loaded.
std::function< T > function(const zpath &symbolName) noexcept
Get a pointer to the function with the given name.
Definition library.hpp:111
T * symbol(const zpath &symbolName) noexcept
Get a pointer to the symbol with the given name.
Definition library.hpp:84