]> granicus.if.org Git - icinga2/blob - lib/base/library.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / library.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef LIBRARY_H
4 #define LIBRARY_H
5
6 #include "base/i2-base.hpp"
7 #include "base/string.hpp"
8 #include <memory>
9
10 namespace icinga
11 {
12
13 #ifndef _WIN32
14 typedef void *LibraryHandle;
15 #else /* _WIN32 */
16 typedef HMODULE LibraryHandle;
17 #endif /* _WIN32 */
18
19 class Library
20 {
21 public:
22         Library() = default;
23         Library(const String& name);
24
25         void *GetSymbolAddress(const String& name) const;
26
27         template<typename T>
28         T GetSymbolAddress(const String& name) const
29         {
30                 static_assert(!std::is_same<T, void *>::value, "T must not be void *");
31
32                 return reinterpret_cast<T>(GetSymbolAddress(name));
33         }
34
35 private:
36         std::shared_ptr<LibraryHandle> m_Handle;
37 };
38
39 }
40
41 #endif /* LIBRARY_H */