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
19class QFile;
20
21/** Cache for iso-codes JSON data. */
22class IsoCodesCache
23{
24public:
25 ~IsoCodesCache();
26
27 static IsoCodesCache *instance();
28
29 void loadIso3166_1();
30 void loadIso3166_2();
31
32 uint32_t countryCount() const;
33 const MapEntry<uint16_t> *countryNameMapBegin() const;
34 inline const MapEntry<uint16_t> *countryNameMapEnd() const
35 {
36 return countryNameMapBegin() + countryCount();
37 }
38 const MapEntry<uint16_t> *countryAlpha3MapBegin() const;
39 inline const MapEntry<uint16_t> *countryAlpha3MapEnd() const
40 {
41 return countryAlpha3MapBegin() + countryCount();
42 }
43 const char *countryStringTableLookup(uint16_t offset) const;
44
45 uint32_t subdivisionCount() const;
46 const MapEntry<uint32_t> *subdivisionNameMapBegin() const;
47 inline const MapEntry<uint32_t> *subdivisionNameMapEnd() const
48 {
49 return subdivisionNameMapBegin() + subdivisionCount();
50 }
51 uint32_t subdivisionHierachyMapSize() const;
52 const MapEntry<uint32_t> *subdivisionParentMapBegin() const;
53 inline const MapEntry<uint32_t> *subdivisionParentMapEnd() const
54 {
55 return subdivisionParentMapBegin() + subdivisionHierachyMapSize();
56 }
57 const char *subdivisionStringTableLookup(uint16_t offset) const;
58
59 static void createIso3166_1Cache(const QString &isoCodesPath, const QString &cacheFilePath);
60 static void createIso3166_2Cache(const QString &isoCodesPath, const QString &cacheFilePath);
61
62private:
63 bool loadIso3166_1Cache();
64 bool loadIso3166_2Cache();
65
66 std::unique_ptr<QFile> m_iso3166_1CacheFile;
67 const uint8_t *m_iso3166_1CacheData = nullptr;
68 std::size_t m_iso3166_1CacheSize = 0;
69 std::unique_ptr<QFile> m_iso3166_2CacheFile;
70 const uint8_t *m_iso3166_2CacheData = nullptr;
71 std::size_t m_iso3166_2CacheSize = 0;
72};
73
74#endif // ISOCODESCACHE_H
75

source code of ki18n/src/localedata/isocodescache_p.h