mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Made list of countries mutable.
This commit is contained in:
parent
86aaa9673d
commit
c593f43629
2 changed files with 21 additions and 8 deletions
|
@ -248,14 +248,24 @@ const std::array<Info, 231> FallbackList = { {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
const std::array<Info, 231> &CountriesInstance::list() {
|
CountriesInstance::CountriesInstance() {
|
||||||
return FallbackList;
|
}
|
||||||
|
|
||||||
|
const std::vector<Info> &CountriesInstance::list() {
|
||||||
|
if (_list.empty()) {
|
||||||
|
_list = (FallbackList | ranges::to_vector);
|
||||||
|
}
|
||||||
|
return _list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CountriesInstance::setList(std::vector<Info> &&infos) {
|
||||||
|
_list = std::move(infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CountriesInstance::Map &CountriesInstance::byCode() {
|
const CountriesInstance::Map &CountriesInstance::byCode() {
|
||||||
if (_byCode.empty()) {
|
if (_byCode.empty()) {
|
||||||
_byCode.reserve(FallbackList.size());
|
_byCode.reserve(list().size());
|
||||||
for (const auto &entry : FallbackList) {
|
for (const auto &entry : list()) {
|
||||||
_byCode.insert(entry.code, &entry);
|
_byCode.insert(entry.code, &entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,8 +274,8 @@ const CountriesInstance::Map &CountriesInstance::byCode() {
|
||||||
|
|
||||||
const CountriesInstance::Map &CountriesInstance::byISO2() {
|
const CountriesInstance::Map &CountriesInstance::byISO2() {
|
||||||
if (_byISO2.empty()) {
|
if (_byISO2.empty()) {
|
||||||
_byISO2.reserve(FallbackList.size());
|
_byISO2.reserve(list().size());
|
||||||
for (const auto &entry : FallbackList) {
|
for (const auto &entry : list()) {
|
||||||
_byISO2.insert(entry.iso2, &entry);
|
_byISO2.insert(entry.iso2, &entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,9 @@ class CountriesInstance final {
|
||||||
public:
|
public:
|
||||||
using Map = QHash<QString, const Info *>;
|
using Map = QHash<QString, const Info *>;
|
||||||
|
|
||||||
CountriesInstance() = default;
|
CountriesInstance();
|
||||||
[[nodiscard]] const std::array<Info, 231> &list();
|
[[nodiscard]] const std::vector<Info> &list();
|
||||||
|
void setList(std::vector<Info> &&infos);
|
||||||
|
|
||||||
[[nodiscard]] const Map &byCode();
|
[[nodiscard]] const Map &byCode();
|
||||||
[[nodiscard]] const Map &byISO2();
|
[[nodiscard]] const Map &byISO2();
|
||||||
|
@ -32,6 +33,8 @@ public:
|
||||||
[[nodiscard]] QString countryISO2ByPhone(const QString &phone);
|
[[nodiscard]] QString countryISO2ByPhone(const QString &phone);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector<Info> _list;
|
||||||
|
|
||||||
Map _byCode;
|
Map _byCode;
|
||||||
Map _byISO2;
|
Map _byISO2;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue