Rename ForEachNameRef -> ForEachName with rvalue reference functor passing.

This commit is contained in:
vng 2016-01-20 18:59:16 +03:00 committed by Sergey Yershov
parent 38f6a6e10e
commit c843969f7e
10 changed files with 23 additions and 28 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -64,14 +64,14 @@ public:
}
template <class T>
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;
}

View file

@ -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);
});
}

View file

@ -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;

View file

@ -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);

View file

@ -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 <class T>
inline bool ForEachNameRef(T && functor) const
inline bool ForEachName(T && fn) const
{
if (!HasName())
return false;
ParseCommon();
m_params.name.ForEachRef(forward<T>(functor));
m_params.name.ForEach(forward<T>(fn));
return true;
}

View file

@ -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 : ""));

View file

@ -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));

View file

@ -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.