KItinerary

trainstationdb.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "trainstationdb.h"
8#include "trainstationdb_data.cpp"
9
10#include <QString>
11
12#include <algorithm>
13#include <cstring>
14
15using namespace KItinerary;
16using namespace KItinerary::KnowledgeDb;
17
18namespace KItinerary {
19namespace KnowledgeDb {
20
21static const auto trainstation_table_size = sizeof(trainstation_table) / sizeof(TrainStation);
22static_assert(trainstation_table_size < (1 << (sizeof(TrainStationIndex) * 8)), "TrainStationIndex data type too small!");
23
24}
25}
26
27template <typename Id, std::size_t Size>
28static TrainStation lookupStation(Id id, const TrainStationIdIndex<Id>(&tab)[Size])
29{
30 const auto it = std::lower_bound(std::begin(tab), std::end(tab), id);
31 if (it == std::end(tab) || (*it).stationId != id) {
32 return {};
33 }
34
35 return trainstation_table[(*it).stationIndex.value()];
36}
37
39{
40 return lookupStation(ibnr, ibnr_table);
41}
42
44{
45 return lookupStation(uic, uic_table);
46}
47
49{
50 return lookupStation(sncfId, sncfStationId_table);
51}
52
54{
55 const auto codeStr = code.toUtf8();
56 const auto it = std::lower_bound(std::begin(indianRailwaysSationCode_index), std::end(indianRailwaysSationCode_index), codeStr, [](auto lhs, const QByteArray &rhs) {
57 return strcmp(indianRailwaysSationCode_stringtable + lhs.offset, rhs.constData()) < 0;
58 });
59 if (it == std::end(indianRailwaysSationCode_index) || strcmp(indianRailwaysSationCode_stringtable + (*it).offset, codeStr.constData()) != 0) {
60 return {};
61 }
62
63 return trainstation_table[(*it).stationIndex.value()];
64}
65
67{
68 return lookupStation(vrStation, vrfiConnexionsId_table);
69}
70
72{
73 return lookupStation(id, benerail_table);
74}
75
77{
78 return lookupStation(iataCode, iata_table);
79}
80
82{
83 return lookupStation(code, amtrak_table);
84}
85
87{
88 return lookupStation(code, viarail_table);
89}
90
92{
93 return lookupStation(code, uk_table);
94}
Position in the train station database.
Train station.
Definition place.h:126
Lookup functions, utilities and data types for the static knowledge database.
Definition airportdb.cpp:21
TrainStation stationForViaRailStationCode(ViaRailStationCode code)
Lookup train station data by Via Rail station code.
TrainStation stationForUkRailwayStationCode(UKRailwayStationCode code)
Lookup train station data by UK railway station code.
TrainStation stationForIbnr(IBNR ibnr)
Lookup train station data by IBNR.
TrainStation stationForAmtrakStationCode(AmtrakStationCode code)
Lookup train station data by Amtrak station code.
TrainStation stationForUic(UICStation uic)
Lookup train station data by UIC station id.
TrainStation stationForIndianRailwaysStationCode(const QString &code)
Lookup train station data by Indian Railways station code.
TrainStation stationForSncfStationId(SncfStationId sncfId)
Lookup train station data by SNCF station id.
TrainStation stationForVRStationCode(VRStationCode vrStation)
Lookup train station data by VR (Finland) station code.
TrainStation stationForIataCode(IataCode iataCode)
Lookup train station data by IATA location code.
TrainStation stationForBenerailId(BenerailStationId id)
Lookup train station data by Benerail station identifier.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
const char * constData() const const
QByteArray toUtf8() const const
Train station id to station index lookup table structure.
Train station entry in the station table.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:14:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.