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