OSFI-C++  3.11.0
OpenSF Integration Library
base.h
Go to the documentation of this file.
1 /*
2  * openSF Integration Libraries (OSFI)
3  * Deimos Space, S.L.U.
4  *
5  * This file is part of OSFI. OSFI is free software; you can redistribute it
6  * and/or modify it under the terms of the 'ESA Software Community Licence Permissive' as
7  * published by the European Space Agency; either version 2.4 of the License,
8  * or (at your option) any later version. You should have received a
9  * copy of the 'ESA Software Community Licence Permissive - v2.4' along with this program
10  * or one can be found at <http://eop-cfi.esa.int/index.php/docs-and-mission-data/licensing-documents>.
11  */
12 
17 #ifndef OSFI_CONFM_BASE_H_
18 #define OSFI_CONFM_BASE_H_
19 
20 #include <string>
21 #include <vector>
22 #include <iosfwd>
23 #include <utility>
24 #include <cstdint>
25 
27 namespace osfi::confm {
31  enum class ElementType {
33  INTEGER = 1,
35  FLOAT,
37  BOOLEAN,
43  STRING,
48  FILE,
50  FOLDER,
56  TIME
57  };
61  std::string to_string(ElementType et);
65  ElementType as_ElementType(const std::string& str);
66 
72  struct TimeValue {
73  std::int16_t year;
74  std::int8_t month;
75  std::int8_t dom;
76  std::int8_t hour;
77  std::int8_t minute;
78  std::int8_t sec;
79  std::int32_t nanosec;
80  // TODO in the future, implement operator<=> for C++20-compliant compilers
81  // friend auto operator<=>(const TimeValue&, const TimeValue&) = default;
82  };
84  std::string to_string(const TimeValue&);
86  std::ostream& operator<<(std::ostream&, const TimeValue&);
91  bool operator==(const TimeValue&, const TimeValue&);
96  bool operator<(const TimeValue&, const TimeValue&);
98 #define OSFI_RELOP_IMPL(op, T) \
99  inline bool operator op(const T& a, const T& b) { \
100  return std::rel_ops::operator op(a, b); \
101  }
102  OSFI_RELOP_IMPL(!=, TimeValue)
103  OSFI_RELOP_IMPL(<=, TimeValue)
104  OSFI_RELOP_IMPL(>=, TimeValue)
105  OSFI_RELOP_IMPL(>, TimeValue)
106 #undef OSFI_RELOP_IMPL
107 
109  template<ElementType et>
110  struct parsed_type;
111  // Specializations for each element type
112  template<> struct parsed_type<ElementType::INTEGER> { using type = int; };
113  template<> struct parsed_type<ElementType::FLOAT> { using type = double; };
114  template<> struct parsed_type<ElementType::BOOLEAN> { using type = bool; };
115  template<> struct parsed_type<ElementType::STRING> { using type = std::string; };
116  template<> struct parsed_type<ElementType::FILE> { using type = std::string; };
117  template<> struct parsed_type<ElementType::FOLDER> { using type = std::string; };
118  template<> struct parsed_type<ElementType::TIME> { using type = TimeValue; };
119 
121  template<ElementType et>
123 }
124 
125 #endif // OSFI_CONFM_BASE_H_
#define OSFI_RELOP_IMPL(op, T)
Definition: base.h:98
Definition: base.h:27
typename parsed_type< et >::type parsed_type_t
Definition: base.h:122
bool operator==(const TimeValue &, const TimeValue &)
std::ostream & operator<<(std::ostream &, const TimeValue &)
ElementType
Definition: base.h:31
@ INTEGER
Integral number, with the value range of std::int32_t.
@ FOLDER
Path to a folder, with the same rules as FILE.
@ BOOLEAN
Truth value. Per the E2E-ICD, only TRUE or FALSE are accepted, capitalized.
@ FLOAT
Floating point number, in decimal representation with the range of IEEE754 binary64.
ElementType as_ElementType(const std::string &str)
bool operator<(const TimeValue &, const TimeValue &)
std::string to_string(ElementType et)
Definition: base.h:72
std::int16_t year
Year number, from 1 to 9999 inclusive.
Definition: base.h:73
std::int8_t minute
Minute of hour, from 0 to 59.
Definition: base.h:77
std::int8_t hour
Hour of day, from 0 to 23.
Definition: base.h:76
std::int32_t nanosec
Fraction of second in ns resolution, from 0 to 999999999.
Definition: base.h:79
std::int8_t month
Month number, from 1 to 12.
Definition: base.h:74
std::int8_t sec
Second of minute, from 0 to 60 to allow for leap seconds.
Definition: base.h:78
std::int8_t dom
Day of month, from 1 to the appropriate length according to the year.
Definition: base.h:75
Definition: base.h:110