mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +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
|
||||
|
||||
const std::array<Info, 231> &CountriesInstance::list() {
|
||||
return FallbackList;
|
||||
CountriesInstance::CountriesInstance() {
|
||||
}
|
||||
|
||||
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() {
|
||||
if (_byCode.empty()) {
|
||||
_byCode.reserve(FallbackList.size());
|
||||
for (const auto &entry : FallbackList) {
|
||||
_byCode.reserve(list().size());
|
||||
for (const auto &entry : list()) {
|
||||
_byCode.insert(entry.code, &entry);
|
||||
}
|
||||
}
|
||||
|
@ -264,8 +274,8 @@ const CountriesInstance::Map &CountriesInstance::byCode() {
|
|||
|
||||
const CountriesInstance::Map &CountriesInstance::byISO2() {
|
||||
if (_byISO2.empty()) {
|
||||
_byISO2.reserve(FallbackList.size());
|
||||
for (const auto &entry : FallbackList) {
|
||||
_byISO2.reserve(list().size());
|
||||
for (const auto &entry : list()) {
|
||||
_byISO2.insert(entry.iso2, &entry);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,9 @@ class CountriesInstance final {
|
|||
public:
|
||||
using Map = QHash<QString, const Info *>;
|
||||
|
||||
CountriesInstance() = default;
|
||||
[[nodiscard]] const std::array<Info, 231> &list();
|
||||
CountriesInstance();
|
||||
[[nodiscard]] const std::vector<Info> &list();
|
||||
void setList(std::vector<Info> &&infos);
|
||||
|
||||
[[nodiscard]] const Map &byCode();
|
||||
[[nodiscard]] const Map &byISO2();
|
||||
|
@ -32,6 +33,8 @@ public:
|
|||
[[nodiscard]] QString countryISO2ByPhone(const QString &phone);
|
||||
|
||||
private:
|
||||
std::vector<Info> _list;
|
||||
|
||||
Map _byCode;
|
||||
Map _byISO2;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue