openMSX
BooleanSetting.hh
Go to the documentation of this file.
1 #ifndef BOOLEANSETTING_HH
2 #define BOOLEANSETTING_HH
3 
4 #include "Setting.hh"
5 
6 namespace openmsx {
7 
8 class BooleanSetting final : public Setting
9 {
10 public:
11  BooleanSetting(CommandController& commandController,
12  string_view name, string_view description,
13  bool initialValue, SaveSetting save = SAVE);
14  string_view getTypeString() const override;
15  void tabCompletion(std::vector<std::string>& tokens) const override;
16 
17  bool getBoolean() const { return getValue().getBoolean(getInterpreter()); }
18  void setBoolean(bool b) { setValue(TclObject(toString(b))); }
19 
20 private:
21  static string_view toString(bool b) { return b ? "true" : "false"; }
22 };
23 
24 } // namespace openmsx
25 
26 #endif
const TclObject & getValue() const final override
Gets the current value of this setting as a TclObject.
Definition: Setting.hh:134
void tabCompletion(std::vector< std::string > &tokens) const override
Complete a partly typed value.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
bool getBoolean(Interpreter &interp) const
Definition: TclObject.cc:119
void setValue(const TclObject &newValue) final override
Change the value of this setting to the given value.
Definition: Setting.cc:89
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:15
string_view getTypeString() const override
Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an ...
Interpreter & getInterpreter() const
Definition: Setting.cc:162
BooleanSetting(CommandController &commandController, string_view name, string_view description, bool initialValue, SaveSetting save=SAVE)