[generator] Remove names for "boundary-administrative-*" features.

This commit is contained in:
vng 2014-04-01 18:18:52 +03:00 committed by Alex Zolotarev
parent 5f441c5e92
commit b1eabf79ee
6 changed files with 82 additions and 9 deletions

View file

@ -154,6 +154,13 @@ struct IdFunctor
}
};
template <class T> struct EqualFunctor
{
T const & m_t;
explicit EqualFunctor(T const & t) : m_t(t) {}
inline bool operator() (T const & t) const { return (t == m_t); }
};
template <typename IterT> IterT NextIterInCycle(IterT it, IterT beg, IterT end)
{
if (++it == end)

View file

@ -212,10 +212,31 @@ bool FeatureBuilder1::PreSerialize()
// AlexZ: Commented this line to enable captions on subway exits, which
// are not drawn but should be visible in balloons and search results
//RemoveNameIfInvisible();
RemoveUselessNames();
return true;
}
void FeatureBuilder1::RemoveUselessNames()
{
int64_t dummy;
if (!m_Params.name.IsEmpty() && !GetCoastCell(dummy))
{
using namespace feature;
char const * arr[] = { "boundary", "administrative" };
static TypeSetChecker checkBoundary(arr, ARRAY_SIZE(arr));
TypesHolder types(GetFeatureBase());
if (types.RemoveIf(bind(&TypeSetChecker::IsEqual, cref(checkBoundary), _1)))
{
pair<int, int> const range = GetDrawableScaleRangeForRules(types, RULE_ANY_TEXT);
if (range.first == -1)
m_Params.name.Clear();
}
}
}
void FeatureBuilder1::RemoveNameIfInvisible(int minS, int maxS)
{
int64_t dummy;

View file

@ -52,6 +52,7 @@ public:
/// Clear name if it's not visible in scale range [minS, maxS].
void RemoveNameIfInvisible(int minS = 0, int maxS = 1000);
void RemoveUselessNames();
template <class FnT> bool RemoveTypesIf(FnT fn)
{
@ -148,10 +149,10 @@ public:
else return false;
}
inline string GetName() const
inline string GetName(int8_t lang = StringUtf8Multilang::DEFAULT_CODE) const
{
string s;
m_Params.name.GetString(0, s);
m_Params.name.GetString(lang, s);
return s;
}

View file

@ -81,3 +81,36 @@ UNIT_TEST(FVisibility_RemoveNoDrawableTypes)
TEST(feature::RemoveNoDrawableTypes(types, feature::FEATURE_TYPE_AREA), ());
TEST_EQUAL(types.size(), 2, ());
}
UNIT_TEST(FBuilder_RemoveUselessNames)
{
classificator::Load();
FeatureParams params;
char const * arr3[][3] = { { "boundary", "administrative", "2" } };
AddTypes(params, arr3);
char const * arr2[][2] = { { "barrier", "fence" } };
AddTypes(params, arr2);
params.FinishAddingTypes();
params.name.AddString(0, "Name");
params.name.AddString(8, "Имя");
FeatureBuilder1 fb1;
fb1.SetParams(params);
fb1.AddPoint(m2::PointD(0, 0));
fb1.AddPoint(m2::PointD(1, 1));
fb1.SetLinear();
TEST(!fb1.GetName(0).empty(), ());
TEST(!fb1.GetName(8).empty(), ());
fb1.RemoveUselessNames();
TEST(fb1.GetName(0).empty(), ());
TEST(fb1.GetName(8).empty(), ());
TEST(fb1.CheckValid(), ());
}

View file

@ -3,7 +3,8 @@
#include "classificator.hpp"
#include "feature.hpp"
#include "../std/algorithm.hpp"
#include "../base/stl_add.hpp"
#include "../std/bind.hpp"
@ -31,12 +32,7 @@ string TypesHolder::DebugPrint() const
void TypesHolder::Remove(uint32_t t)
{
if (m_size > 0)
{
uint32_t * e = m_types + m_size;
if (std::remove(m_types, e, t) != e)
--m_size;
}
(void) RemoveIf(EqualFunctor<uint32_t>(t));
}
namespace

View file

@ -9,6 +9,7 @@
#include "../std/string.hpp"
#include "../std/vector.hpp"
#include "../std/algorithm.hpp"
class FeatureBase;
@ -92,7 +93,21 @@ namespace feature
}
//@}
template <class FnT> bool RemoveIf(FnT fn)
{
if (m_size > 0)
{
size_t const oldSize = m_size;
uint32_t * e = remove_if(m_types, m_types + m_size, fn);
m_size = distance(m_types, e);
return (m_size != oldSize);
}
return false;
}
void Remove(uint32_t t);
string DebugPrint() const;
/// Sort types by it's specification (more detailed type goes first).