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 "string_view.hh"
6 #include <vector>
7 #include <memory>
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(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<string_view> getSettingNames() const;
45  } userSettingCommand;
46 
47  Settings settings; // unordered
48 };
49 
50 } // namespace openmsx
51 
52 #endif
void addSetting(std::unique_ptr< Setting > setting)
Definition: UserSettings.cc:30
Definition: span.hh:34
Setting * findSetting(string_view name) const
Definition: UserSettings.cc:42
const Settings & getSettings() const
Definition: UserSettings.hh:23
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void deleteSetting(Setting &setting)
Definition: UserSettings.cc:36
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
UserSettings(CommandController &commandController)
Definition: UserSettings.cc:25
std::vector< std::unique_ptr< Setting > > Settings
Definition: UserSettings.hh:16
std::unique_ptr< IDEDevice > create(const DeviceConfig &config)