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  using Settings = std::vector<std::unique_ptr<Setting>>;
17 
18  explicit UserSettings(CommandController& commandController);
19 
20  void addSetting(std::unique_ptr<Setting> setting);
21  void deleteSetting(Setting& setting);
22  Setting* findSetting(std::string_view name) const;
23  const Settings& getSettings() const { return settings; }
24 
25 private:
26  class Cmd final : public Command {
27  public:
28  explicit Cmd(CommandController& commandController);
29  void execute(span<const TclObject> tokens,
30  TclObject& result) override;
31  std::string help(const std::vector<std::string>& tokens) const override;
32  void tabCompletion(std::vector<std::string>& tokens) const override;
33 
34  private:
35  void create (span<const TclObject> tokens, TclObject& result);
36  void destroy(span<const TclObject> tokens, TclObject& result);
37  void info (span<const TclObject> tokens, TclObject& result);
38 
39  std::unique_ptr<Setting> createString (span<const TclObject> tokens);
40  std::unique_ptr<Setting> createBoolean(span<const TclObject> tokens);
41  std::unique_ptr<Setting> createInteger(span<const TclObject> tokens);
42  std::unique_ptr<Setting> createFloat (span<const TclObject> tokens);
43 
44  std::vector<std::string_view> getSettingNames() const;
45  } userSettingCommand;
46 
47  Settings settings; // unordered
48 };
49 
50 } // namespace openmsx
51 
52 #endif
openmsx::CommandController
Definition: CommandController.hh:17
openmsx::UserSettings::findSetting
Setting * findSetting(std::string_view name) const
Definition: UserSettings.cc:42
openmsx::UserSettings::UserSettings
UserSettings(CommandController &commandController)
Definition: UserSettings.cc:25
openmsx::UserSettings::Settings
std::vector< std::unique_ptr< Setting > > Settings
Definition: UserSettings.hh:16
openmsx::UserSettings
Definition: UserSettings.hh:13
openmsx::Setting
Definition: Setting.hh:119
span
Definition: span.hh:34
openmsx::IDEDeviceFactory::create
std::unique_ptr< IDEDevice > create(const DeviceConfig &config)
Definition: IDEDeviceFactory.cc:11
openmsx::UserSettings::deleteSetting
void deleteSetting(Setting &setting)
Definition: UserSettings.cc:36
Command.hh
openmsx::Command
Definition: Command.hh:40
openmsx::TclObject
Definition: TclObject.hh:21
openmsx::UserSettings::addSetting
void addSetting(std::unique_ptr< Setting > setting)
Definition: UserSettings.cc:30
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::UserSettings::getSettings
const Settings & getSettings() const
Definition: UserSettings.hh:23