From c843969f7e1d387464403fc7e468bef5c816fe48 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 20 Jan 2016 18:59:16 +0300 Subject: [PATCH] Rename ForEachNameRef -> ForEachName with rvalue reference functor passing. --- .../coding_tests/multilang_utf8_string_test.cpp | 3 +-- coding/multilang_utf8_string.cpp | 5 ++--- coding/multilang_utf8_string.hpp | 4 ++-- generator/dumper.cpp | 4 ++-- generator/search_index_builder.cpp | 2 +- indexer/feature.cpp | 16 ++++++++-------- indexer/feature.hpp | 5 +++-- indexer/feature_data.cpp | 5 +---- qt/editor_dialog.cpp | 2 +- search/search_query.cpp | 5 ++--- 10 files changed, 23 insertions(+), 28 deletions(-) diff --git a/coding/coding_tests/multilang_utf8_string_test.cpp b/coding/coding_tests/multilang_utf8_string_test.cpp index 6934a6660e..4b694454f7 100644 --- a/coding/coding_tests/multilang_utf8_string_test.cpp +++ b/coding/coding_tests/multilang_utf8_string_test.cpp @@ -74,8 +74,7 @@ UNIT_TEST(MultilangString_ForEach) for (size_t i = 0; i < ARRAY_SIZE(gArr); ++i) s.AddString(gArr[i].m_lang, gArr[i].m_str); - LangChecker doClass; - s.ForEachRef(doClass); + s.ForEach(LangChecker()); } UNIT_TEST(MultilangString_Unique) diff --git a/coding/multilang_utf8_string.cpp b/coding/multilang_utf8_string.cpp index a3432c07e8..eac7ea4513 100644 --- a/coding/multilang_utf8_string.cpp +++ b/coding/multilang_utf8_string.cpp @@ -139,14 +139,13 @@ struct Finder int8_t StringUtf8Multilang::FindString(string const & utf8s) const { Finder finder(utf8s); - ForEachRef(finder); + ForEach(finder); return finder.m_res; } string DebugPrint(StringUtf8Multilang const & s) { string out; - Printer printer(out); - s.ForEachRef(printer); + s.ForEach(Printer(out)); return out; } diff --git a/coding/multilang_utf8_string.hpp b/coding/multilang_utf8_string.hpp index 7c0efce963..7fe6f8ff3e 100644 --- a/coding/multilang_utf8_string.hpp +++ b/coding/multilang_utf8_string.hpp @@ -64,14 +64,14 @@ public: } template - void ForEachRef(T && functor) const + void ForEach(T && fn) const { size_t i = 0; size_t const sz = m_s.size(); while (i < sz) { size_t const next = GetNextIndex(i); - if (!functor((m_s[i] & 0x3F), m_s.substr(i + 1, next - i - 1))) + if (!fn((m_s[i] & 0x3F), m_s.substr(i + 1, next - i - 1))) return; i = next; } diff --git a/generator/dumper.cpp b/generator/dumper.cpp index 2620a16ad6..8357a3d05f 100644 --- a/generator/dumper.cpp +++ b/generator/dumper.cpp @@ -151,7 +151,7 @@ namespace feature void operator()(FeatureType & f, uint32_t) { - f.ForEachNameRef(*this); + f.ForEachName(*this); } }; @@ -228,7 +228,7 @@ namespace feature feature::ForEachFromDat(fPath, [&](FeatureType & f, uint32_t) { - f.ForEachNameRef(printName); + f.ForEachName(printName); }); } diff --git a/generator/search_index_builder.cpp b/generator/search_index_builder.cpp index 3eb9ff0340..dde49cbb76 100644 --- a/generator/search_index_builder.cpp +++ b/generator/search_index_builder.cpp @@ -277,7 +277,7 @@ public: m_valueBuilder.MakeValue(f, types, index, inserter.m_val); // Skip types for features without names. - if (!f.ForEachNameRef(inserter)) + if (!f.ForEachName(inserter)) skipIndex.SkipEmptyNameTypes(types); if (types.Empty()) return; diff --git a/indexer/feature.cpp b/indexer/feature.cpp index e49dd875a3..bf18707282 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -103,11 +103,11 @@ editor::XMLFeature FeatureType::ToXML() const if (GetFeatureType() == feature::GEOM_POINT) feature.SetCenter(GetCenter()); - ForEachNameRef([&feature](uint8_t const & lang, string const & name) - { - feature.SetName(lang, name); - return true; - }); + ForEachName([&feature](uint8_t const & lang, string const & name) + { + feature.SetName(lang, name); + return true; + }); string const house = GetHouseNumber(); if (!house.empty()) @@ -275,7 +275,7 @@ void FeatureType::SetNames(StringUtf8Multilang const & newNames) { m_params.name.Clear(); // Validate passed string to clean up empty names (if any). - newNames.ForEachRef([this](int8_t langCode, string const & name) -> bool + newNames.ForEach([this](int8_t langCode, string const & name) -> bool { if (!name.empty()) m_params.name.AddString(langCode, name); @@ -427,7 +427,7 @@ void FeatureType::GetPreferredNames(string & defaultName, string & intName) cons ParseCommon(); BestMatchedLangNames matcher; - ForEachNameRef(matcher); + ForEachName(matcher); defaultName.swap(matcher.m_defaultName); @@ -453,7 +453,7 @@ void FeatureType::GetReadableName(string & name) const ParseCommon(); BestMatchedLangNames matcher; - ForEachNameRef(matcher); + ForEachName(matcher); if (!matcher.m_nativeName.empty()) name.swap(matcher.m_nativeName); diff --git a/indexer/feature.hpp b/indexer/feature.hpp index 9c1ef8bf83..be53c9e7ac 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -10,6 +10,7 @@ #include "editor/xml_feature.hpp" #include "std/string.hpp" +#include "std/utility.hpp" namespace feature @@ -81,13 +82,13 @@ public: */ template - inline bool ForEachNameRef(T && functor) const + inline bool ForEachName(T && fn) const { if (!HasName()) return false; ParseCommon(); - m_params.name.ForEachRef(forward(functor)); + m_params.name.ForEach(forward(fn)); return true; } diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index fe4b8a9679..f3c9e025b9 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -175,11 +175,8 @@ bool FeatureParamsBase::CheckValid() const string FeatureParamsBase::DebugString() const { - string utf8name; - name.GetString(StringUtf8Multilang::DEFAULT_CODE, utf8name); - + string const utf8name = DebugPrint(name); return ((!utf8name.empty() ? "Name:" + utf8name : "") + - (" Layer:" + DebugPrint(layer)) + (rank != 0 ? " Rank:" + DebugPrint(rank) : "") + (!house.IsEmpty() ? " House:" + house.Get() : "") + (!ref.empty() ? " Ref:" + ref : "")); diff --git a/qt/editor_dialog.cpp b/qt/editor_dialog.cpp index f107e2b4d2..f0f5571e06 100644 --- a/qt/editor_dialog.cpp +++ b/qt/editor_dialog.cpp @@ -68,7 +68,7 @@ EditorDialog::EditorDialog(QWidget * parent, FeatureType const & feature, Framew defaultNameRow->addWidget(defaultNamelineEdit); vLayout->addLayout(defaultNameRow); - feature.ForEachNameRef([&](int8_t langCode, string const & name) -> bool + feature.ForEachName([&](int8_t langCode, string const & name) -> bool { if (langCode == StringUtf8Multilang::DEFAULT_CODE) defaultNamelineEdit->setText(QString::fromStdString(name)); diff --git a/search/search_query.cpp b/search/search_query.cpp index 5dd0bc1d9f..8b01e379b8 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -958,7 +958,7 @@ public: { } - bool operator()(signed char lang, string const & name) + bool operator()(int8_t lang, string const & name) { KeywordLangMatcher::ScoreT const score = m_keywordsScorer.Score(lang, name); if (m_score < score) @@ -973,8 +973,7 @@ public: void Query::GetBestMatchName(FeatureType const & f, string & name) const { - impl::BestNameFinder bestNameFinder(name, m_keywordsScorer); - (void)f.ForEachNameRef(bestNameFinder); + (void)f.ForEachName(impl::BestNameFinder(name, m_keywordsScorer)); } /// Makes continuous range for tokens and prefix.