OSFI-C++  3.10.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 #if __cplusplus >= 201402L
22 # define OSFI_DEPRECATED(reason) [[deprecated(reason)]]
23 #else
24 # define OSFI_DEPRECATED(reason) /*deprecated*/
25 #endif
26 
27 #include <string>
28 #include <vector>
29 #include <iosfwd>
30 #include <utility>
31 #include <cstdint>
32 
33 namespace osfi {
35  namespace confm {
39  enum class ElementType {
41  INTEGER = 1,
43  FLOAT,
45  BOOLEAN,
51  STRING,
56  FILE,
58  FOLDER,
64  TIME
65  };
69  std::string to_string(ElementType et);
73  ElementType as_ElementType(const std::string& str);
74 
80  struct TimeValue {
81  std::int16_t year;
82  std::int8_t month;
83  std::int8_t dom;
84  std::int8_t hour;
85  std::int8_t minute;
86  std::int8_t sec;
87  std::int32_t nanosec;
88  // TODO in the future, implement operator<=> for C++20-compliant compilers
89  // friend auto operator<=>(const TimeValue&, const TimeValue&) = default;
90  };
92  std::string to_string(const TimeValue&);
94  std::ostream& operator<<(std::ostream&, const TimeValue&);
99  bool operator==(const TimeValue&, const TimeValue&);
104  bool operator<(const TimeValue&, const TimeValue&);
106 #define OSFI_RELOP_IMPL(op, T) \
107  inline bool operator op(const T& a, const T& b) { \
108  return std::rel_ops::operator op(a, b); \
109  }
110  OSFI_RELOP_IMPL(!=, TimeValue)
111  OSFI_RELOP_IMPL(<=, TimeValue)
112  OSFI_RELOP_IMPL(>=, TimeValue)
113  OSFI_RELOP_IMPL(>, TimeValue)
114 #undef OSFI_RELOP_IMPL
115 
117  template<ElementType et>
118  struct parsed_type;
119  // Specializations for each element type
120  template<> struct parsed_type<ElementType::INTEGER> { using type = int; };
121  template<> struct parsed_type<ElementType::FLOAT> { using type = double; };
122  template<> struct parsed_type<ElementType::BOOLEAN> { using type = bool; };
123  template<> struct parsed_type<ElementType::STRING> { using type = std::string; };
124  template<> struct parsed_type<ElementType::FILE> { using type = std::string; };
125  template<> struct parsed_type<ElementType::FOLDER> { using type = std::string; };
126  template<> struct parsed_type<ElementType::TIME> { using type = TimeValue; };
127 
129  template<ElementType et>
131  }
132 }
133 
134 #endif // OSFI_CONFM_BASE_H_
#define OSFI_RELOP_IMPL(op, T)
Definition: base.h:106
typename parsed_type< et >::type parsed_type_t
Definition: base.h:130
bool operator==(const TimeValue &, const TimeValue &)
std::ostream & operator<<(std::ostream &, const TimeValue &)
ElementType
Definition: base.h:39
@ 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:80
std::int16_t year
Year number, from 1 to 9999 inclusive.
Definition: base.h:81
std::int8_t minute
Minute of hour, from 0 to 59.
Definition: base.h:85
std::int8_t hour
Hour of day, from 0 to 23.
Definition: base.h:84
std::int32_t nanosec
Fraction of second in ns resolution, from 0 to 999999999.
Definition: base.h:87
std::int8_t month
Month number, from 1 to 12.
Definition: base.h:82
std::int8_t sec
Second of minute, from 0 to 60 to allow for leap seconds.
Definition: base.h:86
std::int8_t dom
Day of month, from 1 to the appropriate length according to the year.
Definition: base.h:83
Definition: base.h:118