Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarDynamicLib.hpp
blob: 47957865069ba73bce260f0035c4fb49bb024492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once

#include "StarString.hpp"

namespace Star {

STAR_CLASS(DynamicLib);

class DynamicLib {
public:
  // Returns the library extension normally used on the current platform
  // including the '.', e.g.  '.dll', '.so', '.dylib'
  static String libraryExtension();

  // Load a dll from the given filename.  If the library is found and
  // succesfully loaded, returns a handle to the library, otherwise nullptr.
  static DynamicLibUPtr loadLibrary(String const& fileName);

  // Load a dll from the given name, minus extension.
  static DynamicLibUPtr loadLibraryBase(String const& baseName);

  // Should return handle to currently running executable.  Will always
  // succeed.
  static DynamicLibUPtr currentExecutable();

  virtual ~DynamicLib() = default;

  virtual void* funcPtr(char const* name) = 0;
};

inline DynamicLibUPtr DynamicLib::loadLibraryBase(String const& baseName) {
  return loadLibrary(baseName + libraryExtension());
}

}