NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
dynamic_library.hpp
浏览该文件的文档.
1#ifndef NEFORCE_PLUGIN_DYNAMIC_LIBRARY_HPP__
2#define NEFORCE_PLUGIN_DYNAMIC_LIBRARY_HPP__
3
10
12NEFORCE_BEGIN_NAMESPACE__
13
19
24struct dynamic_library_exception final : system_exception {
25 explicit dynamic_library_exception(const char* info = "Dynamic Library Operation Failed.",
26 const char* type = static_type, const int code = 0) noexcept :
27 system_exception(info, type, code) {}
28
29 explicit dynamic_library_exception(const exception& e) :
30 system_exception(e) {}
31
32 ~dynamic_library_exception() override = default;
33 static constexpr auto static_type = "dynamic_library_exception";
34};
35 // Exceptions
37
43
50class NEFORCE_API dynamic_library {
51private:
52 void* handle_{nullptr};
53 string path_;
54
55private:
56 void open();
57 void close();
58
59public:
65 explicit dynamic_library(string pth);
66
68
69 dynamic_library(const dynamic_library&) = delete;
70 dynamic_library& operator=(const dynamic_library&) = delete;
71
77
84
92 template <typename T>
93 T to_symbol(const string& name) const {
94 return reinterpret_cast<T>(symbol(name));
95 }
96
103 NEFORCE_NODISCARD void* symbol(const string& name) const;
104
110 NEFORCE_NODISCARD bool has_symbol(const string& name) const noexcept;
111
116 NEFORCE_NODISCARD bool is_open() const noexcept { return handle_ != nullptr; }
117
121 void unload() { close(); }
122
127 NEFORCE_NODISCARD void* native_handle() const noexcept { return handle_; }
128
133 NEFORCE_NODISCARD const string& path() const noexcept { return path_; }
134};
135 // DynamicLibrary
137
138NEFORCE_END_NAMESPACE__
139#endif // NEFORCE_PLUGIN_DYNAMIC_LIBRARY_HPP__
void unload()
卸载动态库
void * symbol(const string &name) const
获取原始符号地址
bool has_symbol(const string &name) const noexcept
检查符号是否存在
dynamic_library(string pth)
构造函数,打开指定的动态库
T to_symbol(const string &name) const
获取符号
dynamic_library & operator=(dynamic_library &&other) noexcept
移动赋值运算符
bool is_open() const noexcept
检查动态库是否已加载
dynamic_library(dynamic_library &&other) noexcept
移动构造函数
void * native_handle() const noexcept
获取原生句柄
const string & path() const noexcept
获取库文件路径
bool name(char *buffer, size_t size)
获取当前线程名称
字符串类型别名和实用函数
exception(const char *info=static_type, const char *type=static_type, const int code=0)
构造函数
const char * type() const noexcept
获取异常类型
int code() const noexcept
获取异常码