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_;
53 string path_;
54
55private:
60 void open();
61
65 void close();
66
67public:
73 explicit dynamic_library(string pth);
74
76
77 dynamic_library(const dynamic_library&) = delete;
78 dynamic_library& operator=(const dynamic_library&) = delete;
79
85
92
100 template <typename T>
101 T to_symbol(const string& name) const {
102 return reinterpret_cast<T>(symbol(name));
103 }
104
111 NEFORCE_NODISCARD void* symbol(const string& name) const;
112
118 NEFORCE_NODISCARD bool has_symbol(const string& name) const noexcept;
119
124 NEFORCE_NODISCARD bool is_open() const noexcept { return handle_ != nullptr; }
125
129 void unload() { close(); }
130
135 NEFORCE_NODISCARD void* native_handle() const noexcept { return handle_; }
136
141 NEFORCE_NODISCARD const string& path() const noexcept { return path_; }
142};
143 // DynamicLibrary
145
146NEFORCE_END_NAMESPACE__
147#endif // NEFORCE_PLUGIN_DYNAMIC_LIBRARY_HPP__
NEFORCE_NODISCARD bool has_symbol(const string &name) const noexcept
检查符号是否存在
void unload()
卸载动态库
NEFORCE_NODISCARD void * symbol(const string &name) const
获取原始符号地址
dynamic_library(string pth)
构造函数,打开指定的动态库
NEFORCE_NODISCARD bool is_open() const noexcept
检查动态库是否已加载
T to_symbol(const string &name) const
获取符号
NEFORCE_NODISCARD void * native_handle() const noexcept
获取原生句柄
NEFORCE_NODISCARD const string & path() const noexcept
获取库文件路径
dynamic_library & operator=(dynamic_library &&other) noexcept
移动赋值运算符
dynamic_library(dynamic_library &&other) noexcept
移动构造函数
NEFORCE_ALWAYS_INLINE_INLINE bool name(char *buffer, size_t size)
获取当前线程名称
字符串类型别名和实用函数
exception(const char *info=static_type, const char *type=static_type, const int code=0)
构造函数
NEFORCE_NODISCARD int code() const noexcept
获取异常码
NEFORCE_NODISCARD const char * type() const noexcept
获取异常类型