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 
11 namespace openmsx {
12 
13 class Setting;
14 
16 {
17 public:
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 
30 private:
31  class Cmd final : public Command {
32  public:
33  explicit Cmd(CommandController& commandController);
34  void execute(span<const TclObject> tokens,
35  TclObject& result) override;
36  [[nodiscard]] std::string help(span<const TclObject> tokens) const override;
37  void tabCompletion(std::vector<std::string>& tokens) const override;
38 
39  private:
40  void create (span<const TclObject> tokens, TclObject& result);
41  void destroy(span<const TclObject> tokens, TclObject& result);
42  void info (span<const TclObject> tokens, TclObject& result);
43 
44  [[nodiscard]] Info createString (span<const TclObject> tokens);
45  [[nodiscard]] Info createBoolean(span<const TclObject> tokens);
46  [[nodiscard]] Info createInteger(span<const TclObject> tokens);
47  [[nodiscard]] Info createFloat (span<const TclObject> tokens);
48  [[nodiscard]] Info createEnum (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:27
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
Definition: span.hh:126
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:392
#define OUTER(type, member)
Definition: outer.hh:41
std::unique_ptr< Setting > setting
Definition: UserSettings.hh:19