openMSX
BooleanSetting.cc
Go to the documentation of this file.
1 #include "BooleanSetting.hh"
2 #include "Completer.hh"
3 
4 namespace openmsx {
5 
7  CommandController& commandController_, std::string_view name,
8  std::string_view description_, bool initialValue, SaveSetting save_)
9  : Setting(commandController_, name, description_,
10  TclObject(toString(initialValue)), save_)
11 {
12  auto& interp = getInterpreter();
13  setChecker([&interp](TclObject& newValue) {
14  // May throw.
15  // Re-set the queried value to get a normalized value.
16  newValue = toString(newValue.getBoolean(interp));
17  });
18  init();
19 }
20 
21 std::string_view BooleanSetting::getTypeString() const
22 {
23  return "boolean";
24 }
25 
26 void BooleanSetting::tabCompletion(std::vector<std::string>& tokens) const
27 {
28  static constexpr const char* const values[] = {
29  "true", "on", "yes",
30  "false", "off", "no",
31  };
32  Completer::completeString(tokens, values, false); // case insensitive
33 }
34 
35 
36 } // namespace openmsx
openmsx::Setting::getInterpreter
Interpreter & getInterpreter() const
Definition: Setting.cc:162
openmsx::CommandController
Definition: CommandController.hh:18
openmsx::TclObject::getBoolean
bool getBoolean(Interpreter &interp) const
Definition: TclObject.cc:82
openmsx::Setting
Definition: Setting.hh:120
BooleanSetting.hh
openmsx::Completer::completeString
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
Definition: Completer.hh:125
openmsx::BooleanSetting::tabCompletion
void tabCompletion(std::vector< std::string > &tokens) const override
Complete a partly typed value.
Definition: BooleanSetting.cc:26
view::values
auto values(Map &&map)
Definition: view.hh:317
openmsx::Setting::init
void init()
Definition: Setting.cc:54
openmsx::Setting::SaveSetting
SaveSetting
Definition: Setting.hh:125
openmsx::BooleanSetting::getTypeString
std::string_view getTypeString() const override
Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an ...
Definition: BooleanSetting.cc:21
openmsx::TclObject
Definition: TclObject.hh:22
openmsx::Setting::setChecker
void setChecker(std::function< void(TclObject &)> checkFunc_)
Set value-check-callback.
Definition: Setting.hh:152
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::BooleanSetting::BooleanSetting
BooleanSetting(CommandController &commandController, std::string_view name, std::string_view description, bool initialValue, SaveSetting save=SAVE)
Definition: BooleanSetting.cc:6
Completer.hh