Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2016-04-27 18:31:39 +0300
committerAlex Zolotarev <alex@maps.me>2016-05-01 10:28:03 +0300
commit920f2577a35aba443ee33abf36050f7d0c66a505 (patch)
treec5bd60d11d032435e4d22c559c0ea71eb9fe676e /editor
parent21e50e2d5e3f2fca71cc4da012e6d2687ed773a2 (diff)
Now types are also returned along with category names.
Diffstat (limited to 'editor')
-rw-r--r--editor/new_feature_categories.cpp23
-rw-r--r--editor/new_feature_categories.hpp16
2 files changed, 23 insertions, 16 deletions
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<string> 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<string> 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<uint32_t> resultTypes;
m_index.GetAssociatedTypes(query, resultTypes);
- vector<string> 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<string> 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<string, uint32_t>;
+ using TNames = vector<TName>;
+
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<string> 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<string> GetAllCategoryNames(string const & lang);
+ TNames const & GetAllCategoryNames(string const & lang) const;
private:
indexer::CategoriesIndex m_index;
vector<uint32_t> m_types;
- map<string, vector<string>> m_categoryNames;
+ map<string, TNames> m_categoriesByLang;
DISALLOW_COPY(NewFeatureCategories);
};