plugify 1.0.0.0
Loading...
Searching...
No Matches
module.hpp
1#pragma once
2
3#include <cstdint>
4#include <optional>
5
6#include "handle.hpp"
7#include "path.hpp"
8
9#include <plugify_export.h>
10
11namespace plugify {
12 class Module;
13 class LanguageModuleDescriptorHandle;
14
22 enum class ModuleState {
23 NotLoaded,
24 Error,
25 Loaded,
26 Unknown,
27 };
28
33 using UniqueId = std::ptrdiff_t;
34
39 class PLUGIFY_API ModuleHandle : public Handle<const Module> {
40 using Handle::Handle;
41 public:
46 UniqueId GetId() const noexcept;
47
52 std::string_view GetName() const noexcept;
53
58 std::string_view GetLanguage() const noexcept;
59
64 std::string_view GetFriendlyName() const noexcept;
65
70 std::filesystem::path_view GetFilePath() const noexcept;
71
76 std::filesystem::path_view GetBaseDir() const noexcept;
77
82 LanguageModuleDescriptorHandle GetDescriptor() const noexcept;
83
88 ModuleState GetState() const noexcept;
89
94 std::string_view GetError() const noexcept;
95
117 std::optional<std::filesystem::path_view> FindResource(std::filesystem::path_view path) const;
118 };
119
123 namespace ModuleUtils {
129 constexpr std::string_view ToString(ModuleState state) noexcept {
130 switch (state) {
131 case ModuleState::NotLoaded: return "NotLoaded";
132 case ModuleState::Error: return "Error";
133 case ModuleState::Loaded: return "Loaded";
134 default: return "Unknown";
135 }
136 }
137
143 constexpr ModuleState FromString(std::string_view state) noexcept {
144 if (state == "NotLoaded") {
145 return ModuleState::NotLoaded;
146 } else if (state == "Error") {
147 return ModuleState::Error;
148 } else if (state == "Loaded") {
149 return ModuleState::Loaded;
150 }
151 return ModuleState::Unknown;
152 }
153 } // namespace ModuleUtils
154
155} // namespace plugify
A generic handle class that manages a pointer to an object of type T.
Definition handle.hpp:18
A handle class for the LanguageModuleDescriptor structure.
Handle wrapper to access language module's information.
Definition module.hpp:39
UniqueId GetId() const noexcept
Get the unique identifier of the language module.