File indexing completed on 2024-05-12 04:42:51

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KPUBLICTRANSPORT_LINEMETADATA_P_H
0008 #define KPUBLICTRANSPORT_LINEMETADATA_P_H
0009 
0010 #include <cstdint>
0011 
0012 namespace KPublicTransport {
0013 
0014 #pragma pack(push)
0015 #pragma pack(1)
0016 
0017 /** Static color structure. */
0018 struct Color
0019 {
0020     explicit constexpr inline Color() = default;
0021     explicit constexpr inline Color(uint32_t rgb)
0022         : colorRed(rgb >> 16)
0023         , colorGreen(rgb >> 8)
0024         , colorBlue(rgb)
0025     {}
0026 
0027     enum : uint8_t { Invalid = 0x01 };
0028 
0029     uint8_t colorRed = Invalid;
0030     uint8_t colorGreen = Invalid;
0031     uint8_t colorBlue = Invalid;
0032 
0033     constexpr inline uint32_t argb() const
0034     {
0035         if (colorRed == Invalid && colorGreen == Invalid && colorRed == Invalid) {
0036             return 0;
0037         }
0038         return 0xff000000 | colorRed << 16 | colorGreen << 8 | colorBlue;
0039     }
0040 };
0041 
0042 /** Static informaytion about a public transport line as stored in .rodata. */
0043 struct LineMetaDataContent
0044 {
0045     enum Mode : uint16_t {
0046         Tramway,
0047         Subway,
0048         RapidTransit,
0049         LocalTrain,
0050         LongDistanceTrain,
0051     };
0052 
0053     constexpr inline LineMetaDataContent(uint16_t _nameIdx, uint16_t _logoIdx, uint16_t _prodLogoIdx, Mode _mode, Color _col)
0054         : nameIdx(_nameIdx)
0055         , mode(_mode)
0056         , logoIdx(_logoIdx)
0057         , productLogoIdx(_prodLogoIdx)
0058         , color(_col)
0059     {}
0060 
0061     uint16_t nameIdx : 13;
0062     Mode mode : 3;
0063     uint16_t logoIdx;
0064     uint16_t productLogoIdx;
0065 
0066     Color color;
0067 };
0068 
0069 /** Quad tree depth map entries. */
0070 struct LineMetaDataQuadTreeDepthIndex
0071 {
0072     uint8_t depth;
0073     uint16_t offset;
0074 };
0075 
0076 inline bool operator<(LineMetaDataQuadTreeDepthIndex lhs, uint8_t rhs)
0077 {
0078     return lhs.depth > rhs;
0079 }
0080 
0081 /** z-index to line meta data index mapping. */
0082 struct LineMetaDataZIndex
0083 {
0084     uint32_t z;
0085     uint16_t lineIdx;
0086 };
0087 
0088 static_assert(sizeof(LineMetaDataZIndex) == 6, "size of quad tree entry changed!");
0089 static_assert(sizeof(LineMetaDataZIndex) % alignof(LineMetaDataZIndex) == 0, "alignment of quad tree entry introduces padding");
0090 
0091 inline bool operator<(LineMetaDataZIndex lhs, uint32_t rhs)
0092 {
0093     return lhs.z < rhs;
0094 }
0095 
0096 #pragma pack(pop)
0097 
0098 }
0099 
0100 #endif // KPUBLICTRANSPORT_LINEMETADATA_P_H