SOIL C++
C++ Unified Device Interface
Range.h
Go to the documentation of this file.
1#pragma once
2#include "constants.h"
3#include "json_helpers.h"
4#include "Types.h"
5#include "REST/Types.h"
6
7namespace SOIL
8{
23 template <typename T>
24 class Range
25 {
26 private:
32 T low;
33
39 T high;
40
47 bool set;
48 public:
54 Range();
55
64 Range(T low, T high);
65
74 Range(std::vector<T> limits);
75
81 ~Range();
82
89 HTTP::Json wjson(void);
90
101 bool check(const T & value);
102 };
103
109 template<>
110 class DLL Range<std::string>
111 {
112 private:
113 size_t low;
114 size_t high;
115 bool set;
116 public:
117 Range();
118 Range(size_t low, size_t high);
119 Range(std::vector<size_t> limits);
120 ~Range();
121 HTTP::Json wjson(void);
122 bool check(const std::string& value);
123 };
124
130 template<>
131 class DLL Range<ENUM>
132 {
133 private:
134 std::vector<std::string> choices;
135 bool set;
136 public:
138 Range(std::vector<std::string> choices);
141 bool check(const std::string& value);
142 bool check(const SOIL::ENUM& value);
143 };
144
145 template<typename T>
146 Range<T>::Range() : set(false)
147 {
148 }
149
150 template<typename T>
151 Range<T>::Range(T low, T high): set(true), low(low), high(high)
152 {
153 }
154
155 template<typename T>
156 Range<T>::Range(std::vector<T> limits)
157 {
158 if (limits.size() == 0)
159 {
160 set = false;
161 }
162 else if (limits.size() == 2)
163 {
164 low = limits.at(0);
165 high = limits.at(1);
166 set = true;
167 }
168 else
169 {
170 throw std::runtime_error("Invalid vector for range initialization!");
171 }
172 }
173
174 template<typename T>
176 {
177 }
178
179 template<typename T>
181 {
182 HTTP::Json range_array = HTTP::Json::array();
183 if (set)
184 {
185 range_array[0] = to_json<T>(low);
186 range_array[1] = to_json<T>(high);
187 }
188 return range_array;
189 }
190
191
192 template<typename T>
193 bool Range<T>::check(const T & value)
194 {
195 if (set)
196 {
197 return ((value >= low) && (value <= high));
198 }
199 else
200 {
201 return true;
202 }
203 }
204
205
206
207
208}
209
210
SOIL Enum Datatype.
Definition: Enum.h:16
bool check(const std::string &value)
Range(std::vector< std::string > choices)
HTTP::Json wjson(void)
bool check(const SOIL::ENUM &value)
Range Helper Class.
Definition: Range.h:25
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
web::json::value Json
HTTP JSON.
Definition: Types.h:39
Type definitions.
Definition: Container.h:7