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 "noncopyable.hh"
6 #include "string_ref.hh"
7 #include <vector>
8 #include <memory>
9 
10 namespace openmsx {
11 
12 class Setting;
13 
14 class UserSettings : private noncopyable
15 {
16 public:
17  using Settings = std::vector<std::unique_ptr<Setting>>;
18 
19  explicit UserSettings(CommandController& commandController);
20 
21  void addSetting(std::unique_ptr<Setting> setting);
22  void deleteSetting(Setting& setting);
23  Setting* findSetting(string_ref name) const;
24  const Settings& getSettings() const { return settings; }
25 
26 private:
27  class Cmd final : public Command {
28  public:
29  Cmd(CommandController& commandController);
30  void execute(array_ref<TclObject> tokens,
31  TclObject& result) override;
32  std::string help(const std::vector<std::string>& tokens) const override;
33  void tabCompletion(std::vector<std::string>& tokens) const override;
34 
35  private:
36  void create (array_ref<TclObject> tokens, TclObject& result);
37  void destroy(array_ref<TclObject> tokens, TclObject& result);
38  void info (array_ref<TclObject> tokens, TclObject& result);
39 
40  std::unique_ptr<Setting> createString (array_ref<TclObject> tokens);
41  std::unique_ptr<Setting> createBoolean(array_ref<TclObject> tokens);
42  std::unique_ptr<Setting> createInteger(array_ref<TclObject> tokens);
43  std::unique_ptr<Setting> createFloat (array_ref<TclObject> tokens);
44 
45  std::vector<string_ref> getSettingNames() const;
46  } userSettingCommand;
47 
48  Settings settings;
49 };
50 
51 } // namespace openmsx
52 
53 #endif
std::vector< std::unique_ptr< Setting >> Settings
Definition: UserSettings.hh:17
void addSetting(std::unique_ptr< Setting > setting)
Definition: UserSettings.cc:27
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void deleteSetting(Setting &setting)
Definition: UserSettings.cc:33
const Settings & getSettings() const
Definition: UserSettings.hh:24
UserSettings(CommandController &commandController)
Definition: UserSettings.cc:22
unique_ptr< IDEDevice > create(const DeviceConfig &config)
Based on boost::noncopyable, see boost documentation: http://www.boost.org/libs/utility.
Definition: noncopyable.hh:12
Setting * findSetting(string_ref name) const
Definition: UserSettings.cc:39