diff --git a/editor/new_feature_categories.cpp b/editor/new_feature_categories.cpp index 90f033a728..456b076dfd 100644 --- a/editor/new_feature_categories.cpp +++ b/editor/new_feature_categories.cpp @@ -3,6 +3,7 @@ #include "indexer/categories_holder.hpp" #include "indexer/classificator.hpp" +#include "base/assert.hpp" #include "base/stl_helpers.hpp" #include "std/algorithm.hpp" @@ -31,35 +32,37 @@ NewFeatureCategories::NewFeatureCategories(editor::EditorConfig const & config) void NewFeatureCategories::AddLanguage(string const & lang) { auto const langCode = CategoriesHolder::MapLocaleToInteger(lang); - vector names; + NewFeatureCategories::TNames names; names.reserve(m_types.size()); for (auto const & type : m_types) { m_index.AddCategoryByTypeAndLang(type, langCode); - names.push_back(m_index.GetCategoriesHolder()->GetReadableFeatureType(type, langCode)); + names.emplace_back(m_index.GetCategoriesHolder()->GetReadableFeatureType(type, langCode), type); } my::SortUnique(names); - m_categoryNames[lang] = names; + m_categoriesByLang[lang] = names; } -vector NewFeatureCategories::Search(string const & query, string const & lang) const +NewFeatureCategories::TNames NewFeatureCategories::Search(string const & query, + string const & lang) const { auto const langCode = CategoriesHolder::MapLocaleToInteger(lang); vector resultTypes; m_index.GetAssociatedTypes(query, resultTypes); - vector result(resultTypes.size()); + NewFeatureCategories::TNames result(resultTypes.size()); for (size_t i = 0; i < result.size(); ++i) - result[i] = m_index.GetCategoriesHolder()->GetReadableFeatureType(resultTypes[i], langCode); + result[i] = {m_index.GetCategoriesHolder()->GetReadableFeatureType(resultTypes[i], langCode), + resultTypes[i]}; my::SortUnique(result); return result; } -vector NewFeatureCategories::GetAllCategoryNames(string const & lang) +NewFeatureCategories::TNames const & NewFeatureCategories::GetAllCategoryNames( + string const & lang) const { - auto const it = m_categoryNames.find(lang); - if (it == m_categoryNames.end()) - return {}; + auto const it = m_categoriesByLang.find(lang); + CHECK(it != m_categoriesByLang.end(), ()); return it->second; } } // namespace osm diff --git a/editor/new_feature_categories.hpp b/editor/new_feature_categories.hpp index 66f604dc2e..6f1ad89bf5 100644 --- a/editor/new_feature_categories.hpp +++ b/editor/new_feature_categories.hpp @@ -18,12 +18,15 @@ namespace osm class NewFeatureCategories { public: + using TName = pair; + using TNames = vector; + NewFeatureCategories(editor::EditorConfig const & config); NewFeatureCategories(NewFeatureCategories && other) : m_index(move(other.m_index)) , m_types(move(other.m_types)) - , m_categoryNames(move(other.m_categoryNames)) + , m_categoriesByLang(move(other.m_categoriesByLang)) { } @@ -35,19 +38,20 @@ public: // can be applied to a newly added feature. void AddLanguage(string const & lang); - // Returns names (in language |lang|) of categories that have a synonym containing + // Returns names (in language |lang|) and types of categories that have a synonym containing // the substring |query| (in any language that was added before). // The returned list is sorted. - vector Search(string const & query, string const & lang) const; + TNames Search(string const & query, string const & lang) const; - // Returns all registered names of categories in language |lang|. + // Returns all registered names of categories in language |lang| and + // types corresponding to these names. The language must have been added before. // The returned list is sorted. - vector GetAllCategoryNames(string const & lang); + TNames const & GetAllCategoryNames(string const & lang) const; private: indexer::CategoriesIndex m_index; vector m_types; - map> m_categoryNames; + map m_categoriesByLang; DISALLOW_COPY(NewFeatureCategories); }; diff --git a/indexer/categories_index.hpp b/indexer/categories_index.hpp index 02ac8d104e..7fb5a310c7 100644 --- a/indexer/categories_index.hpp +++ b/indexer/categories_index.hpp @@ -63,6 +63,9 @@ public: #endif private: + // There is a raw pointer instead of const reference + // here because this class may be used from Objectvie-C + // so a default constructor is needed. CategoriesHolder const * m_catHolder = nullptr; my::MemTrie m_trie; };