plugify  1.0.0.0
module.hpp
1 #pragma once
2 
3 #include <cstdint>
4 #include <optional>
5 #include <plugify/path.hpp>
6 #include <plugify/reference_wrapper.hpp>
7 #include <plugify_export.h>
8 
9 namespace plugify {
10  class Module;
11  class LanguageModuleDescriptorRef;
12 
20  enum class ModuleState : uint8_t {
21  NotLoaded,
22  Error,
23  Loaded,
24  Unknown,
25  };
26 
31  using UniqueId = std::ptrdiff_t;
32 
37  class PLUGIFY_API ModuleRef : public Ref<const Module> {
38  using Ref::Ref;
39  public:
44  UniqueId GetId() const noexcept;
45 
50  std::string_view GetName() const noexcept;
51 
56  std::string_view GetLanguage() const noexcept;
57 
62  std::string_view GetFriendlyName() const noexcept;
63 
68  std::filesystem::path_view GetFilePath() const noexcept;
69 
74  std::filesystem::path_view GetBaseDir() const noexcept;
75 
80  LanguageModuleDescriptorRef GetDescriptor() const noexcept;
81 
86  ModuleState GetState() const noexcept;
87 
92  std::string_view GetError() const noexcept;
93 
115  std::optional<std::filesystem::path_view> FindResource(std::filesystem::path_view path) const;
116  };
117  static_assert(is_ref_v<ModuleRef>);
118 
122  namespace ModuleUtils {
128  [[maybe_unused]] constexpr std::string_view ToString(ModuleState state) noexcept {
129  switch (state) {
130  case ModuleState::NotLoaded: return "NotLoaded";
131  case ModuleState::Error: return "Error";
132  case ModuleState::Loaded: return "Loaded";
133  default: return "Unknown";
134  }
135  }
136 
142  [[maybe_unused]] constexpr ModuleState FromString(std::string_view state) noexcept {
143  if (state == "NotLoaded") {
144  return ModuleState::NotLoaded;
145  } else if (state == "Error") {
146  return ModuleState::Error;
147  } else if (state == "Loaded") {
148  return ModuleState::Loaded;
149  }
150  return ModuleState::Unknown;
151  }
152  } // namespace ModuleUtils
153 
154 } // namespace plugify
A reference class for the LanguageModuleDescriptor structure.
Reference wrapper to access language module's information.
Definition: module.hpp:37
UniqueId GetId() const noexcept
Get the unique identifier of the language module.
A lightweight reference wrapper for objects of type T.