MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
dynamic_library.hpp
1#ifndef MSTL_PLUGIN_DYNAMIC_LIBRARY_HPP__
2#define MSTL_PLUGIN_DYNAMIC_LIBRARY_HPP__
3#include "MSTL/core/string/string.hpp"
5
6MSTL_ERROR_BUILD_FINAL_CLASS(dl_exception, system_exception, "Dynamic Library Operation Failed")
7
8
9class MSTL_API dynamic_library {
10private:
11 void* handle_;
12 string path_;
13
14private:
15 void open();
16 void close();
17
18public:
19 explicit dynamic_library(const string& path);
20 ~dynamic_library();
21
22 dynamic_library(const dynamic_library&) = delete;
23 dynamic_library& operator =(const dynamic_library&) = delete;
24 dynamic_library(dynamic_library&& other) noexcept;
25 dynamic_library& operator =(dynamic_library&& other) noexcept;
26
27 template <typename T>
28 T get_symbol(const string& name) const {
29 return reinterpret_cast<T>(symbol_row(name));
30 }
31
32 MSTL_NODISCARD void* symbol_row(const string& name) const;
33 MSTL_NODISCARD bool has_symbol(const string& name) const noexcept;
34
35 MSTL_NODISCARD bool is_open() const noexcept { return handle_ != nullptr; }
36 void unload() { close(); }
37
38 MSTL_NODISCARD void* native_handle() const noexcept { return handle_; }
39 MSTL_NODISCARD const string& path() const noexcept { return path_; }
40};
41
42
44#endif // MSTL_PLUGIN_DYNAMIC_LIBRARY_HPP__
#define MSTL_ERROR_BUILD_FINAL_CLASS(THIS, BASE, INFO)
构建最终异常类宏
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
系统访问异常