SOIL C++
C++ Unified Device Interface
Range.cpp
Go to the documentation of this file.
1#include "Range.h"
2
3SOIL::Range<std::string>::Range() : set(false), low(0), high(std::numeric_limits<size_t>::max())
4{
5}
6
7SOIL::Range<std::string>::Range(size_t low, size_t high) : set(true), low(low), high(high)
8{
9}
10
11SOIL::Range<std::string>::Range(std::vector<size_t> limits) : set(true)
12{
13 if (limits.size() == 0)
14 {
15 set = false;
16 }
17 else if (limits.size() == 2)
18 {
19 low = limits.at(0);
20 high = limits.at(1);
21 set = true;
22 }
23 else
24 {
25 throw std::runtime_error("Invalid vector for range initialization!");
26 }
27}
28
30{
31}
32
33web::json::value SOIL::Range<std::string>::wjson(void)
34{
35 web::json::value range_array = web::json::value::array();
36 if (set)
37 {
38 range_array[0] = SOIL::to_json<int>(static_cast<int>(low));
39 range_array[1] = SOIL::to_json<int>(static_cast<int>(high));
40 }
41 return range_array;
42}
43
44bool SOIL::Range<std::string>::check(const std::string & value)
45{
46 if (set)
47 {
48 return ((value.size() >= low) && (value.size() <= high));
49 }
50 else
51 {
52 return true;
53 }
54}
55
56
57
59{
60}
61
62
63SOIL::Range<SOIL::ENUM>::Range(std::vector<std::string> choices) : set(true), choices(choices)
64{
65
66}
67
69{
70}
71
72web::json::value SOIL::Range<SOIL::ENUM>::wjson(void)
73{
74 web::json::value range_array = web::json::value::array();
75 if (set)
76 {
77 for (int i = 0; i < static_cast<int>(choices.size()); i++)
78 {
79 range_array[i] = SOIL::to_json<std::string>(choices.at(i));
80 }
81 }
82 return range_array;
83}
84
85bool SOIL::Range<SOIL::ENUM>::check(const std::string& value)
86{
87 if (set)
88 {
89 for (int i = 0; i < static_cast<int>(choices.size()); i++)
90 {
91 if (value == choices.at(i))
92 {
93 return true;
94 }
95 }
96 return false;
97 }
98 else
99 {
100 return true;
101 }
102}
103
105{
106 return this->check(value.selected());
107}
108
SOIL Enum Datatype.
Definition: Enum.h:16
std::string selected(void) const
Get selected value.
Definition: Enum.cpp:21
HTTP::Json wjson(void)
HTTP JSON.
Definition: Range.cpp:72
Range()
Default Constructor.
Definition: Range.cpp:58
bool check(const T &value)
Check.
Definition: Range.cpp:85
~Range()
Destructor.
Definition: Range.cpp:68
DLL web::json::value to_json< int >(const int &value)