openMSX
SettingsManager.hh
Go to the documentation of this file.
1 #ifndef SETTINGSMANAGER_HH
2 #define SETTINGSMANAGER_HH
3 
4 #include "Command.hh"
5 #include "InfoTopic.hh"
6 #include "Setting.hh"
7 #include "hash_set.hh"
8 #include "string_view.hh"
9 #include "TclObject.hh"
10 
11 namespace openmsx {
12 
13 class GlobalCommandController;
14 class XMLElement;
15 
19 {
20 public:
21  SettingsManager(const SettingsManager&) = delete;
22  SettingsManager& operator=(const SettingsManager&) = delete;
23 
24  explicit SettingsManager(GlobalCommandController& commandController);
26 
30  BaseSetting* findSetting(string_view name) const;
31  BaseSetting* findSetting(string_view prefix, string_view baseName) const;
32 
33  void loadSettings(const XMLElement& config);
34 
35  void registerSetting (BaseSetting& setting);
36  void unregisterSetting(BaseSetting& setting);
37 
38 private:
39  BaseSetting& getByName(string_view cmd, string_view name) const;
40  std::vector<std::string> getTabSettingNames() const;
41 
42  struct SettingInfo final : InfoTopic {
43  explicit SettingInfo(InfoCommand& openMSXInfoCommand);
44  void execute(span<const TclObject> tokens,
45  TclObject& result) const override;
46  std::string help(const std::vector<std::string>& tokens) const override;
47  void tabCompletion(std::vector<std::string>& tokens) const override;
48  } settingInfo;
49 
50  struct SetCompleter final : CommandCompleter {
51  explicit SetCompleter(CommandController& commandController);
52  std::string help(const std::vector<std::string>& tokens) const override;
53  void tabCompletion(std::vector<std::string>& tokens) const override;
54  } setCompleter;
55 
56  class SettingCompleter final : public CommandCompleter {
57  public:
58  SettingCompleter(CommandController& commandController,
59  SettingsManager& manager,
60  const std::string& name);
61  std::string help(const std::vector<std::string>& tokens) const override;
62  void tabCompletion(std::vector<std::string>& tokens) const override;
63  private:
64  SettingsManager& manager;
65  };
66  SettingCompleter incrCompleter;
67  SettingCompleter unsetCompleter;
68 
69  struct NameFromSetting {
70  const TclObject& operator()(BaseSetting* s) const {
71  return s->getFullNameObj();
72  }
73  };
75 };
76 
77 } // namespace openmsx
78 
79 #endif
const TclObject & getFullNameObj() const
Get the name of this setting.
Definition: Setting.hh:32
void unregisterSetting(BaseSetting &setting)
Definition: span.hh:34
void loadSettings(const XMLElement &config)
Manages all settings.
SettingsManager & operator=(const SettingsManager &)=delete
void registerSetting(BaseSetting &setting)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
SettingsManager(const SettingsManager &)=delete
BaseSetting * findSetting(string_view name) const
Find the setting with given name.