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:138
std::vector< MapEntry > Map
void tabCompletionBase(std::vector< std::string > &tokens) const
void additionalInfoBase(TclObject &result) const
std::string_view toStringBase(int value) const
int fromStringBase(std::string_view str) const
auto getPossibleValues() const
void addListElement(const T &t)
Definition TclObject.hh:131
void addListElements(ITER first, ITER last)
Definition TclObject.hh:132
This file implemented 3 utility functions:
Definition Autofire.cc:11
auto find(InputRange &&range, const T &value)
Definition ranges.hh:162
constexpr void sort(RandomAccessRange &&range)
Definition ranges.hh:51
STL namespace.
auto * binary_find(ForwardRange &&range, const T &value, Compare comp={}, Proj proj={})
Definition ranges.hh:440