tempoch-cpp 0.5.3
Header-only C++ wrapper for tempoch
Loading...
Searching...
No Matches
gnss_week.hpp
Go to the documentation of this file.
1#pragma once
2
13#include "scales/scales.hpp"
14#include "time_base.hpp"
15
16#include <cstdint>
17#include <type_traits>
18
19namespace tempoch {
20
22template <typename S> struct is_gnss_scale : std::false_type {};
23template <> struct is_gnss_scale<scale::GPST> : std::true_type {};
24template <> struct is_gnss_scale<scale::GST> : std::true_type {};
25template <> struct is_gnss_scale<scale::BDT> : std::true_type {};
26template <> struct is_gnss_scale<scale::QZSST> : std::true_type {};
27
28template <typename S> inline constexpr bool is_gnss_scale_v = is_gnss_scale<S>::value;
29
35struct GnssWeek {
37 std::uint32_t week;
39 std::uint32_t seconds_of_week;
41 std::uint32_t subsecond_nanos;
42};
43
45template <typename S, std::enable_if_t<is_gnss_scale_v<S>, int> = 0>
46inline GnssWeek to_gnss_week(const Time<S> &time) {
47 TempochGnssWeek raw{};
49 tempoch_time_to_gnss_week(time.c_inner(), static_cast<int32_t>(scale_tag_v<S>), &raw),
50 "tempoch::to_gnss_week");
51 return GnssWeek{raw.week, raw.seconds_of_week, raw.subsecond_nanos};
52}
53
55template <typename S, std::enable_if_t<is_gnss_scale_v<S>, int> = 0>
57 TempochGnssWeek raw{gw.week, gw.seconds_of_week, gw.subsecond_nanos};
60 "tempoch::from_gnss_week");
61 return Time<S>::from_split_seconds(qtty::Second(out.hi_seconds), qtty::Second(out.lo_seconds));
62}
63
64} // namespace tempoch
A point in time on scale S, stored as a split J2000-second pair.
const tempoch_time_t & c_inner() const noexcept
static Time from_split_seconds(qtty::Second hi, qtty::Second lo=qtty::Second(0.0))
constexpr bool is_gnss_scale_v
Definition gnss_week.hpp:28
GnssWeek to_gnss_week(const Time< S > &time)
Decompose a GNSS-scale instant into its week-number form.
Definition gnss_week.hpp:46
Time< S > from_gnss_week(const GnssWeek &gw)
Build a GNSS-scale instant from a week-number decomposition.
Definition gnss_week.hpp:56
void check_status(tempoch_status_t status, const char *operation)
Check a tempoch_status_t and throw the appropriate exception on error.
Definition ffi_core.hpp:139
constexpr tempoch_scale_tag_t scale_tag_v
Time-scale tag types for the tempoch C++ API.
std::uint32_t subsecond_nanos
Subsecond nanoseconds remainder, in [0, 1'000'000'000).
Definition gnss_week.hpp:41
std::uint32_t seconds_of_week
Seconds since the start of week, in [0, 604'800).
Definition gnss_week.hpp:39
std::uint32_t week
Full week number since the constellation's epoch (no rollover applied).
Definition gnss_week.hpp:37
Trait marking the GNSS coordinate scales that support week decomposition.
Definition gnss_week.hpp:22
Core Time<S>, EncodedTime<S, F>, and TimeContext types.