1 /*
2    SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3 
4    SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "countrydb.h"
10 #include "timezonedb.h"
11 
12 namespace KItinerary {
13 namespace KnowledgeDb  {
14 
15 // country to timezone mapping (for countries where this is unique)
16 struct CountryTimezoneMap {
17     CountryId country;
18     Tz timezone;
19 };
20 
21 inline constexpr bool operator<(const CountryTimezoneMap lhs, const CountryId rhs)
22 {
23     return lhs.country < rhs;
24 }
25 
26 // encoding parameters for the timezone index
27 struct TimezoneZIndexParams {
28     float   xStart;
29     float   xRange;
30     float   yStart;
31     float   yRange;
32     uint8_t zDepth;
33 
yEndTimezoneZIndexParams34     constexpr inline float yEnd() const { return yStart + yRange; }
35 };
36 
37 // geo coordinate to timezone index entry
38 // Note: MSVC cannot create bitfields across unsigned integer types and enums/bools (as those are signed there)
39 // so we need to use a single type for the bitfield and do the conversion manually (and very forcefully)
40 struct TimezoneZIndexEntry {
TimezoneZIndexEntryTimezoneZIndexEntry41     inline constexpr TimezoneZIndexEntry(uint32_t _z, Tz _tz, bool _isAmbiguous)
42         : z(_z)
43         , tz(uint32_t(_tz))
44         , isAmbiguous(_isAmbiguous)
45     {}
46 
47     uint32_t z: 22;
48     uint32_t tz: 9;
49     uint32_t isAmbiguous: 1;
50 };
51 
52 static_assert(sizeof(TimezoneZIndexEntry) == 4, "structure is size-sensitive");
53 
54 inline constexpr bool operator<(uint32_t lhs, TimezoneZIndexEntry rhs)
55 {
56     return lhs < rhs.z;
57 }
58 
59 }
60 }
61 
62