CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
dll.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_SYSTEM_DLL_H
10#define CPPCOMMON_SYSTEM_DLL_H
11
12#include "filesystem/path.h"
13#include "system/exceptions.h"
14
15#include <memory>
16
18
27#if defined(_WIN32) || defined(_WIN64)
28 #ifdef EXPORTS
29 #define EXPORT __declspec(dllexport)
30 #else
31 #define EXPORT __declspec(dllimport)
32 #endif
33#else
34 #define EXPORT
35#endif
36
38
45#define API extern "C" EXPORT
46
47namespace CppCommon {
48
50
55class DLL
56{
57public:
59 DLL();
61
65 DLL(const Path& path, bool load = true);
66 DLL(const DLL& dll);
67 DLL(DLL&& dll) noexcept;
68 ~DLL();
69
70 DLL& operator=(const Path& path);
71 DLL& operator=(const DLL& dll);
72 DLL& operator=(DLL&& dll) noexcept;
73
75 explicit operator bool() const { return IsLoaded(); }
76
78 const Path path() const;
79
81 bool IsLoaded() const;
82
84 bool IsResolve(const std::string& name) const;
85
87
90 bool Load();
92
96 bool Load(const Path& path);
97
99
103 void Unload();
104
106
110 template <typename T>
111 T* Resolve(const std::string& name) const;
112
114
123 static std::string prefix();
125
132 static std::string extension();
133
135 void swap(DLL& dll) noexcept;
136 friend void swap(DLL& dll1, DLL& dll2) noexcept;
137
138private:
139 class Impl;
140
141 Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
142 const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
143
144 static const size_t StorageSize = 48;
145 static const size_t StorageAlign = 8;
146 alignas(StorageAlign) std::byte _storage[StorageSize];
147
149
153 void* ResolveAddress(const std::string& name) const;
154};
155
158} // namespace CppCommon
159
160#include "dll.inl"
161
162#endif // CPPCOMMON_SYSTEM_DLL_H
Dynamic link library.
Definition dll.h:56
static std::string extension()
Get the dynamic link library extension.
Definition dll.inl:28
DLL & operator=(const Path &path)
Definition dll.cpp:206
friend void swap(DLL &dll1, DLL &dll2) noexcept
Definition dll.inl:41
T * Resolve(const std::string &name) const
Resolve dynamic link library symbol by the given name.
Definition dll.inl:12
static std::string prefix()
Get the dynamic link library prefix.
Definition dll.inl:17
bool IsResolve(const std::string &name) const
Is dynamic link library resolve the given symbol?
Definition dll.cpp:227
bool Load()
Load dynamic link library.
Definition dll.cpp:229
void Unload()
Unload dynamic link library.
Definition dll.cpp:231
DLL()
Initialize the dynamic link library with an empty path.
Definition dll.cpp:147
const Path path() const
Get the dynamic link library path.
Definition dll.cpp:224
bool IsLoaded() const
Is dynamic link library loaded?
Definition dll.cpp:226
Filesystem path.
Definition path.h:90
Dynamic link library inline implementation.
C++ Common project definitions.
Filesystem path definition.