0.3.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 <cstdint>
17#include <string>
18#include <fmt/format.h>
19
20#include <nlohmann/json.hpp>
21using json = nlohmann::json;
22
23namespace NAV
24{
26enum TimeSystem_ : uint8_t
27{
28 TimeSys_None = 0x00,
29 UTC = 0x01,
30 GPST = 0x02,
31 GLNT = 0x04,
32 GST = 0x08,
33 BDT = 0x10,
34 QZSST = 0x20,
35 IRNSST = 0x40,
36};
37
40{
41 public:
43 constexpr TimeSystem() = default;
44
47 constexpr TimeSystem(TimeSystem_ type) // NOLINT(hicpp-explicit-conversions, google-explicit-constructor)
48 : value(type)
49 {}
50
53 static TimeSystem fromString(const std::string& typeString)
54 {
55 if (typeString == "UTC")
56 {
57 return UTC;
58 }
59 if (typeString == "GPST" || typeString == "GPS")
60 {
61 return GPST;
62 }
63 if (typeString == "GLNT" || typeString == "GLO")
64 {
65 return GLNT;
66 }
67 if (typeString == "GST" || typeString == "GAL")
68 {
69 return GST;
70 }
71 if (typeString == "BDT")
72 {
73 return BDT;
74 }
75 if (typeString == "QZSST" || typeString == "QZS")
76 {
77 return QZSST;
78 }
79 if (typeString == "IRNSST" || typeString == "IRN")
80 {
81 return IRNSST;
82 }
83
84 return TimeSys_None;
85 }
86
91 {
92 value = v;
93 return *this;
94 }
95
96 friend constexpr bool operator==(const TimeSystem& lhs, const TimeSystem& rhs);
97
99 constexpr explicit operator TimeSystem_() const { return value; }
101 constexpr explicit operator bool() = delete;
102
105 constexpr explicit operator int() const { return int(value); }
106
109 explicit operator std::string() const { return toString(); }
110
112 [[nodiscard]] constexpr const char* toString() const
113 {
114 switch (value)
115 {
116 case UTC:
117 return "UTC";
118 case GPST:
119 return "GPST";
120 case GLNT:
121 return "GLNT";
122 case GST:
123 return "GST";
124 case BDT:
125 return "BDT";
126 case QZSST:
127 return "QZSST";
128 case IRNSST:
129 return "IRNSST";
130 case TimeSys_None:
131 return "None";
132 }
133
134 return "None";
135 }
136
138 enum class TimeSystemEnum : uint8_t
139 {
141 UTC,
142 GPST,
143 GLNT,
144 GST,
145 BDT,
146 QZSST,
147 IRNSST,
148 COUNT,
149 };
150
154
156 [[nodiscard]] TimeSystemEnum getEnumValue() const;
157
160 constexpr TimeSystem(TimeSystemEnum timeSystem) // NOLINT(hicpp-explicit-conversions, google-explicit-constructor)
161 {
162 switch (timeSystem)
163 {
165 value = UTC;
166 break;
168 value = GPST;
169 break;
171 value = GLNT;
172 break;
174 value = GST;
175 break;
177 value = BDT;
178 break;
180 value = QZSST;
181 break;
183 value = IRNSST;
184 break;
185 default:
187 break;
188 }
189 }
190
191 private:
193 TimeSystem_ value = TimeSystem_::TimeSys_None;
194};
195
199bool ComboTimeSystem(const char* label, TimeSystem& timeSystem);
200
204const char* to_string(TimeSystem::TimeSystemEnum timeSystem);
205
211{
212 return TimeSystem_(int(lhs) | int(rhs));
213}
219{
220 return { TimeSystem_(lhs) | TimeSystem_(rhs) };
221}
227{
228 return { lhs | TimeSystem_(rhs) };
229}
235{
236 return { TimeSystem_(lhs) | rhs };
237}
238
243constexpr TimeSystem_& operator|=(TimeSystem_& lhs, const TimeSystem_& rhs)
244{
245 lhs = lhs | rhs;
246 return lhs;
247}
252constexpr TimeSystem& operator|=(TimeSystem& lhs, const TimeSystem& rhs)
253{
254 lhs = lhs | rhs;
255 return lhs;
256}
261constexpr TimeSystem_& operator|=(TimeSystem_& lhs, const TimeSystem& rhs)
262{
263 lhs = lhs | TimeSystem_(rhs);
264 return lhs;
265}
270constexpr TimeSystem& operator|=(TimeSystem& lhs, const TimeSystem_& rhs)
271{
272 lhs = lhs | rhs;
273 return lhs;
274}
275
281{
282 return TimeSystem_(int(lhs) & int(rhs));
283}
289{
290 return { TimeSystem_(lhs) & TimeSystem_(rhs) };
291}
297{
298 return { TimeSystem_(lhs) & rhs };
299}
305{
306 return { lhs & TimeSystem_(rhs) };
307}
308
313constexpr TimeSystem_& operator&=(TimeSystem_& lhs, const TimeSystem_& rhs)
314{
315 lhs = lhs & rhs;
316 return lhs;
317}
322constexpr TimeSystem& operator&=(TimeSystem& lhs, const TimeSystem& rhs)
323{
324 lhs = lhs & rhs;
325 return lhs;
326}
331constexpr TimeSystem_& operator&=(TimeSystem_& lhs, const TimeSystem& rhs)
332{
333 lhs = lhs & TimeSystem_(rhs);
334 return lhs;
335}
340constexpr TimeSystem& operator&=(TimeSystem& lhs, const TimeSystem_& rhs)
341{
342 lhs = lhs & rhs;
343 return lhs;
344}
345
350{
351 return { TimeSystem_(~int(rhs)) };
352}
357{
358 return { TimeSystem_(~int(rhs)) };
359}
360
365constexpr bool operator==(const TimeSystem& lhs, const TimeSystem& rhs) { return lhs.value == rhs.value; }
370constexpr bool operator==(const TimeSystem& lhs, const TimeSystem_& rhs) { return lhs == TimeSystem(rhs); }
375constexpr bool operator==(const TimeSystem_& lhs, const TimeSystem& rhs) { return TimeSystem(lhs) == rhs; }
376
381constexpr bool operator!=(const TimeSystem& lhs, const TimeSystem& rhs) { return !(lhs == rhs); }
386constexpr bool operator!=(const TimeSystem& lhs, const TimeSystem_& rhs) { return !(lhs == rhs); }
391constexpr bool operator!=(const TimeSystem_& lhs, const TimeSystem& rhs) { return !(lhs == rhs); }
392
396void to_json(json& j, const TimeSystem& timeSystem);
400void from_json(const json& j, TimeSystem& timeSystem);
401
402} // namespace NAV
403
404namespace std
405{
407template<>
408struct hash<NAV::TimeSystem>
409{
412 std::size_t operator()(const NAV::TimeSystem& f) const
413 {
414 return std::hash<NAV::TimeSystem_>{}(NAV::TimeSystem_(f));
415 }
416};
417} // namespace std
418
419#ifndef DOXYGEN_IGNORE
420
422template<>
423struct fmt::formatter<NAV::TimeSystem> : fmt::formatter<std::string>
424{
429 template<typename FormatContext>
430 auto format(const NAV::TimeSystem& timeSys, FormatContext& ctx) const
431 {
432 return fmt::formatter<std::string>::format(std::string(timeSys), ctx);
433 }
434};
435
436#endif
437
442std::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:378
constexpr Frequency_ & operator&=(Frequency_ &lhs, const Frequency_ &rhs)
Allows combining flags of the Frequency enum.
Definition Frequency.hpp:342
constexpr Frequency_ & operator|=(Frequency_ &lhs, const Frequency_ &rhs)
Allows combining flags of the Frequency enum.
Definition Frequency.hpp:272
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:27
@ IRNSST
Indian Regional Navigation Satellite System Time.
Definition TimeSystem.hpp:35
@ GST
Galileo System Time.
Definition TimeSystem.hpp:32
@ BDT
BeiDou Time.
Definition TimeSystem.hpp:33
@ GLNT
GLONASS Time (GLONASST)
Definition TimeSystem.hpp:31
@ TimeSys_None
No Time system.
Definition TimeSystem.hpp:28
@ QZSST
Quasi-Zenith Satellite System Time.
Definition TimeSystem.hpp:34
@ GPST
GPS Time.
Definition TimeSystem.hpp:30
@ UTC
Coordinated Universal Time.
Definition TimeSystem.hpp:29
bool ComboTimeSystem(const char *label, TimeSystem &timeSystem)
Shows a ComboBox to select the time system.
Time System defintions.
Definition TimeSystem.hpp:40
TimeSystemEnum
Continuous enum for the time systems.
Definition TimeSystem.hpp:139
@ 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.
friend constexpr bool operator==(const TimeSystem &lhs, const TimeSystem &rhs)
Equal compares values.
Definition TimeSystem.hpp:365
static TimeSystem fromString(const std::string &typeString)
Construct new object from std::string.
Definition TimeSystem.hpp:53
TimeSystem_ value
Internal value.
Definition TimeSystem.hpp:193
constexpr TimeSystem(TimeSystemEnum timeSystem)
Definition TimeSystem.hpp:160
constexpr const char * toString() const
Converts the time system into a string.
Definition TimeSystem.hpp:112
constexpr TimeSystem()=default
Default Constructor.
constexpr TimeSystem(TimeSystem_ type)
Implicit Constructor from Value type.
Definition TimeSystem.hpp:47
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:90
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:412