KItinerary

fcbutil.h
1/*
2 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KITINERARY_FCBUTIL_H
7#define KITINERARY_FCBUTIL_H
8
9#include "fcbticket.h"
10#include "fcbticket3.h"
11#include "logging.h"
12
13#include <QString>
14
15namespace KItinerary {
16
17/** Higher-level decoding utilities for ERA FCB ticket data. */
19{
20private:
21 constexpr inline static bool isUicCode(Fcb::v13::CodeTableType stationCodeTable)
22 {
23 return stationCodeTable == Fcb::v13::stationUIC || stationCodeTable == Fcb::v13::stationUICReservation;
24 }
25 constexpr inline static bool isUicCode(Fcb::v3::CodeTableType stationCodeTable)
26 {
27 return stationCodeTable == Fcb::v3::stationUIC || stationCodeTable == Fcb::v3::stationUICReservation;
28 }
29public:
30 /** Departure station identifier for a travel document,
31 * in the format needed for output with our JSON-LD format.
32 */
33 template <typename CodeTableTypeT, typename T>
34 [[nodiscard]] static QString fromStationIdentifier(CodeTableTypeT stationCodeTable, const T &doc)
35 {
36 if (isUicCode(stationCodeTable)) {
37 return stringifyUicStationIdentifier(doc.fromStationNum, doc.fromStationIA5);
38 }
39 qCWarning(Log) << "Unhandled station code table:" << stationCodeTable;
40 return stringifyStationIdentifier(doc.fromStationNumIsSet(), doc.fromStationNum, doc.fromStationIA5);
41 }
42 template <typename T>
43 [[nodiscard]] static QString fromStationIdentifier(const T &doc) { return fromStationIdentifier(doc.stationCodeTable, doc); }
44 /** Arrival station identifier for a travel document,
45 * in the format needed for output with our JSON-LD format.
46 */
47 template <typename CodeTableTypeT, typename T>
48 [[nodiscard]] static QString toStationIdentifier(CodeTableTypeT stationCodeTable, const T &doc)
49 {
50 if (isUicCode(stationCodeTable)) {
51 return stringifyUicStationIdentifier(doc.toStationNum, doc.toStationIA5);
52 }
53 qCWarning(Log) << "Unhandled station code table:" << stationCodeTable;
54 return stringifyStationIdentifier(doc.toStationNumIsSet(), doc.toStationNum, doc.toStationIA5);
55 }
56 template <typename T>
57 [[nodiscard]] static QString toStationIdentifier(const T &doc) { return toStationIdentifier(doc.stationCodeTable, doc); }
58
59 /** Convert a class code enum value to a string for human representation. */
60 [[nodiscard]] static QString classCodeToString(Fcb::v13::TravelClassType classCode);
61 [[nodiscard]] static QString classCodeToString(Fcb::v3::TravelClassType classCode);
62
63 /** Decode FCB date. */
64 [[nodiscard]] static QDate decodeDate(int year, std::optional<int> day);
65 [[nodiscard]] static QDate decodeDifferentialDate(const QDate &base, int year, std::optional<int> day);
66
67 /** Decode FCB issuing time. */
68 [[nodiscard]] static QDateTime issuingDateTime(int year, int day, std::optional<int> time);
69 /** Decode differential time, relative to @p baseDt. */
70 [[nodiscard]] static QDateTime decodeDifferentialTime(const QDateTime &baseDt, int day, std::optional<int> time, std::optional<int> utcOffset);
71 [[nodiscard]] static QDateTime decodeDifferentialStartTime(const QDateTime &baseDt, int day, std::optional<int> time, std::optional<int> utcOffset);
72 [[nodiscard]] static QDateTime decodeDifferentialEndTime(const QDateTime &baseDt, int day, std::optional<int> time, std::optional<int> utcOffset);
73
74private:
75 [[nodiscard]] static QString stringifyUicStationIdentifier(int num, const QByteArray &ia5);
76 [[nodiscard]] static QString stringifyStationIdentifier(bool numIsSet, int num, const QByteArray &ia5);
77};
78
79}
80
81#endif // KITINERARY_FCBUTIL_H
Higher-level decoding utilities for ERA FCB ticket data.
Definition fcbutil.h:19
static QString toStationIdentifier(CodeTableTypeT stationCodeTable, const T &doc)
Arrival station identifier for a travel document, in the format needed for output with our JSON-LD fo...
Definition fcbutil.h:48
static QString classCodeToString(Fcb::v13::TravelClassType classCode)
Convert a class code enum value to a string for human representation.
Definition fcbutil.cpp:30
static QString fromStationIdentifier(CodeTableTypeT stationCodeTable, const T &doc)
Departure station identifier for a travel document, in the format needed for output with our JSON-LD ...
Definition fcbutil.h:34
static QDateTime decodeDifferentialTime(const QDateTime &baseDt, int day, std::optional< int > time, std::optional< int > utcOffset)
Decode differential time, relative to baseDt.
Definition fcbutil.cpp:86
static QDateTime issuingDateTime(int year, int day, std::optional< int > time)
Decode FCB issuing time.
Definition fcbutil.cpp:77
static QDate decodeDate(int year, std::optional< int > day)
Decode FCB date.
Definition fcbutil.cpp:58
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:52:35 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.