| 1 | /* |
|---|---|
| 2 | SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef ISOCODESCACHE_P_H |
| 8 | #define ISOCODESCACHE_P_H |
| 9 | |
| 10 | #include "mapentry_p.h" |
| 11 | |
| 12 | #include <QByteArray> |
| 13 | #include <QStringView> |
| 14 | |
| 15 | #include <cstdint> |
| 16 | #include <memory> |
| 17 | #include <vector> |
| 18 | |
| 19 | class QFile; |
| 20 | |
| 21 | /*! |
| 22 | * Cache for iso-codes JSON data. |
| 23 | * |
| 24 | * \internal |
| 25 | */ |
| 26 | class IsoCodesCache |
| 27 | { |
| 28 | public: |
| 29 | ~IsoCodesCache(); |
| 30 | |
| 31 | static IsoCodesCache *instance(); |
| 32 | |
| 33 | void loadIso3166_1(); |
| 34 | void loadIso3166_2(); |
| 35 | |
| 36 | uint32_t countryCount() const; |
| 37 | const MapEntry<uint16_t> *countryNameMapBegin() const; |
| 38 | inline const MapEntry<uint16_t> *countryNameMapEnd() const |
| 39 | { |
| 40 | return countryNameMapBegin() + countryCount(); |
| 41 | } |
| 42 | const MapEntry<uint16_t> *countryAlpha3MapBegin() const; |
| 43 | inline const MapEntry<uint16_t> *countryAlpha3MapEnd() const |
| 44 | { |
| 45 | return countryAlpha3MapBegin() + countryCount(); |
| 46 | } |
| 47 | const char *countryStringTableLookup(uint16_t offset) const; |
| 48 | |
| 49 | uint32_t subdivisionCount() const; |
| 50 | const MapEntry<uint32_t> *subdivisionNameMapBegin() const; |
| 51 | inline const MapEntry<uint32_t> *subdivisionNameMapEnd() const |
| 52 | { |
| 53 | return subdivisionNameMapBegin() + subdivisionCount(); |
| 54 | } |
| 55 | uint32_t subdivisionHierachyMapSize() const; |
| 56 | const MapEntry<uint32_t> *subdivisionParentMapBegin() const; |
| 57 | inline const MapEntry<uint32_t> *subdivisionParentMapEnd() const |
| 58 | { |
| 59 | return subdivisionParentMapBegin() + subdivisionHierachyMapSize(); |
| 60 | } |
| 61 | const char *subdivisionStringTableLookup(uint16_t offset) const; |
| 62 | |
| 63 | static void createIso3166_1Cache(const QString &isoCodesPath, const QString &cacheFilePath); |
| 64 | static void createIso3166_2Cache(const QString &isoCodesPath, const QString &cacheFilePath); |
| 65 | |
| 66 | private: |
| 67 | bool loadIso3166_1Cache(); |
| 68 | bool loadIso3166_2Cache(); |
| 69 | |
| 70 | std::unique_ptr<QFile> m_iso3166_1CacheFile; |
| 71 | const uint8_t *m_iso3166_1CacheData = nullptr; |
| 72 | std::size_t m_iso3166_1CacheSize = 0; |
| 73 | std::unique_ptr<QFile> m_iso3166_2CacheFile; |
| 74 | const uint8_t *m_iso3166_2CacheData = nullptr; |
| 75 | std::size_t m_iso3166_2CacheSize = 0; |
| 76 | }; |
| 77 | |
| 78 | #endif // ISOCODESCACHE_H |
| 79 |
