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 <memory>
6 #include <string_view>
7 #include <vector>
8 
9 namespace openmsx {
10 
11 class Setting;
12 
14 {
15 public:
16  struct Info {
17  std::unique_ptr<Setting> setting;
18  StringStorage description; // because setting doesn't take ownership
19  };
20  using Settings = std::vector<Info>;
21 
22  explicit UserSettings(CommandController& commandController);
23 
24  void addSetting(Info&& info);
26  [[nodiscard]] Setting* findSetting(std::string_view name) const;
27  [[nodiscard]] const Settings& getSettingsInfo() const { return settings; }
28 
29 private:
30  class Cmd final : public Command {
31  public:
32  explicit Cmd(CommandController& commandController);
33  void execute(span<const TclObject> tokens,
34  TclObject& result) override;
35  [[nodiscard]] std::string help(span<const TclObject> tokens) const override;
36  void tabCompletion(std::vector<std::string>& tokens) const override;
37 
38  private:
39  void create (span<const TclObject> tokens, TclObject& result);
40  void destroy(span<const TclObject> tokens, TclObject& result);
41  void info (span<const TclObject> tokens, TclObject& result);
42 
43  [[nodiscard]] Info createString (span<const TclObject> tokens);
44  [[nodiscard]] Info createBoolean(span<const TclObject> tokens);
45  [[nodiscard]] Info createInteger(span<const TclObject> tokens);
46  [[nodiscard]] Info createFloat (span<const TclObject> tokens);
47  [[nodiscard]] Info createEnum (span<const TclObject> tokens);
48 
49  [[nodiscard]] std::vector<std::string_view> getSettingNames() const;
50  } userSettingCommand;
51 
52  Settings settings; // unordered
53 };
54 
55 } // namespace openmsx
56 
57 #endif
BaseSetting * setting
Definition: Interpreter.cc:30
std::unique_ptr< char, FreeStringStorage > StringStorage
void deleteSetting(Setting &setting)
Definition: UserSettings.cc:36
void addSetting(Info &&info)
Definition: UserSettings.cc:30
Setting * findSetting(std::string_view name) const
Definition: UserSettings.cc:42
UserSettings(CommandController &commandController)
Definition: UserSettings.cc:25
const Settings & getSettingsInfo() const
Definition: UserSettings.hh:27
std::vector< Info > Settings
Definition: UserSettings.hh:20
Definition: span.hh:126
std::unique_ptr< IDEDevice > create(const DeviceConfig &config)
This file implemented 3 utility functions:
Definition: Autofire.cc:9
std::unique_ptr< Setting > setting
Definition: UserSettings.hh:17