This commit is contained in:
2026-02-04 18:29:08 +03:00
parent 5b4456d6ef
commit 593a914d8d
5 changed files with 587 additions and 40 deletions

View File

@@ -17,6 +17,51 @@
namespace mcc
{
/* celestial angle serialization */
enum class MccSerializedAngleFormat {
MCC_SERIALIZED_FORMAT_DEGREES, // degrees as floating-point number
MCC_SERIALIZED_FORMAT_SXGM_HOURS, // sexagesimal representation: hours:mins:secs
MCC_SERIALIZED_FORMAT_SXGM_DEGS, // sexagesimal representation: degs:arcmins:arcsecs
MCC_SERIALIZED_FORMAT_UNKNOWN
};
static constexpr std::string_view MCC_SERIALIZED_ANG_FORMAT_DEGREES_STR = "SRANG-FORMAT-DEGREES";
static constexpr std::string_view MCC_SERIALIZED_ANG_FORMAT_SXGM_HOURS_STR = "SRANG-FORMAT-SXGM_HOURDEG";
static constexpr std::string_view MCC_SERIALIZED_ANG_FORMAT_SXGM_DEGS_STR = "SRANG-FORMAT-SXGM_DEGDEG";
static constexpr std::string_view MccSerializedAngleFormatToStr(MccSerializedAngleFormat fmt)
{
return fmt == MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_DEGREES ? MCC_SERIALIZED_ANG_FORMAT_DEGREES_STR
: fmt == MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_SXGM_HOURS
? MCC_SERIALIZED_ANG_FORMAT_SXGM_HOURS_STR
: fmt == MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_SXGM_DEGS ? MCC_SERIALIZED_ANG_FORMAT_SXGM_DEGS_STR
: MCC_SERIALIZED_ANG_FORMAT_DEGREES_STR;
}
template <traits::mcc_input_char_range R>
static constexpr MccSerializedAngleFormat MccSerializedAngleFormatStrToValue(R&& str)
{
if constexpr (std::is_array_v<std::decay_t<R>>) {
return MccSerializedAngleFormatStrToValue(std::string_view{str});
}
const auto hash = mcc::utils::FNV1aHash(std::forward<R>(str));
return hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_ANG_FORMAT_DEGREES_STR)
? MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_DEGREES
: hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_ANG_FORMAT_SXGM_HOURS_STR)
? MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_SXGM_HOURS
: hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_ANG_FORMAT_SXGM_DEGS_STR)
? MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_SXGM_DEGS
: MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_UNKNOWN;
}
/* coordinates pair serialization */
enum class MccSerializedCoordPairFormat {
MCC_SERIALIZED_FORMAT_DEGREES, // both angles are in degrees as floating-point number
MCC_SERIALIZED_FORMAT_SXGM_HOURDEG, // X is in hour and Y is in degree sexagesimal representation
@@ -24,19 +69,19 @@ enum class MccSerializedCoordPairFormat {
MCC_SERIALIZED_FORMAT_UNKNOWN
};
static constexpr std::string_view MCC_SERIALIZED_FORMAT_DEGREES_STR = "SRCP-FORMAT-DEGREES";
static constexpr std::string_view MCC_SERIALIZED_FORMAT_SXGM_HOURDEG_STR = "SRCP-FORMAT-SXGM_HOURDEG";
static constexpr std::string_view MCC_SERIALIZED_FORMAT_SXGM_DEGDEG_STR = "SRCP-FORMAT-SXGM_DEGDEG";
static constexpr std::string_view MCC_SERIALIZED_CP_FORMAT_DEGREES_STR = "SRCP-FORMAT-DEGREES";
static constexpr std::string_view MCC_SERIALIZED_CP_FORMAT_SXGM_HOURDEG_STR = "SRCP-FORMAT-SXGM_HOURDEG";
static constexpr std::string_view MCC_SERIALIZED_CP_FORMAT_SXGM_DEGDEG_STR = "SRCP-FORMAT-SXGM_DEGDEG";
static constexpr std::string_view MccSerializedCoordPairFormatToStr(MccSerializedCoordPairFormat fmt)
{
return fmt == MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_DEGREES ? MCC_SERIALIZED_FORMAT_DEGREES_STR
return fmt == MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_DEGREES ? MCC_SERIALIZED_CP_FORMAT_DEGREES_STR
: fmt == MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_SXGM_HOURDEG
? MCC_SERIALIZED_FORMAT_SXGM_HOURDEG_STR
? MCC_SERIALIZED_CP_FORMAT_SXGM_HOURDEG_STR
: fmt == MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_SXGM_DEGDEG
? MCC_SERIALIZED_FORMAT_SXGM_DEGDEG_STR
: MCC_SERIALIZED_FORMAT_DEGREES_STR;
? MCC_SERIALIZED_CP_FORMAT_SXGM_DEGDEG_STR
: MCC_SERIALIZED_CP_FORMAT_DEGREES_STR;
}
template <traits::mcc_input_char_range R>
@@ -48,17 +93,19 @@ static constexpr MccSerializedCoordPairFormat MccSerializedCoordPairFormatStrToV
const auto hash = mcc::utils::FNV1aHash(std::forward<R>(str));
return hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_FORMAT_DEGREES_STR)
return hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_CP_FORMAT_DEGREES_STR)
? MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_DEGREES
: hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_FORMAT_SXGM_HOURDEG_STR)
: hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_CP_FORMAT_SXGM_HOURDEG_STR)
? MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_SXGM_HOURDEG
: hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_FORMAT_SXGM_DEGDEG_STR)
: hash == mcc::utils::FNV1aHash(MCC_SERIALIZED_CP_FORMAT_SXGM_DEGDEG_STR)
? MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_SXGM_DEGDEG
: MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_UNKNOWN;
}
struct MccSerializedCoordPairFormatPrec {
/* precision of representation of serialized celestial angle/coordinates pair */
struct MccSerializedAngleFormatPrec {
uint8_t hour_prec = 2; // number of decimal places in hour seconds (sexagesimal format)
uint8_t deg_prec = 1; // number of decimal places in arcseconds (sexagesimal format)
// slightly better than 0.1 arcsecond precision
@@ -120,10 +167,14 @@ concept mcc_serialization_params_c = requires(T t) {
requires traits::mcc_output_char_range<decltype(t.seq_delim)>;
requires traits::mcc_output_char_range<decltype(t.elem_delim)>;
requires std::same_as<decltype(t.angle_format), MccSerializedAngleFormat>;
requires std::same_as<decltype(t.angle_prec), MccSerializedAngleFormatPrec>;
requires std::same_as<decltype(t.coordpair_format), MccSerializedCoordPairFormat>;
requires std::same_as<decltype(t.coordpair_prec), MccSerializedCoordPairFormatPrec>;
requires std::same_as<decltype(t.timepoint_format), MccTimePointFormat>;
// a format string for mcc_systime_c types (std;:chrono::sys_time)
requires std::same_as<decltype(t.systime_format), std::string_view>;
// if true - normalize angle in sexagesimal format (to control rounding)
// (to avoid something like "24:00:00.0" for sexagesimal 'hours:minutes:seconds' format)
requires std::convertible_to<decltype(t.norm_sxgm), bool>;
@@ -148,6 +199,12 @@ struct mcc_serializer_interface_t {
return std::forward<SelfT>(self)(output, value);
}
template <std::derived_from<mcc_serializer_interface_t> SelfT, traits::mcc_output_char_range R, typename ValueT>
RetT operator()(this SelfT&& self, R& output, ValueT const& value, mcc_serialization_params_c auto const& params)
{
return std::forward<SelfT>(self)(output, value, params);
}
protected:
mcc_serializer_interface_t() = default;
};
@@ -159,12 +216,12 @@ concept mcc_serializer_c =
// static const variable with name of the serializer
requires std::formattable<decltype(T::serializerName), char> && std::is_const_v<decltype(T::serializerName)>;
// must define a type "params_t"
requires mcc_serialization_params_c<typename T::params_t>;
// // must define a type "params_t"
// requires mcc_serialization_params_c<typename T::params_t>;
{ t.setParams(std::declval<typename T::params_t const&>()) };
// { t.setParams(std::declval<typename T::params_t const&>()) };
{ t_const.getParams() } -> std::same_as<typename T::params_t>;
// { t_const.getParams() } -> std::same_as<typename T::params_t>;
};
@@ -181,6 +238,12 @@ struct mcc_deserializer_interface_t {
return std::forward<SelfT>(self)(input, value);
}
template <std::derived_from<mcc_deserializer_interface_t> SelfT, traits::mcc_input_char_range R, typename ValueT>
RetT operator()(this SelfT&& self, R const& input, ValueT& value, mcc_serialization_params_c auto& params)
{
return std::forward<SelfT>(self)(input, value, params);
}
protected:
mcc_deserializer_interface_t() = default;
};
@@ -193,12 +256,12 @@ concept mcc_deserializer_c =
requires std::formattable<decltype(T::deserializerName), char> &&
std::is_const_v<decltype(T::deserializerName)>;
// must define a type "params_t"
requires mcc_serialization_params_c<typename T::params_t>;
// // must define a type "params_t"
// requires mcc_serialization_params_c<typename T::params_t>;
{ t.setParams(std::declval<typename T::params_t const&>()) };
// { t.setParams(std::declval<typename T::params_t const&>()) };
{ t_const.getParams() } -> std::same_as<typename T::params_t>;
// { t_const.getParams() } -> std::same_as<typename T::params_t>;
};
@@ -213,19 +276,24 @@ struct mcc_serialization_params_t {
std::string seq_delim{MCC_SERIALIZING_DEFAULT_SEQ_DELIMITER};
std::string elem_delim{MCC_SERIALIZING_DEFAULT_ELEM_DELIMITER};
MccSerializedAngleFormat angle_format{MccSerializedAngleFormat::MCC_SERIALIZED_FORMAT_DEGREES};
MccSerializedAngleFormatPrec angle_prec{MccSerializedAngleFormatPrec{.hour_prec = 2, .deg_prec = 1, .decimals = 6}};
MccSerializedCoordPairFormat coordpair_format{MccSerializedCoordPairFormat::MCC_SERIALIZED_FORMAT_SXGM_HOURDEG};
MccSerializedCoordPairFormatPrec coordpair_prec{
MccSerializedCoordPairFormatPrec{.hour_prec = 2, .deg_prec = 1, .decimals = 6}};
MccTimePointFormat timepoint_format{MccTimePointFormat::MCC_TIMEPOINT_FORMAT_DATE};
std::string_view systime_format{"{:%FT%T}"};
bool norm_sxgm{false};
bool sxgm_hms{false};
};
static_assert(mcc_serialization_params_c<mcc_serialization_params_t>, "!!!");
namespace details
{
@@ -244,7 +312,7 @@ struct _params_manipulator_t {
_params.seq_delim = pars.seq_delim;
_params.elem_delim = pars.elem_delim;
_params.coordpair_format = pars.coordpair_format;
_params.coordpair_prec = pars.coordpair_prec;
_params.angle_prec = pars.angle_prec;
_params.timepoint_format = pars.timepoint_format;
_params.norm_sxgm = pars.norm_sxgm;
_params.sxgm_hms = pars.sxgm_hms;
@@ -260,7 +328,7 @@ struct _params_manipulator_t {
pars.seq_delim = _params.seq_delim;
pars.elem_delim = _params.elem_delim;
pars.coordpair_format = _params.coordpair_format;
pars.coordpair_prec = _params.coordpair_prec;
pars.angle_prec = _params.angle_prec;
pars.timepoint_format = _params.timepoint_format;
pars.norm_sxgm = _params.norm_sxgm;
pars.sxgm_hms = _params.sxgm_hms;
@@ -283,30 +351,40 @@ protected:
} // namespace details
template <mcc_serialization_params_c ParamsT>
struct MccSerializerBase : mcc_serializer_interface_t<MccError>, details::_params_manipulator_t<ParamsT> {
virtual ~MccSerializerBase() = default;
using typename mcc_serializer_interface_t<MccError>::error_t;
using typename details::_params_manipulator_t<ParamsT>::params_t;
protected:
MccSerializerBase() = default;
};
template <mcc_serialization_params_c ParamsT>
struct MccDeserializerBase : mcc_deserializer_interface_t<MccError>, details::_params_manipulator_t<ParamsT> {
struct MccDeserializerBase : mcc_deserializer_interface_t<MccError> {
virtual ~MccDeserializerBase() = default;
using typename mcc_deserializer_interface_t<MccError>::error_t;
using typename details::_params_manipulator_t<ParamsT>::params_t;
protected:
MccDeserializerBase() = default;
};
// template <mcc_serialization_params_c ParamsT>
// struct MccSerializerBase : mcc_serializer_interface_t<MccError>, details::_params_manipulator_t<ParamsT> {
// virtual ~MccSerializerBase() = default;
// using typename mcc_serializer_interface_t<MccError>::error_t;
// using typename details::_params_manipulator_t<ParamsT>::params_t;
// protected:
// MccSerializerBase() = default;
// };
// template <mcc_serialization_params_c ParamsT>
// struct MccDeserializerBase : mcc_deserializer_interface_t<MccError>, details::_params_manipulator_t<ParamsT> {
// virtual ~MccDeserializerBase() = default;
// using typename mcc_deserializer_interface_t<MccError>::error_t;
// using typename details::_params_manipulator_t<ParamsT>::params_t;
// protected:
// MccDeserializerBase() = default;
// };
} // namespace impl
} // namespace mcc