diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2019-06-11 13:15:17 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2019-06-13 16:15:51 +0300 |
commit | 68c33fc33a63aedb11535918f7d109f3298d85fc (patch) | |
tree | e4576263e6405ad5eb5a86f2a41882046c6fe7a0 /storage | |
parent | 580839ff032f40434864e3ecdc95ee9b66fd0c0e (diff) |
[promo][storage] Load promo city ids from countries.txt
Diffstat (limited to 'storage')
-rw-r--r-- | storage/country_tree.cpp | 30 | ||||
-rw-r--r-- | storage/country_tree.hpp | 2 | ||||
-rw-r--r-- | storage/storage.cpp | 7 | ||||
-rw-r--r-- | storage/storage.hpp | 3 | ||||
-rw-r--r-- | storage/storage_defines.hpp | 4 |
5 files changed, 39 insertions, 7 deletions
diff --git a/storage/country_tree.cpp b/storage/country_tree.cpp index 512e7370ec..49769add01 100644 --- a/storage/country_tree.cpp +++ b/storage/country_tree.cpp @@ -10,6 +10,7 @@ #include "base/stl_helpers.hpp" #include <algorithm> +#include <cstdint> #include <utility> #include "3party/jansson/myjansson.hpp" @@ -36,6 +37,7 @@ public: virtual void InsertOldMwmMapping(CountryId const & newId, CountryId const & oldId) = 0; virtual void InsertAffiliation(CountryId const & countryId, string const & affilation) = 0; virtual void InsertCountryNameSynonym(CountryId const & countryId, string const & synonym) = 0; + virtual void InsertPromoCatalogCity(CountryId const & countryId, uint64_t const & geoObjectId) {} virtual OldMwmMapping GetMapping() const = 0; }; @@ -44,14 +46,17 @@ class StoreCountriesSingleMwms : public StoreSingleMwmInterface CountryTree & m_countries; Affiliations & m_affiliations; CountryNameSynonyms & m_countryNameSynonyms; + PromoCatalogCities & m_promoCatalogCities; OldMwmMapping m_idsMapping; public: StoreCountriesSingleMwms(CountryTree & countries, Affiliations & affiliations, - CountryNameSynonyms & countryNameSynonyms) + CountryNameSynonyms & countryNameSynonyms, + PromoCatalogCities & promoCatalogCities) : m_countries(countries) , m_affiliations(affiliations) , m_countryNameSynonyms(countryNameSynonyms) + , m_promoCatalogCities(promoCatalogCities) { } ~StoreCountriesSingleMwms() @@ -99,6 +104,14 @@ public: m_countryNameSynonyms[synonym] = countryId; } + void InsertPromoCatalogCity(CountryId const & countryId, uint64_t const & geoObjectId) override + { + ASSERT(!countryId.empty(), ()); + ASSERT_NOT_EQUAL(geoObjectId, 0, ()); + base::GeoObjectId id(geoObjectId); + m_promoCatalogCities.emplace(countryId, move(id)); + } + OldMwmMapping GetMapping() const override { return m_idsMapping; } }; @@ -335,6 +348,11 @@ MwmSubtreeAttrs LoadGroupSingleMwmsImpl(size_t depth, json_t * node, CountryId c for (auto const & affilationValue : affiliations) store.InsertAffiliation(id, affilationValue); + uint64_t geoObjectId = 0; + FromJSONObjectOptionalField(node, "pc", geoObjectId); + if (geoObjectId != 0) + store.InsertPromoCatalogCity(id, geoObjectId); + int nodeSize; FromJSONObjectOptionalField(node, "s", nodeSize); ASSERT_LESS_OR_EQUAL(0, nodeSize, ()); @@ -510,6 +528,7 @@ bool LoadCountriesTwoComponentMwmsImpl(string const & jsonBuffer, int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countries, Affiliations & affiliations, CountryNameSynonyms & countryNameSynonyms, + PromoCatalogCities & promoCatalogCities, OldMwmMapping * mapping /* = nullptr */) { countries.Clear(); @@ -523,7 +542,8 @@ int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countri if (version::IsSingleMwm(version)) { - StoreCountriesSingleMwms store(countries, affiliations, countryNameSynonyms); + StoreCountriesSingleMwms store(countries, affiliations, countryNameSynonyms, + promoCatalogCities); if (!LoadCountriesSingleMwmsImpl(jsonBuffer, store)) return -1; if (mapping) @@ -545,11 +565,13 @@ int64_t LoadCountriesFromBuffer(string const & jsonBuffer, CountryTree & countri int64_t LoadCountriesFromFile(string const & path, CountryTree & countries, Affiliations & affiliations, - CountryNameSynonyms & countryNameSynonyms, OldMwmMapping * mapping) + CountryNameSynonyms & countryNameSynonyms, + PromoCatalogCities & promoCatalogCities, OldMwmMapping * mapping) { string json; ReaderPtr<Reader>(GetPlatform().GetReader(path)).ReadAsString(json); - return LoadCountriesFromBuffer(json, countries, affiliations, countryNameSynonyms, mapping); + return LoadCountriesFromBuffer(json, countries, affiliations, countryNameSynonyms, + promoCatalogCities, mapping); } void LoadCountryFile2CountryInfo(string const & jsonBuffer, map<string, CountryInfo> & id2info, diff --git a/storage/country_tree.hpp b/storage/country_tree.hpp index c4cd916a78..fbcca4a525 100644 --- a/storage/country_tree.hpp +++ b/storage/country_tree.hpp @@ -119,10 +119,12 @@ private: int64_t LoadCountriesFromBuffer(std::string const & buffer, CountryTree & countries, Affiliations & affiliations, CountryNameSynonyms & countryNameSynonyms, + PromoCatalogCities & promoCatalogCities, OldMwmMapping * mapping = nullptr); int64_t LoadCountriesFromFile(std::string const & path, CountryTree & countries, Affiliations & affiliations, CountryNameSynonyms & countryNameSynonyms, + PromoCatalogCities & promoCatalogCities, OldMwmMapping * mapping = nullptr); void LoadCountryFile2CountryInfo(std::string const & jsonBuffer, diff --git a/storage/storage.cpp b/storage/storage.cpp index f830a01262..fcb2c7eb88 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -141,8 +141,9 @@ Storage::Storage(string const & referenceCountriesTxtJsonForTesting, , m_downloadMapOnTheMap(nullptr) , m_maxMwmSizeBytes(0) { - m_currentVersion = LoadCountriesFromBuffer(referenceCountriesTxtJsonForTesting, m_countries, - m_affiliations, m_countryNameSynonyms); + m_currentVersion = + LoadCountriesFromBuffer(referenceCountriesTxtJsonForTesting, m_countries, m_affiliations, + m_countryNameSynonyms, m_promoCatalogCities); CHECK_LESS_OR_EQUAL(0, m_currentVersion, ("Can't load test countries file")); CalcMaxMwmSizeBytes(); } @@ -763,7 +764,7 @@ void Storage::LoadCountriesFile(string const & pathToCountriesFile, string const if (m_countries.IsEmpty()) { m_currentVersion = LoadCountriesFromFile(pathToCountriesFile, m_countries, m_affiliations, - m_countryNameSynonyms, mapping); + m_countryNameSynonyms, m_promoCatalogCities, mapping); LOG_SHORT(LINFO, ("Loaded countries list for version:", m_currentVersion)); if (m_currentVersion < 0) LOG(LERROR, ("Can't load countries file", pathToCountriesFile)); diff --git a/storage/storage.hpp b/storage/storage.hpp index d799cd2d1d..ecab27d3aa 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -264,6 +264,7 @@ private: // Note. |m_affiliations| is empty in case of countries_obsolete.txt. Affiliations m_affiliations; CountryNameSynonyms m_countryNameSynonyms; + PromoCatalogCities m_promoCatalogCities; MwmSize m_maxMwmSizeBytes; @@ -472,6 +473,8 @@ public: CountryNameSynonyms const & GetCountryNameSynonyms() const { return m_countryNameSynonyms; } + PromoCatalogCities const & GetPromoCatalogCities() const { return m_promoCatalogCities; } + /// \brief Calls |toDo| for each node for subtree with |root|. /// For example ForEachInSubtree(GetRootId()) calls |toDo| for every node including /// the result of GetRootId() call. diff --git a/storage/storage_defines.hpp b/storage/storage_defines.hpp index 4d4cefd36a..a93d7ab29b 100644 --- a/storage/storage_defines.hpp +++ b/storage/storage_defines.hpp @@ -2,6 +2,8 @@ #include "platform/local_country_file.hpp" +#include "base/geo_object_id.hpp" + #include <cstdint> #include <functional> #include <map> @@ -23,6 +25,8 @@ using OldMwmMapping = std::map<CountryId, CountriesSet>; using Affiliations = std::unordered_map<std::string, std::vector<CountryId>>; /// Map from country name synonyms and old names into CountryId. using CountryNameSynonyms = std::unordered_map<std::string, CountryId>; +/// Map from CountryId into promo catalog cities GeoObject id. +using PromoCatalogCities = std::unordered_map<CountryId, base::GeoObjectId>; extern const storage::CountryId kInvalidCountryId; |