0.2.0
Loading...
Searching...
No Matches
TimeSystem.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <string>
17#include <fmt/format.h>
18
19#include <nlohmann/json.hpp>
20using json = nlohmann::json;
21
22namespace NAV
23{
26{
27 TimeSys_None = 0x00,
28 UTC = 0x01,
29 GPST = 0x02,
30 GLNT = 0x04,
31 GST = 0x08,
32 BDT = 0x10,
33 QZSST = 0x20,
34 IRNSST = 0x40,
35};
36
39{
40 public:
42 constexpr TimeSystem() = default;
43
46 constexpr TimeSystem(TimeSystem_ type) // NOLINT(hicpp-explicit-conversions, google-explicit-constructor)
47 : value(type)
48 {}
49
52 static TimeSystem fromString(const std::string& typeString)
53 {
54 if (typeString == "UTC")
55 {
56 return UTC;
57 }
58 if (typeString == "GPST" || typeString == "GPS")
59 {
60 return GPST;
61 }
62 if (typeString == "GLNT" || typeString == "GLO")
63 {
64 return GLNT;
65 }
66 if (typeString == "GST" || typeString == "GAL")
67 {
68 return GST;
69 }
70 if (typeString == "BDT")
71 {
72 return BDT;
73 }
74 if (typeString == "QZSST" || typeString == "QZS")
75 {
76 return QZSST;
77 }
78 if (typeString == "IRNSST" || typeString == "IRN")
79 {
80 return IRNSST;
81 }
82
83 return TimeSys_None;
84 }
85
90 {
91 value = v;
92 return *this;
93 }
94
95 friend constexpr bool operator==(const TimeSystem& lhs, const TimeSystem& rhs);
96
98 constexpr explicit operator TimeSystem_() const { return value; }
100 constexpr explicit operator bool() = delete;
101
104 constexpr explicit operator int() const { return int(value); }
105
108 explicit operator std::string() const { return toString(); }
109
111 [[nodiscard]] constexpr const char* toString() const
112 {
113 switch (value)
114 {
115 case UTC:
116 return "UTC";
117 case GPST:
118 return "GPST";
119 case GLNT:
120 return "GLNT";
121 case GST:
122 return "GST";
123 case BDT:
124 return "BDT";
125 case QZSST:
126 return "QZSST";
127 case IRNSST:
128 return "IRNSST";
129 case TimeSys_None:
130 return "None";
131 }
132
133 return "None";
134 }
135
137 enum class TimeSystemEnum
138 {
140 UTC,
141 GPST,
142 GLNT,
143 GST,
144 BDT,
145 QZSST,
146 IRNSST,
147 COUNT,
148 };
149
153
155 [[nodiscard]] TimeSystemEnum getEnumValue() const;
156
159 constexpr TimeSystem(TimeSystemEnum timeSystem) // NOLINT(hicpp-explicit-conversions, google-explicit-constructor)
160 {
161 switch (timeSystem)
162 {
164 value = UTC;
165 break;
167 value = GPST;
168 break;
170 value = GLNT;
171 break;
173 value = GST;
174 break;
176 value = BDT;
177 break;
179 value = QZSST;
180 break;
182 value = IRNSST;
183 break;
184 default:
185 value = TimeSys_None;
186 break;
187 }
188 }
189
190 private:
192 TimeSystem_ value = TimeSystem_::TimeSys_None;
193};
194
198bool ComboTimeSystem(const char* label, TimeSystem& timeSystem);
199
203const char* to_string(TimeSystem::TimeSystemEnum timeSystem);
204
210{
211 return TimeSystem_(int(lhs) | int(rhs));
212}
218{
219 return { TimeSystem_(lhs) | TimeSystem_(rhs) };
220}
226{
227 return { lhs | TimeSystem_(rhs) };
228}
234{
235 return { TimeSystem_(lhs) | rhs };
236}
237
242constexpr TimeSystem_& operator|=(TimeSystem_& lhs, const TimeSystem_& rhs)
243{
244 lhs = lhs | rhs;
245 return lhs;
246}
251constexpr TimeSystem& operator|=(TimeSystem& lhs, const TimeSystem& rhs)
252{
253 lhs = lhs | rhs;
254 return lhs;
255}
260constexpr TimeSystem_& operator|=(TimeSystem_& lhs, const TimeSystem& rhs)
261{
262 lhs = lhs | TimeSystem_(rhs);
263 return lhs;
264}
269constexpr TimeSystem& operator|=(TimeSystem& lhs, const TimeSystem_& rhs)
270{
271 lhs = lhs | rhs;
272 return lhs;
273}
274
280{
281 return TimeSystem_(int(lhs) & int(rhs));
282}
288{
289 return { TimeSystem_(lhs) & TimeSystem_(rhs) };
290}
296{
297 return { TimeSystem_(lhs) & rhs };
298}
304{
305 return { lhs & TimeSystem_(rhs) };
306}
307
312constexpr TimeSystem_& operator&=(TimeSystem_& lhs, const TimeSystem_& rhs)
313{
314 lhs = lhs & rhs;
315 return lhs;
316}
321constexpr TimeSystem& operator&=(TimeSystem& lhs, const TimeSystem& rhs)
322{
323 lhs = lhs & rhs;
324 return lhs;
325}
330constexpr TimeSystem_& operator&=(TimeSystem_& lhs, const TimeSystem& rhs)
331{
332 lhs = lhs & TimeSystem_(rhs);
333 return lhs;
334}
339constexpr TimeSystem& operator&=(TimeSystem& lhs, const TimeSystem_& rhs)
340{
341 lhs = lhs & rhs;
342 return lhs;
343}
344
349{
350 return { TimeSystem_(~int(rhs)) };
351}
356{
357 return { TimeSystem_(~int(rhs)) };
358}
359
364constexpr bool operator==(const TimeSystem& lhs, const TimeSystem& rhs) { return lhs.value == rhs.value; }
369constexpr bool operator==(const TimeSystem& lhs, const TimeSystem_& rhs) { return lhs == TimeSystem(rhs); }
374constexpr bool operator==(const TimeSystem_& lhs, const TimeSystem& rhs) { return TimeSystem(lhs) == rhs; }
375
380constexpr bool operator!=(const TimeSystem& lhs, const TimeSystem& rhs) { return !(lhs == rhs); }
385constexpr bool operator!=(const TimeSystem& lhs, const TimeSystem_& rhs) { return !(lhs == rhs); }
390constexpr bool operator!=(const TimeSystem_& lhs, const TimeSystem& rhs) { return !(lhs == rhs); }
391
395void to_json(json& j, const TimeSystem& timeSystem);
399void from_json(const json& j, TimeSystem& timeSystem);
400
401} // namespace NAV
402
403namespace std
404{
406template<>
407struct hash<NAV::TimeSystem>
408{
411 std::size_t operator()(const NAV::TimeSystem& f) const
412 {
413 return std::hash<NAV::TimeSystem_>{}(NAV::TimeSystem_(f));
414 }
415};
416} // namespace std
417
418#ifndef DOXYGEN_IGNORE
419
421template<>
422struct fmt::formatter<NAV::TimeSystem> : fmt::formatter<std::string>
423{
428 template<typename FormatContext>
429 auto format(const NAV::TimeSystem& timeSys, FormatContext& ctx)
430 {
431 return fmt::formatter<std::string>::format(std::string(timeSys), ctx);
432 }
433};
434
435#endif
436
441std::ostream& operator<<(std::ostream& os, const NAV::TimeSystem& obj);
Code operator|(const Code::Enum &lhs, const Code::Enum &rhs)
Allows combining flags of the Code enum.
Code operator&(const Code::Enum &lhs, const Code::Enum &rhs)
Allows combining flags of the Code enum.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
constexpr Frequency_ operator~(Frequency_ rhs)
Allows negating flags of the Frequency enum.
Definition Frequency.hpp:362
constexpr Frequency_ & operator&=(Frequency_ &lhs, const Frequency_ &rhs)
Allows combining flags of the Frequency enum.
Definition Frequency.hpp:326
constexpr Frequency_ & operator|=(Frequency_ &lhs, const Frequency_ &rhs)
Allows combining flags of the Frequency enum.
Definition Frequency.hpp:256
const char * to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame)
Converts the enum to a string.
std::ostream & operator<<(std::ostream &os, const NAV::TimeSystem &obj)
Stream insertion operator overload.
TimeSystem_
List of all time systems.
Definition TimeSystem.hpp:26
@ IRNSST
Indian Regional Navigation Satellite System Time.
Definition TimeSystem.hpp:34
@ GST
Galileo System Time.
Definition TimeSystem.hpp:31
@ BDT
BeiDou Time.
Definition TimeSystem.hpp:32
@ GLNT
GLONASS Time (GLONASST)
Definition TimeSystem.hpp:30
@ TimeSys_None
No Time system.
Definition TimeSystem.hpp:27
@ QZSST
Quasi-Zenith Satellite System Time.
Definition TimeSystem.hpp:33
@ GPST
GPS Time.
Definition TimeSystem.hpp:29
@ UTC
Coordinated Universal Time.
Definition TimeSystem.hpp:28
bool ComboTimeSystem(const char *label, TimeSystem &timeSystem)
Shows a ComboBox to select the time system.
Time System defintions.
Definition TimeSystem.hpp:39
friend constexpr bool operator==(const TimeSystem &lhs, const TimeSystem &rhs)
Equal compares values.
Definition TimeSystem.hpp:364
static TimeSystem fromString(const std::string &typeString)
Construct new object from std::string.
Definition TimeSystem.hpp:52
constexpr TimeSystem(TimeSystemEnum timeSystem)
Definition TimeSystem.hpp:159
constexpr const char * toString() const
Converts the time system into a string.
Definition TimeSystem.hpp:111
TimeSystemEnum
Continuous enum for the time systems.
Definition TimeSystem.hpp:138
@ IRNSST
Indian Regional Navigation Satellite System Time.
@ COUNT
Amount of items in the enum.
@ GST
Galileo System Time.
@ UTC
Coordinated Universal Time.
@ GLNT
GLONASS Time (GLONASST)
@ QZSST
Quasi-Zenith Satellite System Time.
constexpr TimeSystem()=default
Default Constructor.
constexpr TimeSystem(TimeSystem_ type)
Implicit Constructor from Value type.
Definition TimeSystem.hpp:46
TimeSystemEnum getEnumValue() const
Returns the enum value (only one must be set)
static TimeSystemEnum GetTimeSystemEnumValue(TimeSystem timeSystem)
Returns the enum value (only one must be set)
constexpr TimeSystem & operator=(TimeSystem_ v)
Assignment operator from Value type.
Definition TimeSystem.hpp:89
bool operator==(const ImVec4 &lhs, const ImVec4 &rhs)
Equal comparison operator.
bool operator!=(const ImVec4 &lhs, const ImVec4 &rhs)
Unequal comparison operator.
std::size_t operator()(const NAV::TimeSystem &f) const
Hash function for TimeSystem.
Definition TimeSystem.hpp:411