RuntimeLibraryLoader.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-09-06
  6. * Changed: 2022-10-20
  7. *
  8. * */
  9. #ifndef LS_STD_RUNTIME_LIBRARY_LOADER_HPP
  10. #define LS_STD_RUNTIME_LIBRARY_LOADER_HPP
  11. #include "RuntimeLibraryLoaderParameter.hpp"
  12. #include <unordered_map>
  13. namespace ls::std::os
  14. {
  15. class RuntimeLibraryLoader
  16. {
  17. public:
  18. explicit RuntimeLibraryLoader(ls::std::os::RuntimeLibraryLoaderParameter _parameter); // TODO: rename class to RuntimeLibrary? Should there be a validator check for file extensions?
  19. ~RuntimeLibraryLoader() = default;
  20. bool close();
  21. void* getSymbol(const ::std::string& _symbolName);
  22. bool hasSymbol(const ::std::string& _symbolName);
  23. bool loadSymbol(const ::std::string& _symbolName);
  24. bool open();
  25. private:
  26. #if defined(unix) || defined(__APPLE__)
  27. void* handle{};
  28. #endif
  29. ls::std::os::RuntimeLibraryLoaderParameter parameter{};
  30. #if defined(unix) || defined(__APPLE__)
  31. ::std::unordered_map<::std::string, void*> symbols{};
  32. #endif
  33. #if defined(unix) || defined(__APPLE__)
  34. [[nodiscard]] bool _close();
  35. [[nodiscard]] void* _getSymbolUnix(const ::std::string& _symbolName);
  36. [[nodiscard]] bool _hasSymbolUnix(const ::std::string& _symbolName);
  37. [[nodiscard]] bool _loadSymbolUnix(const ::std::string& _symbolName);
  38. [[nodiscard]] bool _openUnix();
  39. #endif
  40. #ifdef _WIN32
  41. bool _openWindows();
  42. #endif
  43. };
  44. }
  45. #endif