AnnDynamicLibraryHolder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "systemMacro.h"
4 
5 //Include the correct header for the OS
6 #ifdef _WIN32
7 #include <Windows.h>
8 #else
9 #include <dlfcn.h>
10 #endif
11 
12 #include <memory> //std::unique_ptr
13 
14 namespace Annwvyn
15 {
18  {
19  public:
23  void operator=(AnnDynamicLibraryHolder&) = delete;
24 
27  {
28  heldLibrary = other.heldLibrary;
29  other.heldLibrary = nullptr;
30  }
31 
34  {
35  heldLibrary = other.heldLibrary;
36  other.heldLibrary = nullptr;
37  return *this;
38  }
39 
41 #ifdef _WIN32
42  using AnnDynLib = HMODULE;
43 #else
44  using AnnDynLib = void*;
45 #endif
46 
49  {
50  heldLibrary = lib;
51  }
52 
55  {
56  if(heldLibrary)
57 #ifdef _WIN32
58  if(!FreeLibrary(heldLibrary))
59 #else
60  if(dlclose(heldLibrary) != 0)
61 #endif
62  {
63  //TODO report about error now
64  }
65  }
66 
67  private:
69  AnnDynLib heldLibrary = nullptr;
70  };
71 
74 }
file for defining macros used for symbol export regarding the way the OS does things.
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
AnnDynamicLibraryHolder(AnnDynamicLibraryHolder &&other) noexcept
Move constructor.
void * AnnDynLib
Abstract the type of what we are keeping. This type is either HMODULE or void* depending on the host ...
Class that handle the lifetime of a DLL. Automatically call FreeLibrary/dlclose for you...
#define AnnDllExport
Definition: systemMacro.h:24
AnnDynamicLibraryHolder(AnnDynLib lib)
Construct the holder.
AnnDynLib heldLibrary
handle to dll/so that has been loaded in memory
~AnnDynamicLibraryHolder()
Destruct the holder, will FreeLibrary/dlclose the library handle/pointer.
AnnDynamicLibraryHolder & operator=(AnnDynamicLibraryHolder &&other) noexcept
Move-assign operator.