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
25 class _nout dlib {
26 BY(ME(dlib))
27
28 public:
29 public:
30 dlib();
31 dlib(const char* path);
32 dlib(const std::string& path);
33 dlib(const me& rhs);
34 virtual ~dlib();
35
36 public:
37 me& operator=(const me& rhs);
38
39 public:
40 const std::string& getPath() const;
41 void setPath(const std::string& path);
42 void setPath(const std::string* it) BY_SIDE_FUNC(setPath);
43
47 nbool isLoaded() const;
48
51 template <typename F> tmayFunc<F> accessFunc(const std::string& name) { return accessFunc<F>(name.c_str()); }
52
53 template <typename F> tmayFunc<F> accessFunc(const std::string* it) BY_SIDE_FUNC(accessFunc<F>);
54
55 template <typename F> tmayFunc<F> accessFunc(const nchar* name) {
56 auto&& res = _accessFunc(name);
57 return res.has() ? tmayFunc<F>((F&) *res) : tmayFunc<F>(res.getErr());
58 }
59
60 void rel();
61
62 private:
63 tmayFunc<void*> _accessFunc(const nchar* name);
64
65 private:
66 std::string _path;
67 dlibHandle _handle;
68 };
69
70 typedef std::vector<dlib> dlibs;
71} // namespace by
Dynamic library loading and management class.
Definition: dlib.hpp:25
tmay< std::string > load()
tmayFunc< F > accessFunc(const std::string &name)
Definition: dlib.hpp:51
Optional value wrapper with byeol-style interface.
Definition: tmay.hpp:18
Template result container with error handling capabilities.
Definition: tres.hpp:13