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
11namespace openmsx {
12
14 : baseMap(std::move(map))
15{
17}
18
19int EnumSettingBase::fromStringBase(std::string_view str) const
20{
21 if (auto s = binary_find(baseMap, str, StringOp::caseless{}, &MapEntry::name)) {
22 return s->value;
23 }
24 throw CommandException("not a valid value: ", str);
25}
26
27std::string_view EnumSettingBase::toStringBase(int value) const
28{
29 auto it = ranges::find(baseMap, value, &MapEntry::value);
30 assert(it != baseMap.end());
31 return it->name;
32}
33
35{
36 TclObject valueList;
38 result.addListElement(valueList);
39}
40
41void EnumSettingBase::tabCompletionBase(std::vector<std::string>& tokens) const
42{
44 false); // case insensitive
45}
46
47} // 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:27
void tabCompletionBase(std::vector< std::string > &tokens) const
Definition: EnumSetting.cc:41
void additionalInfoBase(TclObject &result) const
Definition: EnumSetting.cc:34
std::string_view toStringBase(int value) const
Definition: EnumSetting.cc:27
int fromStringBase(std::string_view str) const
Definition: EnumSetting.cc:19
auto getPossibleValues() const
Definition: EnumSetting.hh:35
void addListElement(const T &t)
Definition: TclObject.hh:128
void addListElements(ITER first, ITER last)
Definition: TclObject.hh:129
This file implemented 3 utility functions:
Definition: Autofire.cc:9
auto find(InputRange &&range, const T &value)
Definition: ranges.hh:160
constexpr void sort(RandomAccessRange &&range)
Definition: ranges.hh:49
STL namespace.
auto * binary_find(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
Definition: ranges.hh:413