openMSX
UserSettings.hh
Go to the documentation of this file.
1#ifndef USERSETTINGS_HH
2#define USERSETTINGS_HH
3
4#include "Command.hh"
5#include "outer.hh"
6#include "view.hh"
7#include <memory>
8#include <string_view>
9#include <vector>
10
11namespace openmsx {
12
13class Setting;
14
16{
17public:
18 struct Info {
19 std::unique_ptr<Setting> setting;
20 StringStorage description; // because setting doesn't take ownership
21 };
22 using Settings = std::vector<Info>;
23
24 explicit UserSettings(CommandController& commandController);
25
26 void addSetting(Info&& info);
28 [[nodiscard]] Setting* findSetting(std::string_view name) const;
29
30private:
31 class Cmd final : public Command {
32 public:
33 explicit Cmd(CommandController& commandController);
34 void execute(std::span<const TclObject> tokens,
35 TclObject& result) override;
36 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
37 void tabCompletion(std::vector<std::string>& tokens) const override;
38
39 private:
40 void create (std::span<const TclObject> tokens, TclObject& result);
41 void destroy(std::span<const TclObject> tokens, TclObject& result);
42 void info (std::span<const TclObject> tokens, TclObject& result);
43
44 [[nodiscard]] Info createString (std::span<const TclObject> tokens);
45 [[nodiscard]] Info createBoolean(std::span<const TclObject> tokens);
46 [[nodiscard]] Info createInteger(std::span<const TclObject> tokens);
47 [[nodiscard]] Info createFloat (std::span<const TclObject> tokens);
48 [[nodiscard]] Info createEnum (std::span<const TclObject> tokens);
49
50 [[nodiscard]] auto getSettingNames() const {
51 return view::transform(
52 OUTER(UserSettings, userSettingCommand).settings,
53 [](const auto& info) { return info.setting->getFullName(); });
54 }
55 } userSettingCommand;
56
57 Settings settings; // unordered
58};
59
60} // namespace openmsx
61
62#endif
BaseSetting * setting
Definition: Interpreter.cc:28
std::unique_ptr< char, FreeStringStorage > StringStorage
void deleteSetting(Setting &setting)
Definition: UserSettings.cc:31
void addSetting(Info &&info)
Definition: UserSettings.cc:25
Setting * findSetting(std::string_view name) const
Definition: UserSettings.cc:37
UserSettings(CommandController &commandController)
Definition: UserSettings.cc:20
std::vector< Info > Settings
Definition: UserSettings.hh:22
std::unique_ptr< IDEDevice > create(const DeviceConfig &config)
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr auto transform(Range &&range, UnaryOp op)
Definition: view.hh:458
#define OUTER(type, member)
Definition: outer.hh:41
std::unique_ptr< Setting > setting
Definition: UserSettings.hh:19