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 inline constexpr bool isValid() const
107 {
108 return value() > 0;
109 }
110
111 KITINERARY_EXPORT QString toString() const;
112
113private:
114 static inline constexpr uint32_t charVal(const char c)
115 {
116 // TODO in theory there's apparently also 'Ä' amd 'Ö'?
117 return c == '\0' ? 0 : c - '@';
118 }
119 static inline constexpr uint32_t fromChars(const char s[4])
120 {
121 return (charVal(s[0]) << 18) + (charVal(s[1]) << 12) + (charVal(s[2]) << 6) + charVal(s[3]);
122 }
123};
124
125/** Amtrak staion codes. */
127/** Via Rail station code. */
129/** UK railway station code. */
131}
132}
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 Tue Mar 26 2024 11:14:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.