Loading...
Searching...
No Matches
dlib.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "indep/common.hpp"
5#include "indep/def.hpp"
6#include "indep/macro.hpp"
7#include "tres.inl"
8#ifdef BY_BUILD_PLATFORM_IS_WINDOWS
9# include <windows.h> // for dll loading
10#endif
11
12namespace by {
13
14#ifdef BY_BUILD_PLATFORM_IS_WINDOWS
15 typedef HMODULE dlibHandle;
16#else
17 typedef void* dlibHandle;
18#endif
19 template <typename F> using tmayFunc = tres<F, std::string>;
20
63 class _nout dlib {
64 BY(ME(dlib))
65
66 public:
67 public:
68 dlib();
69 dlib(const char* path);
70 dlib(const std::string& path);
71 dlib(const me& rhs);
72 virtual ~dlib();
73
74 public:
75 me& operator=(const me& rhs);
76
77 public:
78 const std::string& getPath() const;
79 void setPath(const std::string& path);
80 void setPath(const std::string* it) BY_SIDE_FUNC(setPath);
81
89
90 nbool isLoaded() const;
91
98 template <typename F> tmayFunc<F> accessFunc(const std::string& name) { return accessFunc<F>(name.c_str()); }
99
100 template <typename F> tmayFunc<F> accessFunc(const std::string* it) BY_SIDE_FUNC(accessFunc<F>);
101
102 template <typename F> tmayFunc<F> accessFunc(const nchar* name) {
103 auto&& res = _accessFunc(name);
104 return res.has() ? tmayFunc<F>((F&) *res) : tmayFunc<F>(res.getErr());
105 }
106
107 void rel();
108
109 private:
110 tmayFunc<void*> _accessFunc(const nchar* name);
111
112 private:
113 std::string _path;
114 dlibHandle _handle;
115 };
116
117 typedef std::vector<dlib> dlibs;
118} // namespace by
Dynamic library loading and management class.
Definition dlib.hpp:63
tmay< std::string > load()
Loads dynamic library into memory.
tmayFunc< F > accessFunc(const std::string &name)
Accesses function by name and returns typed function pointer.
Definition dlib.hpp:98
#define BY_SIDE_FUNC(...)
Side function macros for safe pointer operations.
Definition sideFunc.hpp:24
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34