ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
defines.hpp
Go to the documentation of this file.
1 
6 #ifndef IFW_CTD_DEFINES_HPP_
7 #define IFW_CTD_DEFINES_HPP_
8 
9 #include <stdarg.h>
10 #include <string>
11 #include <map>
12 #include <list>
13 #include <fstream>
14 
15 #include "rad/Logger.hpp"
16 #include "rad/Exceptions.hpp"
17 
18 namespace ifw {
19 
21 std::string Print(const char* format, ...);
22 
23 }
24 
25 namespace ctd {
26 namespace defines {
27 
29 using IsoTime = std::string;
30 
31 
33 typedef enum {
35  DATA_TYPE_INT8 = 2,
36  DATA_TYPE_UINT8 = 4,
37  DATA_TYPE_INT16 = 8,
38  DATA_TYPE_UINT16 = 16,
39  DATA_TYPE_INT32 = 32,
40  DATA_TYPE_UINT32 = 64,
41  DATA_TYPE_INT64 = 128,
42  DATA_TYPE_UINT64 = 256,
43  DATA_TYPE_FLOAT = 512,
44  DATA_TYPE_DOUBLE = 1024,
45  DATA_TYPE_STRING = 2048,
46  DATA_TYPE_NON_BASIC = 4096,
47  DATA_TYPE_TIME_DATE = 8192,
48  DATA_TYPE_TIMESTAMP = 16384,
49  DATA_TYPE_BLOB = 32768,
54  | DATA_TYPE_BLOB),
55  DATA_TYPE_UNKNOWN = 2147483648
56 } DataType;
57 
62 const std::string DATA_TYPE_BOOLEAN_STR = "Boolean";
63 const std::string DATA_TYPE_INT8_STR = "Int8";
64 const std::string DATA_TYPE_UINT8_STR = "UInt8";
65 const std::string DATA_TYPE_INT16_STR = "Int16";
66 const std::string DATA_TYPE_UINT16_STR = "UInt16";
67 const std::string DATA_TYPE_INT32_STR = "Int32";
68 const std::string DATA_TYPE_UINT32_STR = "UInt32";
69 const std::string DATA_TYPE_INT64_STR = "Int64";
70 const std::string DATA_TYPE_UINT64_STR = "UInt64";
71 const std::string DATA_TYPE_FLOAT_STR = "Float";
72 const std::string DATA_TYPE_DOUBLE_STR = "Double";
73 const std::string DATA_TYPE_STRING_STR = "String";
74 const std::string DATA_TYPE_NON_BASIC_STR = "NonBasic";
75 const std::string DATA_TYPE_TIME_DATE_STR = "TimeDate";
76 const std::string DATA_TYPE_TIMESTAMP_STR = "TimeStamp";
77 const std::string DATA_TYPE_BLOB_STR = "Blob";
78 const std::string DATA_TYPE_UNKNOWN_STR = "Unknown";
81 static const std::map<DataType, std::string> s_data_types_nb_map =
83 {
84  {DATA_TYPE_BOOLEAN, DATA_TYPE_BOOLEAN_STR},
85  {DATA_TYPE_INT8, DATA_TYPE_INT8_STR},
86  {DATA_TYPE_UINT8, DATA_TYPE_UINT8_STR},
87  {DATA_TYPE_INT16, DATA_TYPE_INT16_STR},
88  {DATA_TYPE_UINT16, DATA_TYPE_UINT16_STR},
89  {DATA_TYPE_INT32, DATA_TYPE_INT32_STR},
90  {DATA_TYPE_UINT32, DATA_TYPE_UINT32_STR},
91  {DATA_TYPE_INT64, DATA_TYPE_INT64_STR},
92  {DATA_TYPE_UINT64, DATA_TYPE_UINT64_STR},
93  {DATA_TYPE_FLOAT, DATA_TYPE_FLOAT_STR},
94  {DATA_TYPE_DOUBLE, DATA_TYPE_DOUBLE_STR},
95  {DATA_TYPE_STRING, DATA_TYPE_STRING_STR},
96  {DATA_TYPE_NON_BASIC, DATA_TYPE_NON_BASIC_STR},
97  {DATA_TYPE_TIME_DATE, DATA_TYPE_TIME_DATE_STR},
98  {DATA_TYPE_TIMESTAMP, DATA_TYPE_TIMESTAMP_STR},
99  {DATA_TYPE_BLOB, DATA_TYPE_BLOB_STR},
100  {DATA_TYPE_UNKNOWN, DATA_TYPE_UNKNOWN_STR}
101 };
102 
104 static const std::map<std::string, DataType> s_data_types_name_map =
105 {
123 };
124 
126 const std::map<DataType, std::string>& DataTypesNbMap();
127 
129 const std::map<std::string, DataType>& DataTypesNameMap();
130 
132 DataType IfwDataTypeToNumeric(const std::string& data_type);
133 
135 std::string IfwDataTypeToString(const DataType data_type);
136 
138 static const std::map<DataType, std::string> s_data_type_2_type_id_map =
139 {
140  {DATA_TYPE_BOOLEAN, typeid(bool).name()},
141  {DATA_TYPE_INT8, typeid(int8_t).name()},
142  {DATA_TYPE_UINT8, typeid(uint8_t).name()},
143  {DATA_TYPE_INT16, typeid(int16_t).name()},
144  {DATA_TYPE_UINT16, typeid(uint16_t).name()},
145  {DATA_TYPE_INT32, typeid(int32_t).name()},
146  {DATA_TYPE_UINT32, typeid(uint32_t).name()},
147  {DATA_TYPE_INT64, typeid(int64_t).name()},
148  {DATA_TYPE_UINT64, typeid(uint64_t).name()},
149  {DATA_TYPE_FLOAT, typeid(float).name()},
150  {DATA_TYPE_DOUBLE, typeid(double).name()},
151  {DATA_TYPE_STRING, typeid(std::string).name()}
152 };
153 // @todo: Support:
154 // DATA_TYPE_NON_BASIC
155 // DATA_TYPE_TIME_DATE
156 // {DATA_TYPE_TIMESTAMP
157 // DATA_TYPE_BLOB
158 
160 static const std::map<std::string, DataType> s_type_id_2_data_type_map =
161 {
162  {typeid(bool).name(), DATA_TYPE_BOOLEAN},
163  {typeid(int8_t).name(), DATA_TYPE_INT8},
164  {typeid(uint8_t).name(), DATA_TYPE_UINT8},
165  {typeid(int16_t).name(), DATA_TYPE_INT16},
166  {typeid(uint16_t).name(), DATA_TYPE_UINT16},
167  {typeid(int32_t).name(), DATA_TYPE_INT32},
168  {typeid(uint32_t).name(), DATA_TYPE_UINT32},
169  {typeid(int64_t).name(), DATA_TYPE_INT64},
170  {typeid(uint64_t).name(), DATA_TYPE_UINT64},
171  {typeid(float).name(), DATA_TYPE_FLOAT},
172  {typeid(double).name(), DATA_TYPE_DOUBLE},
173  {typeid(std::string).name(), DATA_TYPE_STRING}
174 };
175 
177 const std::map<DataType, std::string>& DataType2TypeIdMap();
178 
180 const std::map<std::string, DataType>& TypeId2DataTypeMap();
181 
183 template <class TYPE> bool SupportedType(const TYPE& variable) {
184  RAD_LOG_TRACE();
185 
186  return (TypeId2DataTypeMap().find(typeid(variable).name()) != TypeId2DataTypeMap().end());
187 }
188 
193 const std::string EXT_FITS = "fits";
194 const std::string EXT_YAML = "yaml";
195 const std::string EXT_XML = "xml";
196 const std::string EXT_CONFIG = "config";
203 const std::string TRUE_STR = "True";
204 const std::string FALSE_STR = "False";
205 
206 const int64_t NO_TIMEOUT = -1;
207 const std::string NO_TIMEOUT_STR = "NoTimeout";
208 
209 const int64_t ERROR = -1;
210 const std::string ERROR_STR = "Error";
211 
212 const int64_t ILLEGAL = -3;
213 const std::string ILLEGAL_STR = "Illegal";
214 
215 const int64_t INVALID = -4;
216 const std::string INVALID_STR = "__INVALID__";
217 
218 const int64_t NOT_IMPLEMENTED = -5;
219 const std::string NOT_IMPLEMENTED_STR = "NotImplemented";
220 
221 const int64_t UNDEFINED = -6;
222 const std::string UNDEFINED_STR = "__UNDEFINED__";
223 
224 const int64_t UNKNOWN = -7;
225 const std::string UNKNOWN_STR = "Unknown";
226 
227 const int64_t FAILURE = -8;
228 const std::string FAILURE_STR = "Failure";
229 
230 const int64_t SUCCESS = 0;
231 const std::string SUCCESS_STR = "Success";
232 
233 const std::string INDEFINITE_STR = "Indefinite";
234 const std::string ALL_STR = "All";
235 const std::string NONE_STR = "None";
236 const std::string COMPLETED_STR = "Completed";
237 const std::string PROCESSING_STR = "Processing";
238 const std::string BUSY_STR = "Busy";
239 const std::string ACTIVE_STR = "Active";
240 const std::string MOVING_STR = "Moving";
241 const std::string WARMING_UP_STR = "WarmingUp";
242 const std::string COOLING_DOWN_STR = "CoolingDown";
243 const std::string INITIALIZING_STR = "Initializing";
244 const std::string OFFSETTING_STR = "Offsetting";
245 const std::string CALIBRATING_STR = "Calibrating";
246 const std::string ADJUSTING_STR = "Adjusting";
247 const std::string RECEIVING_STR = "Receiving";
248 const std::string TRANSFERRING_STR = "Transferring";
249 const std::string STORING_STR = "Storing";
250 const std::string READING_STR = "Reading";
251 const std::string LOADING_STR = "Loading";
252 const std::string PARSING_STR = "Parsing";
253 const std::string ACQUIRING_STR = "Acquiring";
254 const std::string INSTALLING_STR = "Installing";
255 const std::string ON_STR = "On";
256 const std::string OFF_STR = "Off";
257 const std::string OK_STR = "OK";
258 const std::string NOT_OK_STR = "NOK";
261 template <class TYPE> class List: public std::list<TYPE> {
263 public:
264  TYPE& operator[] (const int32_t index) {
265  typename List<TYPE>::iterator list_it = this->begin();
266  std::advance(list_it, index);
267  return *list_it;
268  }
269 };
270 
272 template <class TYPE> void CleanList(
273  const List<TYPE>& list,
274  const TYPE& pattern,
275  List<TYPE>& clean_list) {
276 
277  typename List<TYPE>::iterator list_it;
278  for (list_it = list.begin(); list_it != list.end(); list_it++) {
279  if (*list_it != pattern) {
280  clean_list.push_back(*list_it);
281  }
282  }
283 }
284 
287 template <class TYPE> void CheckRange(const std::string& par,
288  TYPE value,
289  TYPE lower_limit,
290  TYPE upper_limit);
291 
294 template <class TYPE> void CheckRange(const std::string& par,
295  const TYPE& value,
296  List<TYPE>& valid_values);
297 
299 template <class TYPE> int32_t ElInList(
300  const List<TYPE>& list,
301  const TYPE& value) {
302 
303  int32_t i = 0;
304  for (auto list_it = list.begin(); list_it != list.end(); list_it++, i++) {
305  if (*list_it == value) {
306  return i;
307  }
308  }
309  return -1;
310 }
311 
313 template <class TYPE> std::string DumpList(
314  const List<TYPE>& list,
315  const std::string& separator = "\n") {
316 
317  std::stringstream tmp_buf;
318  int32_t i = 0;
319  for (auto list_it = list.begin(); list_it != list.end(); list_it++, i++) {
320  tmp_buf << *list_it << separator;
321  }
322  return tmp_buf.str();
323 }
324 
326 template <class MAP_TYPE> bool ElInMap(const std::string& key,
327  const MAP_TYPE& map) {
328  return (map.find(key) != map.end());
329 }
330 
331 } // namespace ctd
332 } // namespace defines
333 
335 void IFW_DEBUG(const char* format, ...);
336 
337 
338 #endif // IFW_CTD_DEFINES_HPP_
double value
Definition: easylogging++.h:814
const std::string DATA_TYPE_BLOB_STR
Definition: defines.hpp:77
Definition: defines.hpp:35
DataType IfwDataTypeToNumeric(const std::string &data_type)
Data type IFW string representation to IFW numeric representation.
Definition: defines.cpp:31
optional bool index
Definition: topics.proto:34
const std::string NOT_IMPLEMENTED_STR
Definition: defines.hpp:219
const std::string RECEIVING_STR
Definition: defines.hpp:247
Definition: defines.hpp:42
const std::map< std::string, DataType > & TypeId2DataTypeMap()
Return reference to data types numeric to string map.
Definition: defines.cpp:60
const std::string LOADING_STR
Definition: defines.hpp:251
const std::string EXT_FITS
Definition: defines.hpp:193
const std::string DATA_TYPE_NON_BASIC_STR
Definition: defines.hpp:74
const std::map< DataType, std::string > & DataTypesNbMap()
Return reference to data types numeric to string map.
Definition: defines.cpp:17
Definition: defines.hpp:36
Definition: defines.hpp:37
const std::string UNKNOWN_STR
Definition: defines.hpp:225
Definition: defines.hpp:45
const std::string NO_TIMEOUT_STR
Definition: defines.hpp:207
const std::string DATA_TYPE_TIMESTAMP_STR
Definition: defines.hpp:76
const std::string ADJUSTING_STR
Definition: defines.hpp:246
const std::string INDEFINITE_STR
Definition: defines.hpp:233
const std::string NONE_STR
Definition: defines.hpp:235
const std::string UNDEFINED_STR
Definition: defines.hpp:222
const int64_t UNKNOWN
Definition: defines.hpp:224
const std::string READING_STR
Definition: defines.hpp:250
const std::string MOVING_STR
Definition: defines.hpp:240
const std::string INVALID_STR
Definition: defines.hpp:216
const std::string DATA_TYPE_FLOAT_STR
Definition: defines.hpp:71
void CleanList(const List< TYPE > &list, const TYPE &pattern, List< TYPE > &clean_list)
Remove elements from list, which are equal to &quot;pattern&quot;.
Definition: defines.hpp:272
const int64_t ERROR
Definition: defines.hpp:209
const std::string ACTIVE_STR
Definition: defines.hpp:239
const std::string EXT_CONFIG
Definition: defines.hpp:196
const std::string PARSING_STR
Definition: defines.hpp:252
DataType
Data types numeric representations.
Definition: defines.hpp:33
const std::string PROCESSING_STR
Definition: defines.hpp:237
const std::string INITIALIZING_STR
Definition: defines.hpp:243
TYPE & operator[](const int32_t index)
Definition: defines.hpp:264
const std::string DATA_TYPE_BOOLEAN_STR
Definition: defines.hpp:62
const std::string OFF_STR
Definition: defines.hpp:256
const std::string CALIBRATING_STR
Definition: defines.hpp:245
bool ElInMap(const std::string &key, const MAP_TYPE &map)
Check if a given key is contained in an STL map.
Definition: defines.hpp:326
const std::string NOT_OK_STR
Definition: defines.hpp:258
Definition: defines.hpp:55
const std::string EXT_YAML
Definition: defines.hpp:194
const int64_t UNDEFINED
Definition: defines.hpp:221
Definition: defines.hpp:49
const std::string DATA_TYPE_UINT8_STR
Definition: defines.hpp:64
@ brief STL like list that can be indexed with []&#39;s.
Definition: defines.hpp:262
const std::string ACQUIRING_STR
Definition: defines.hpp:253
Definition: defines.hpp:50
const std::string DATA_TYPE_INT16_STR
Definition: defines.hpp:65
const std::string COMPLETED_STR
Definition: defines.hpp:236
Definition: defines.hpp:46
const std::map< DataType, std::string > & DataType2TypeIdMap()
Return reference to data types numeric to string map.
Definition: defines.cpp:54
const std::string SUCCESS_STR
Definition: defines.hpp:231
void IFW_DEBUG(const char *format,...)
Print out a temporary debug log. These kind of logs should be removed from the code.
Definition: defines.cpp:87
std::string IsoTime
ISO8601 data type.
Definition: defines.hpp:29
const int64_t INVALID
Definition: defines.hpp:215
const int64_t FAILURE
Definition: defines.hpp:227
const std::string DATA_TYPE_UINT16_STR
Definition: defines.hpp:66
const std::string ERROR_STR
Definition: defines.hpp:210
const std::string INSTALLING_STR
Definition: defines.hpp:254
const std::string WARMING_UP_STR
Definition: defines.hpp:241
const int64_t SUCCESS
Definition: defines.hpp:230
const std::map< std::string, DataType > & DataTypesNameMap()
Return reference to data types numeric to string map.
Definition: defines.cpp:24
const std::string DATA_TYPE_INT32_STR
Definition: defines.hpp:67
const std::string FAILURE_STR
Definition: defines.hpp:228
const std::string DATA_TYPE_INT8_STR
Definition: defines.hpp:63
int32_t ElInList(const List< TYPE > &list, const TYPE &value)
Check for specific element in the list.
Definition: defines.hpp:299
const std::string BUSY_STR
Definition: defines.hpp:238
const std::string COOLING_DOWN_STR
Definition: defines.hpp:242
const std::string DATA_TYPE_UINT64_STR
Definition: defines.hpp:70
std::string DumpList(const List< TYPE > &list, const std::string &separator="\n")
Dump contents of a list into a string buffer.
Definition: defines.hpp:313
const std::string ALL_STR
Definition: defines.hpp:234
const std::string ON_STR
Definition: defines.hpp:255
bool SupportedType(const TYPE &variable)
Check if the variable has a data type which is supported by the ELT ICS.
Definition: defines.hpp:183
const std::string OFFSETTING_STR
Definition: defines.hpp:244
Definition: defines.hpp:41
std::string Print(const char *format,...)
Create formatted string, return formatted string (C formatting convention).
Definition: defines.cpp:71
#define RAD_LOG_TRACE()
Definition: Logger.hpp:319
Definition: defines.hpp:48
const int64_t ILLEGAL
Definition: defines.hpp:212
Definition: defines.hpp:47
void CheckRange(const std::string &par, TYPE value, TYPE lower_limit, TYPE upper_limit)
Check if a value is within a given range.
Definition: defines.hpp:38
const std::string ILLEGAL_STR
Definition: defines.hpp:213
const std::string TRANSFERRING_STR
Definition: defines.hpp:248
Definition: defines.hpp:43
Definition: defines.hpp:39
const std::string TRUE_STR
Definition: defines.hpp:203
const std::string OK_STR
Definition: defines.hpp:257
const std::string DATA_TYPE_INT64_STR
Definition: defines.hpp:69
const std::string DATA_TYPE_DOUBLE_STR
Definition: defines.hpp:72
const int64_t NO_TIMEOUT
Definition: defines.hpp:206
optional string name
Definition: topics.proto:50
const std::string STORING_STR
Definition: defines.hpp:249
const std::string FALSE_STR
Definition: defines.hpp:204
Definition: defines.hpp:44
Definition: defines.hpp:34
const int64_t NOT_IMPLEMENTED
Definition: defines.hpp:218
std::string IfwDataTypeToString(const DataType data_type)
Data type IFW numeric representation to IFW string representation.
Definition: defines.cpp:43
const std::string EXT_XML
Definition: defines.hpp:195
const std::string DATA_TYPE_TIME_DATE_STR
Definition: defines.hpp:75
const std::string DATA_TYPE_STRING_STR
Definition: defines.hpp:73
const std::string DATA_TYPE_UINT32_STR
Definition: defines.hpp:68
Definition: defines.hpp:40
const std::string DATA_TYPE_UNKNOWN_STR
Definition: defines.hpp:78