KItinerary

countrydb.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 "config-kitinerary.h"
8#include "countrydb.h"
9#include "countrydb_data.cpp"
10
11#include <QDebug>
12#include <QString>
13
14#include <algorithm>
15
16using namespace KItinerary;
17using namespace KItinerary::KnowledgeDb;
18
19static_assert(sizeof(CountryId) <= 2, "CountryId too large");
20
22{
23 const auto it = std::lower_bound(std::begin(country_table), std::end(country_table), id, [](const Country &lhs, CountryId rhs) {
24 return lhs.id < rhs;
25 });
26 if (it == std::end(country_table) || (*it).id != id) {
27 return {CountryId{}, DrivingSide::Unknown, Unknown};
28 }
29 return (*it);
30}
31
32struct PowerPlugCompatMap {
33 PowerPlugType plug;
34 PowerPlugTypes sockets;
35};
36
37static const PowerPlugCompatMap power_plug_compat_map[] = {
38 { TypeA, TypeA | TypeB },
39 { TypeB, TypeB },
40 { TypeC, TypeC | TypeE | TypeF | TypeH | TypeJ | TypeK | TypeL | TypeN },
41 { TypeD, TypeD },
42 { TypeE, TypeE | TypeF | TypeK }, // TypeE <-> TypeF not strictly correct, but in practice almost always compatible
43 { TypeF, TypeE | TypeF | TypeK },
44 { TypeG, TypeG },
45 { TypeH, TypeH },
46 { TypeI, TypeI },
47 { TypeJ, TypeJ },
48 { TypeK, TypeK },
49 { TypeL, TypeL },
50 { TypeM, TypeM },
51 { TypeN, TypeN }
52};
53
55{
56 PowerPlugTypes failPlugs{};
57 for (const auto map : power_plug_compat_map) {
58 if ((plugs & map.plug) == 0) {
59 continue;
60 }
61 if ((map.sockets & sockets) == 0) {
62 failPlugs |= map.plug;
63 }
64 }
65 return failPlugs;
66}
67
69{
70 PowerPlugTypes failSockets{};
71 for (const auto map : power_plug_compat_map) {
72 if ((plugs & map.plug) == 0) {
73 continue;
74 }
75 if ((map.sockets & ~sockets) != 0) {
76 failSockets |= (map.sockets ^ sockets) & sockets;
77 }
78 }
79 return failSockets & ~plugs;
80}
81
83{
84 const auto it = std::lower_bound(std::begin(uic_country_code_table), std::end(uic_country_code_table), uicCountryCode, [](const auto &lhs, uint16_t rhs) {
85 return lhs.uicCode < rhs;
86 });
87 if (it == std::end(uic_country_code_table) || (*it).uicCode != uicCountryCode) {
88 return {};
89 }
90
91 return (*it).isoCode;
92}
93
94#include "moc_countrydb.cpp"
Lookup functions, utilities and data types for the static knowledge database.
Definition airportdb.cpp:21
AlphaId< uint16_t, 2 > CountryId
ISO 3166-1 alpha 2 country identifier.
Definition countrydb.h:22
PowerPlugTypes incompatiblePowerSockets(PowerPlugTypes plugs, PowerPlugTypes sockets)
Returns the power sockets out pf sockets that are unable to receive plugs out of plugs,...
Definition countrydb.cpp:68
Country countryForId(CountryId id)
Look up country information by id.
Definition countrydb.cpp:21
CountryId countryIdForUicCode(uint16_t uicCountryCode)
Look up country ISO code from a UIC country code.
Definition countrydb.cpp:82
PowerPlugType
Power plug types.
Definition countrydb.h:35
@ TypeF
Schuko plug.
Definition countrydb.h:42
@ TypeI
Australian plug.
Definition countrydb.h:45
@ TypeE
French plug.
Definition countrydb.h:41
@ TypeH
Israel plug.
Definition countrydb.h:44
@ TypeK
Danish plug.
Definition countrydb.h:47
@ TypeN
Type N (Brasilian)
Definition countrydb.h:50
@ TypeB
US three-pin plugs.
Definition countrydb.h:38
@ TypeA
US two-pin plugs.
Definition countrydb.h:37
PowerPlugTypes incompatiblePowerPlugs(PowerPlugTypes plugs, PowerPlugTypes sockets)
Returns the power plugs out of plugs that won't fit into sockets.
Definition countrydb.cpp:54
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
Country information.
Definition countrydb.h:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:28:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.