openMSX
EnumSetting.cc
Go to the documentation of this file.
1 #include "EnumSetting.hh"
2 #include "TclObject.hh"
3 #include "Completer.hh"
4 #include "CommandException.hh"
5 #include "StringOp.hh"
6 #include "ranges.hh"
7 #include "stl.hh"
8 #include "stringsp.hh"
9 #include "view.hh"
10 #include "unreachable.hh"
11 
12 namespace openmsx {
13 
15  : baseMap(std::move(map))
16 {
18 }
19 
20 int EnumSettingBase::fromStringBase(std::string_view str) const
21 {
22  auto it = ranges::lower_bound(baseMap, str, StringOp::caseless{}, &MapEntry::name);
24  if ((it == end(baseMap)) || !cmp(it->name, str)) {
25  throw CommandException("not a valid value: ", str);
26  }
27  return it->value;
28 }
29 
30 std::string_view EnumSettingBase::toStringBase(int value) const
31 {
32  for (const auto& entry : baseMap) {
33  if (entry.value == value) {
34  return entry.name;
35  }
36  }
37  UNREACHABLE; return {};
38 }
39 
41 {
42  TclObject valueList;
44  result.addListElement(valueList);
45 }
46 
47 void EnumSettingBase::tabCompletionBase(std::vector<std::string>& tokens) const
48 {
50  false); // case insensitive
51 }
52 
53 } // namespace openmsx
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
Definition: Completer.hh:133
std::vector< MapEntry > Map
Definition: EnumSetting.hh:26
void tabCompletionBase(std::vector< std::string > &tokens) const
Definition: EnumSetting.cc:47
void additionalInfoBase(TclObject &result) const
Definition: EnumSetting.cc:40
std::string_view toStringBase(int value) const
Definition: EnumSetting.cc:30
int fromStringBase(std::string_view str) const
Definition: EnumSetting.cc:20
auto getPossibleValues() const
Definition: EnumSetting.hh:34
void addListElement(const T &t)
Definition: TclObject.hh:129
void addListElements(ITER first, ITER last)
Definition: TclObject.hh:130
This file implemented 3 utility functions:
Definition: Autofire.cc:9
void sort(RandomAccessRange &&range)
Definition: ranges.hh:33
auto lower_bound(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
Definition: ranges.hh:84
#define UNREACHABLE
Definition: unreachable.hh:38
constexpr auto end(const zstring_view &x)
Definition: zstring_view.hh:84