KItinerary

stationidentifier.h
1/*
2 SPDX-FileCopyrightText: 2018-2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kitinerary_export.h"
10
11#include "alphaid.h"
12#include "knowledgedb.h"
13
14class QString;
15
16namespace KItinerary {
17namespace KnowledgeDb {
18
19/** Base class for UIC/IBNR station identifiers. */
21public:
22 inline explicit constexpr UICIdentiferBase() = default;
23 inline explicit constexpr UICIdentiferBase(uint32_t id) :
24 UnalignedNumber<3>(id > 9999999 ? id / 10 : id) // strip off check digit if present
25 {}
26
27 KITINERARY_EXPORT UICIdentiferBase(const QString &id);
28
29 inline constexpr bool isValid() const
30 {
31 return value() >= 1000000 && value() <= 9999999;
32 }
33};
34
35/** IBNR station id.
36 * 2 digits UIC country code, 5 digits station id.
37 * Same format as UICStation, but nevertheless different values.
38 */
39class IBNR : public UICIdentiferBase {
40 using UICIdentiferBase::UICIdentiferBase;
41};
42
43/** UIC station id.
44 * 2 digits UIC country code, 5 digits station id.
45 * Same format as IBNR, but nevertheless different values.
46 */
48 using UICIdentiferBase::UICIdentiferBase;
49};
50
51
52/** Base class for SNCF/Benerail station identifiers. */
53class FiveAlphaId : public UnalignedNumber<3> {
54public:
55 inline explicit constexpr FiveAlphaId() = default;
56 inline explicit constexpr FiveAlphaId(const char s[5])
57 : UnalignedNumber<3>(fromChars(s))
58 {
59 }
60
61 KITINERARY_EXPORT explicit FiveAlphaId(const QString &id);
62
63 inline constexpr bool isValid() const
64 {
65 return value() > 0;
66 }
67
68 KITINERARY_EXPORT QString toString() const;
69
70private:
71 static inline constexpr uint32_t fromChars(const char s[5])
72 {
73 return (s[4] - '@') + 27 * ((s[3] - '@') + 27 * ((s[2] - '@') + 27 * ((s[1] - '@') + 27 * (s[0] - '@'))));
74 }
75};
76
77/** SNCF station id.
78 * 2 letters ISO country code, 3 letters station id, expected to be in upper case.
79 */
81{
82 using FiveAlphaId::FiveAlphaId;
83};
84
85/** Benerail station id.
86 * 2 letters ISO country code, 3 letters station id, expected to be in upper case.
87 */
89{
90 using FiveAlphaId::FiveAlphaId;
91};
92
93
94/** VR (Finland) station codes.
95 * 2 to 4 letter uppercase alphabetic code.
96 */
98{
99public:
100 inline constexpr VRStationCode() = default;
101 inline explicit constexpr VRStationCode(const char s[4])
102 : UnalignedNumber<3>(fromChars(s))
103 {}
104 KITINERARY_EXPORT explicit VRStationCode(const QString &id);
105
106 [[nodiscard]] inline constexpr bool isValid() const
107 {
108 return value() > 0;
109 }
110
111 [[nodiscard]] KITINERARY_EXPORT QString toString() const;
112
113private:
114 [[nodiscard]] static inline constexpr uint32_t charVal(uint8_t c)
115 {
116 switch (c) {
117 case '\0': return 0;
118 case 0xC4: return 27; // Ä in Latin-1
119 case 0xD6: return 28; // Ö in Latin-1
120 }
121 return c - '@';
122 }
123 [[nodiscard]] static inline constexpr uint32_t fromChars(const char s[4])
124 {
125 return (charVal(s[0]) << 18) + (charVal(s[1]) << 12) + (charVal(s[2]) << 6) + charVal(s[3]);
126 }
127};
128
129/** Amtrak staion codes. */
131/** Via Rail station code. */
133/** UK railway station code. */
135}
136}
Base class for SNCF/Benerail station identifiers.
Base class for UIC/IBNR station identifiers.
Unalinged storage of a numerical value.
Definition knowledgedb.h:59
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-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.