diff --git a/generator/borders_loader.cpp b/generator/borders_loader.cpp index 3b343da80a..bb44fd22f4 100644 --- a/generator/borders_loader.cpp +++ b/generator/borders_loader.cpp @@ -176,8 +176,8 @@ void UnpackBorders(string const & baseDir, string const & targetDir) for (size_t id = 0; id < countries.size(); id++) { - ofstream poly(my::JoinFoldersToPath(targetDir, countries[id].m_name + ".poly")); - poly << countries[id].m_name << endl; + ofstream poly(my::JoinFoldersToPath(targetDir, countries[id].m_countryId + ".poly")); + poly << countries[id].m_countryId << endl; src = reader.GetReader(strings::to_string(id)); uint32_t const count = ReadVarUint(src); for (size_t i = 0; i < count; ++i) diff --git a/search/v2/geocoder.hpp b/search/v2/geocoder.hpp index 3cdefc2a22..c273aad162 100644 --- a/search/v2/geocoder.hpp +++ b/search/v2/geocoder.hpp @@ -118,7 +118,7 @@ public: { Region(Locality const & l, RegionType type) : Locality(l), m_center(0, 0), m_type(type) {} - storage::CountryInfoGetter::IdSet m_ids; + storage::CountryInfoGetter::TRegionIdSet m_ids; string m_enName; m2::PointD m_center; RegionType m_type; diff --git a/storage/country_decl.hpp b/storage/country_decl.hpp index f870df5547..c3bb3972d9 100644 --- a/storage/country_decl.hpp +++ b/storage/country_decl.hpp @@ -11,12 +11,12 @@ namespace storage struct CountryDef { /// File name without extension (equal to english name - used in search for region). - TCountryId m_name; + TCountryId m_countryId; m2::RectD m_rect; CountryDef() {} - CountryDef(string const & name, m2::RectD const & rect) - : m_name(name), m_rect(rect) + CountryDef(TCountryId const & countryId, m2::RectD const & rect) + : m_countryId(countryId), m_rect(rect) { } }; diff --git a/storage/country_info_getter.cpp b/storage/country_info_getter.cpp index 95100a1fdf..3994e618e5 100644 --- a/storage/country_info_getter.cpp +++ b/storage/country_info_getter.cpp @@ -39,9 +39,9 @@ public: void operator()(CountryDef const & c) { - if (c.m_name == "USA_Alaska") + if (c.m_countryId == "USA_Alaska") m_rects[1] = c.m_rect; - else if (c.m_name == "USA_Hawaii") + else if (c.m_countryId == "USA_Hawaii") m_rects[2] = c.m_rect; else m_rects[0].Add(c.m_rect); @@ -55,8 +55,8 @@ private: // CountryInfoGetter ------------------------------------------------------------------------------- TCountryId CountryInfoGetter::GetRegionCountryId(m2::PointD const & pt) const { - IdType const id = FindFirstCountry(pt); - return id != kInvalidId ? m_countries[id].m_name : kInvalidCountryId; + TRegionId const id = FindFirstCountry(pt); + return id != kInvalidId ? m_countries[id].m_countryId : kInvalidCountryId; } void CountryInfoGetter::GetRegionsCountryId(m2::PointD const & pt, TCountriesVec & closestCoutryIds) @@ -70,26 +70,26 @@ void CountryInfoGetter::GetRegionsCountryId(m2::PointD const & pt, TCountriesVec for (size_t id = 0; id < m_countries.size(); ++id) { if (m_countries[id].m_rect.IsIntersect(lookupRect) && IsCloseEnough(id, pt, kLookupRadiusM)) - closestCoutryIds.emplace_back(m_countries[id].m_name); + closestCoutryIds.emplace_back(m_countries[id].m_countryId); } } void CountryInfoGetter::GetRegionInfo(m2::PointD const & pt, CountryInfo & info) const { - IdType const id = FindFirstCountry(pt); + TRegionId const id = FindFirstCountry(pt); if (id != kInvalidId) - GetRegionInfo(m_countries[id].m_name, info); + GetRegionInfo(m_countries[id].m_countryId, info); } -void CountryInfoGetter::GetRegionInfo(string const & id, CountryInfo & info) const +void CountryInfoGetter::GetRegionInfo(TCountryId const & countryId, CountryInfo & info) const { - auto const it = m_id2info.find(id); + auto const it = m_id2info.find(countryId); if (it == m_id2info.end()) return; info = it->second; if (info.m_name.empty()) - info.m_name = id; + info.m_name = countryId; CountryInfo::FileName2FullName(info.m_name); } @@ -117,7 +117,7 @@ m2::RectD CountryInfoGetter::GetLimitRectForLeaf(TCountryId const & leafCountryI return m_countries[it->second].m_rect; } -void CountryInfoGetter::GetMatchedRegions(string const & affiliation, IdSet & regions) const +void CountryInfoGetter::GetMatchedRegions(string const & affiliation, TRegionIdSet & regions) const { CHECK(m_affiliations, ()); auto it = m_affiliations->find(affiliation); @@ -126,12 +126,12 @@ void CountryInfoGetter::GetMatchedRegions(string const & affiliation, IdSet & re for (size_t i = 0; i < m_countries.size(); ++i) { - if (binary_search(it->second.begin(), it->second.end(), m_countries[i].m_name)) + if (binary_search(it->second.begin(), it->second.end(), m_countries[i].m_countryId)) regions.push_back(i); } } -bool CountryInfoGetter::IsBelongToRegions(m2::PointD const & pt, IdSet const & regions) const +bool CountryInfoGetter::IsBelongToRegions(m2::PointD const & pt, TRegionIdSet const & regions) const { for (auto const & id : regions) { @@ -141,22 +141,28 @@ bool CountryInfoGetter::IsBelongToRegions(m2::PointD const & pt, IdSet const & r return false; } -bool CountryInfoGetter::IsBelongToRegions(string const & fileName, IdSet const & regions) const +bool CountryInfoGetter::IsBelongToRegions(TCountryId const & countryId, TRegionIdSet const & regions) const { for (auto const & id : regions) { - if (m_countries[id].m_name == fileName) + if (m_countries[id].m_countryId == countryId) return true; } return false; } +void CountryInfoGetter::RegionIdsToCountryIds(TRegionIdSet const & regions, TCountriesVec & countries) const +{ + for (auto const & id : regions) + countries.push_back(m_countries[id].m_countryId); +} + void CountryInfoGetter::InitAffiliationsInfo(TMappingAffiliations const * affiliations) { m_affiliations = affiliations; } -CountryInfoGetter::IdType CountryInfoGetter::FindFirstCountry(m2::PointD const & pt) const +CountryInfoGetter::TRegionId CountryInfoGetter::FindFirstCountry(m2::PointD const & pt) const { for (size_t id = 0; id < m_countries.size(); ++id) { @@ -176,7 +182,7 @@ void CountryInfoGetter::ForEachCountry(string const & prefix, ToDo && toDo) cons { for (auto const & country : m_countries) { - if (strings::StartsWith(country.m_name, prefix.c_str())) + if (strings::StartsWith(country.m_countryId, prefix.c_str())) toDo(country); } } @@ -234,7 +240,7 @@ CountryInfoReader::CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countr size_t const countrySz = m_countries.size(); m_countryIndex.reserve(countrySz); for (size_t i = 0; i < countrySz; ++i) - m_countryIndex[m_countries[i].m_name] = i; + m_countryIndex[m_countries[i].m_countryId] = i; string buffer; countryR.ReadAsString(buffer); @@ -318,16 +324,16 @@ CountryInfoGetterForTesting::CountryInfoGetterForTesting(vector cons void CountryInfoGetterForTesting::AddCountry(CountryDef const & country) { m_countries.push_back(country); - string const & name = country.m_name; + string const & name = country.m_countryId; m_id2info[name].m_name = name; } void CountryInfoGetterForTesting::GetMatchedRegions(string const & affiliation, - IdSet & regions) const + TRegionIdSet & regions) const { for (size_t i = 0; i < m_countries.size(); ++i) { - if (m_countries[i].m_name == affiliation) + if (m_countries[i].m_countryId == affiliation) regions.push_back(i); } } diff --git a/storage/country_info_getter.hpp b/storage/country_info_getter.hpp index 3bb974d9d1..e1108aa1c1 100644 --- a/storage/country_info_getter.hpp +++ b/storage/country_info_getter.hpp @@ -25,8 +25,8 @@ class CountryInfoGetter { public: // Identifier of a region (index in m_countries array). - using IdType = size_t; - using IdSet = vector; + using TRegionId = size_t; + using TRegionIdSet = vector; CountryInfoGetter(bool isSingleMwm) : m_isSingleMwm(isSingleMwm) {} virtual ~CountryInfoGetter() = default; @@ -45,8 +45,8 @@ public: // Returns info for a region |pt| belongs to. void GetRegionInfo(m2::PointD const & pt, CountryInfo & info) const; - // Returns info for a country by file name without an extension. - void GetRegionInfo(string const & id, CountryInfo & info) const; + // Returns info for a country by id. + void GetRegionInfo(TCountryId const & countryId, CountryInfo & info) const; // Return limit rects of USA: // 0 - continental part @@ -63,15 +63,17 @@ public: m2::RectD GetLimitRectForLeaf(TCountryId const & leafCountryId) const; // Returns identifiers for all regions matching to correspondent |affiliation|. - virtual void GetMatchedRegions(string const & affiliation, IdSet & regions) const; + virtual void GetMatchedRegions(string const & affiliation, TRegionIdSet & regions) const; // Returns true when |pt| belongs to at least one of the specified // |regions|. - bool IsBelongToRegions(m2::PointD const & pt, IdSet const & regions) const; + bool IsBelongToRegions(m2::PointD const & pt, TRegionIdSet const & regions) const; - // Returns true if there're at least one region with name equals to - // |fileName|. - bool IsBelongToRegions(string const & fileName, IdSet const & regions) const; + // Returns true if there're at least one region with id equals to + // |countryId|. + bool IsBelongToRegions(TCountryId const & countryId, TRegionIdSet const & regions) const; + + void RegionIdsToCountryIds(TRegionIdSet const & regions, TCountriesVec & countries) const; // Clears regions cache. inline void ClearCaches() const { ClearCachesImpl(); } @@ -82,7 +84,7 @@ protected: CountryInfoGetter() = default; // Returns identifier of a first country containing |pt|. - IdType FindFirstCountry(m2::PointD const & pt) const; + TRegionId FindFirstCountry(m2::PointD const & pt) const; // Invokes |toDo| on each country whose name starts with |prefix|. template @@ -102,7 +104,7 @@ protected: // List of all known countries. vector m_countries; // Maps all leaf country id (file names) to their indices in m_countries. - unordered_map m_countryIndex; + unordered_map m_countryIndex; TMappingAffiliations const * m_affiliations = nullptr; @@ -164,7 +166,7 @@ public: void AddCountry(CountryDef const & country); // CountryInfoGetter overrides: - void GetMatchedRegions(string const & affiliation, IdSet & regions) const override; + void GetMatchedRegions(string const & affiliation, TRegionIdSet & regions) const override; protected: // CountryInfoGetter overrides: diff --git a/storage/country_polygon.hpp b/storage/country_polygon.hpp index 630fdd7c8f..425e739907 100644 --- a/storage/country_polygon.hpp +++ b/storage/country_polygon.hpp @@ -12,7 +12,7 @@ namespace storage { template void Read(TSource & src, CountryDef & p) { - rw::Read(src, p.m_name); + rw::Read(src, p.m_countryId); pair r; r.first = ReadVarInt(src); @@ -22,7 +22,7 @@ namespace storage template void Write(TSink & sink, CountryDef const & p) { - rw::Write(sink, p.m_name); + rw::Write(sink, p.m_countryId); pair const r = RectToInt64(p.m_rect, serial::CodingParams().GetCoordBits()); WriteVarInt(sink, r.first);