SOIL C++
C++ Unified Device Interface
Enum.cpp
Go to the documentation of this file.
1#include "Enum.h"
2
3
5{
6}
7
8SOIL::Enum::Enum(std::string value) : _selected(value)
9{
10}
11
12SOIL::Enum::Enum(std::string value, std::vector<std::string> choices): _selected(value), _choices(choices)
13{
14}
15
16
18{
19}
20
21std::string SOIL::Enum::selected(void) const
22{
23 return _selected;
24}
25
26std::vector<std::string> SOIL::Enum::choices(void)
27{
28 return _choices;
29}
30
32{
33 for (int i = 0; i < static_cast<int>(_choices.size()); i++)
34 {
35 if (_selected == _choices.at(i))
36 {
37 return i;
38 }
39 }
40 throw std::logic_error("Value of ENUM not in choices!");
41}
42
43int SOIL::Enum::index(std::string value) const
44{
45 for (int i = 0; i < static_cast<int>(_choices.size()); i++)
46 {
47 if (value == _choices.at(i))
48 {
49 return i;
50 }
51 }
52 throw std::logic_error("Value of ENUM not in choices!");
53}
54
55void SOIL::Enum::set(int value)
56{
57 if (value < static_cast<int>(_choices.size()))
58 {
59 _selected = _choices.at(value);
60 }
61 else
62 {
63 throw std::logic_error("Index not in ENUM choices!");
64 }
65}
66
67void SOIL::Enum::set(std::string value)
68{
69 _selected = value;
70}
void set(int value)
Set selected item (index)
Definition: Enum.cpp:55
Enum()
Constructor.
Definition: Enum.cpp:4
std::string selected(void) const
Get selected value.
Definition: Enum.cpp:21
~Enum()
Destructor.
Definition: Enum.cpp:17
int index() const
Get index of selected element.
Definition: Enum.cpp:31
std::vector< std::string > choices(void)
Get Choices.
Definition: Enum.cpp:26