ReXGlue SDK
Loading...
Searching...
No Matches
settings_registry.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <filesystem>
15#include <memory>
16#include <string>
17#include <string_view>
18#include <vector>
19
20#include <rex/module.h>
21#include <rex/platform.h>
22#include <rex/result.h>
23#include <rex/types.h>
24#include <rex/setting.h>
25#include <rex/utility.h>
26
27namespace rex {
28
29class ProcessSettingsControl;
30
33 std::string name;
35};
36
44 [[nodiscard]] virtual Result<void> Register(SettingOwner& owner) = 0;
45
49 virtual void Unregister(SettingOwner& owner) = 0;
50
56 [[nodiscard]] virtual Result<SettingBase*> Find(std::string_view name) const = 0;
57
63 virtual std::vector<SettingBase*> Enumerate(std::string_view scope = {}) const = 0;
64
70 virtual std::vector<ConsoleCommand*> EnumerateCommands(std::string_view scope = {}) const = 0;
71
77 [[nodiscard]] virtual Result<void> SetText(std::string_view name, std::string_view text) = 0;
78
86 [[nodiscard]] virtual Result<void> SetText(SettingLayer layer, std::string_view name,
87 std::string_view text) = 0;
88
95 virtual void AddAlias(std::string_view old_name, std::string_view new_name) = 0;
96
103 [[nodiscard]] virtual bool IsAlias(std::string_view name) const = 0;
104
108 [[nodiscard]] virtual Result<void> Reset(std::string_view name) = 0;
109
115 [[nodiscard]] virtual Result<void> Run(std::string_view name, std::string_view args) = 0;
116
118 virtual std::vector<std::string> GetRestartPending() const = 0;
119
125 [[nodiscard]] virtual Result<void> Save(const std::filesystem::path& file) const = 0;
126
133 [[nodiscard]] virtual Result<void> Load(const std::filesystem::path& file,
135};
136
139class REX_API SettingsRegistry final : public ISettingsRegistry {
140 public:
141 [[nodiscard]] Result<void> Register(SettingOwner& owner) override;
142
143 void Unregister(SettingOwner& owner) override;
144
145 [[nodiscard]] Result<SettingBase*> Find(std::string_view name) const override;
146
147 std::vector<SettingBase*> Enumerate(std::string_view scope = {}) const override;
148
149 std::vector<ConsoleCommand*> EnumerateCommands(std::string_view scope = {}) const override;
150
151 [[nodiscard]] Result<void> SetText(std::string_view name, std::string_view text) override;
152
153 [[nodiscard]] Result<void> SetText(SettingLayer layer, std::string_view name,
154 std::string_view text) override;
155
156 void AddAlias(std::string_view old_name, std::string_view new_name) override;
157
158 [[nodiscard]] bool IsAlias(std::string_view name) const override;
159
160 [[nodiscard]] Result<void> Reset(std::string_view name) override;
161
162 [[nodiscard]] Result<void> Run(std::string_view name, std::string_view args) override;
163
164 std::vector<std::string> GetRestartPending() const override;
165
166 [[nodiscard]] Result<void> Save(const std::filesystem::path& file) const override;
167
168 [[nodiscard]] Result<void> Load(const std::filesystem::path& file,
169 SettingLayer layer = SettingLayer::kRuntime) override;
170
171 private:
172 friend REX_API SettingsRegistry& GetSettingsRegistry();
173 friend class ProcessSettingsControl;
174
176 void EndSession();
177
179 void ApplyEnvironment();
180
185 std::vector<std::string> TakeNotices();
186
191 std::vector<UnknownSetting> TakeUnknown();
192
193 SettingsRegistry();
194 ~SettingsRegistry();
195 friend class SettingBase;
196 friend class ConsoleCommand;
197 void Detach(SettingBase& setting);
198 void Detach(ConsoleCommand& command);
199 bool ApplyOldLogFile(SettingLayer layer, std::string_view name, std::string_view text,
200 Result<void>& result);
201
202 struct State;
203 std::unique_ptr<State> state_;
204};
205
206REX_API SettingsRegistry& GetSettingsRegistry();
207
208#define REX_SETTINGS() ::rex::GetSettingsRegistry()
209
210} // namespace rex
Definition settings_registry.h:38
Definition setting.h:249
Definition settings_registry.h:139
std::vector< std::string > GetRestartPending() const override
void AddAlias(std::string_view old_name, std::string_view new_name) override
std::vector< SettingBase * > Enumerate(std::string_view scope={}) const override
Result< void > Save(const std::filesystem::path &file) const override
Result< void > Reset(std::string_view name) override
Result< void > SetText(std::string_view name, std::string_view text) override
Result< void > SetText(SettingLayer layer, std::string_view name, std::string_view text) override
bool IsAlias(std::string_view name) const override
std::vector< ConsoleCommand * > EnumerateCommands(std::string_view scope={}) const override
Result< void > Run(std::string_view name, std::string_view args) override
void Unregister(SettingOwner &owner) override
Result< void > Load(const std::filesystem::path &file, SettingLayer layer=SettingLayer::kRuntime) override
Result< void > Register(SettingOwner &owner) override
Result< SettingBase * > Find(std::string_view name) const override
Interfaces, factory and module declaration.
#define REX_DECLARE_INTERFACE(Name, version)
Definition module.h:114
Definition app.h:36
std::expected< T, Error > Result
Definition result.h:98
SettingLayer
Definition setting.h:50
@ kRuntime
Definition setting.h:56
Platform flags, packing macros and export markers.
#define REX_API
Definition platform.h:177
Typed settings and the owners that declare them.
Definition settings_registry.h:32
std::string name
Definition settings_registry.h:33
SettingLayer layer
Definition settings_registry.h:34
Integer types, byte order wrappers and size literals.
Move only function, const propagating pointer and scope guard.