Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
DynLib.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Core module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_DYNLIB_HPP
8 #define NAZARA_DYNLIB_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/MovablePtr.hpp>
12 #include <Nazara/Core/String.hpp>
13 
14 #if defined(NAZARA_PLATFORM_WINDOWS)
15  #define NAZARA_DYNLIB_EXTENSION ".dll"
16 #elif defined(NAZARA_PLATFORM_LINUX)
17  #define NAZARA_DYNLIB_EXTENSION ".so"
18 #elif defined(NAZARA_PLATFORM_MACOSX)
19  #define NAZARA_DYNLIB_EXTENSION ".dynlib"
20 #else
21  #error OS not handled
22 #endif
23 
24 #if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DYNLIB
25  #include <Nazara/Core/ThreadSafety.hpp>
26 #else
27  #include <Nazara/Core/ThreadSafetyOff.hpp>
28 #endif
29 
30 namespace Nz
31 {
32  using DynLibFunc = int (*)(); // "Generic" type of pointer to function
33 
34  class DynLibImpl;
35 
36  class NAZARA_CORE_API DynLib
37  {
38  public:
39  DynLib();
40  DynLib(const DynLib&) = delete;
41  DynLib(DynLib&&) noexcept = default;
42  ~DynLib();
43 
44  String GetLastError() const;
45  DynLibFunc GetSymbol(const String& symbol) const;
46 
47  bool IsLoaded() const;
48 
49  bool Load(const String& libraryPath);
50  void Unload();
51 
52  DynLib& operator=(const DynLib&) = delete;
53  DynLib& operator=(DynLib&& lib) noexcept = default;
54 
55  private:
56  NazaraMutexAttrib(m_mutex, mutable)
57 
58  mutable String m_lastError;
60  };
61 }
62 
63 #endif // NAZARA_DYNLIB_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Core class that represents a string.
Definition: String.hpp:22
Core class that represents a dynamic library loader.
Definition: DynLib.hpp:36