forked from organicmaps/organicmaps
Add type matchers for ATM and Fuel Station
This commit is contained in:
parent
8f6b34bdb4
commit
28a248389d
6 changed files with 80 additions and 38 deletions
|
@ -526,7 +526,8 @@ namespace feature
|
|||
|
||||
uint32_t const ftID = WriteFeatureBase(holder.m_buffer.m_buffer, fb);
|
||||
|
||||
if (!fb.GetMetadata().Empty()) {
|
||||
if (!fb.GetMetadata().Empty())
|
||||
{
|
||||
uint64_t offset = m_MetadataWriter->Pos();
|
||||
m_MetadataIndex.push_back(make_pair(ftID, static_cast<uint32_t>(offset)));
|
||||
fb.GetMetadata().SerializeToMWM(*m_MetadataWriter);
|
||||
|
|
|
@ -12,56 +12,56 @@ UNIT_TEST(Metadata_ValidateAndFormat_stars)
|
|||
MetadataTagProcessor p(params);
|
||||
|
||||
// ignore incorrect values
|
||||
p("stars","0");
|
||||
p("stars", "0");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
p("stars","-1");
|
||||
p("stars", "-1");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
p("stars","aasdasdas");
|
||||
p("stars", "aasdasdas");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
p("stars","8");
|
||||
p("stars", "8");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
p("stars","10");
|
||||
p("stars", "10");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
p("stars","910");
|
||||
p("stars", "910");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
p("stars","100");
|
||||
p("stars", "100");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
|
||||
// check correct values
|
||||
p("stars","1");
|
||||
p("stars", "1");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "1", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
p("stars","2");
|
||||
p("stars", "2");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "2", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
p("stars","3");
|
||||
p("stars", "3");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "3", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
p("stars","4");
|
||||
p("stars", "4");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "4", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
p("stars","5");
|
||||
p("stars", "5");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "5", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
p("stars","6");
|
||||
p("stars", "6");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "6", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
p("stars","7");
|
||||
p("stars", "7");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "7", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
// check almost correct values
|
||||
p("stars","4+");
|
||||
p("stars", "4+");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "4", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
p("stars","5s");
|
||||
p("stars", "5s");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_STARS), "5", ())
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_STARS);
|
||||
|
||||
|
@ -78,22 +78,22 @@ UNIT_TEST(Metadata_ValidateAndFormat_operator)
|
|||
MetadataTagProcessor p(params);
|
||||
|
||||
// ignore tag 'operator' if feature have inappropriate type
|
||||
p("operator","Some");
|
||||
p("operator", "Some");
|
||||
TEST(params.GetMetadata().Empty(), ());
|
||||
|
||||
params.SetType(type_atm);
|
||||
p("operator","Some");
|
||||
p("operator", "Some");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_OPERATOR), "Some", ());
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_OPERATOR);
|
||||
|
||||
params.SetType(type_fuel);
|
||||
p("operator","Some");
|
||||
p("operator", "Some");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_OPERATOR), "Some", ());
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_OPERATOR);
|
||||
|
||||
params.SetType(type_atm);
|
||||
params.AddType(type_fuel);
|
||||
p("operator","Some");
|
||||
p("operator", "Some");
|
||||
TEST_EQUAL(params.GetMetadata().Get(feature::FeatureMetadata::FMD_OPERATOR), "Some", ());
|
||||
params.GetMetadata().Drop(feature::FeatureMetadata::FMD_OPERATOR);
|
||||
}
|
||||
|
@ -107,11 +107,11 @@ UNIT_TEST(Metadata_ReadWrite_Intermediate)
|
|||
vector<char> buffer;
|
||||
MemWriter<vector<char> > writer(buffer);
|
||||
|
||||
p("stars","3");
|
||||
p("phone","+123456789");
|
||||
p("opening_hours","24/7");
|
||||
p("cuisine","regional");
|
||||
p("operator","Unused");
|
||||
p("stars", "3");
|
||||
p("phone", "+123456789");
|
||||
p("opening_hours", "24/7");
|
||||
p("cuisine", "regional");
|
||||
p("operator", "Unused");
|
||||
params.GetMetadata().Serialize(writer);
|
||||
|
||||
MemReader reader(buffer.data(), buffer.size());
|
||||
|
@ -134,11 +134,11 @@ UNIT_TEST(Metadata_ReadWrite_MWM)
|
|||
vector<char> buffer;
|
||||
MemWriter<vector<char> > writer(buffer);
|
||||
|
||||
p("stars","3");
|
||||
p("phone","+123456789");
|
||||
p("opening_hours","24/7");
|
||||
p("cuisine","regional");
|
||||
p("operator","Unused");
|
||||
p("stars", "3");
|
||||
p("phone", "+123456789");
|
||||
p("opening_hours", "24/7");
|
||||
p("cuisine", "regional");
|
||||
p("operator", "Unused");
|
||||
params.GetMetadata().SerializeToMWM(writer);
|
||||
|
||||
MemReader reader(buffer.data(), buffer.size());
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
#include "../indexer/feature_data.hpp"
|
||||
#include "../indexer/classificator.hpp"
|
||||
#include "../indexer/ftypes_matcher.hpp"
|
||||
|
||||
#include "../std/string.hpp"
|
||||
|
||||
|
||||
class MetadataTagProcessor
|
||||
{
|
||||
FeatureParams & m_params;
|
||||
|
@ -61,6 +63,7 @@ public:
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Validation and formatting functions
|
||||
|
||||
|
@ -86,11 +89,10 @@ protected:
|
|||
}
|
||||
string ValidateAndFormat_operator(string const & v) const
|
||||
{
|
||||
Classificator const & c = classif();
|
||||
uint32_t const type_atm = c.GetTypeByPath({ "amenity", "atm" });
|
||||
uint32_t const type_fuel = c.GetTypeByPath({ "amenity", "fuel" });
|
||||
static ftypes::IsATMChecker const IsATM;
|
||||
static ftypes::IsFuelStationChecker const IsFuelStation;
|
||||
|
||||
if (!(m_params.IsTypeExist(type_atm) || m_params.IsTypeExist(type_fuel)))
|
||||
if (!(IsATM(m_params.m_Types) || IsFuelStation(m_params.m_Types)))
|
||||
return string();
|
||||
|
||||
return v;
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace feature
|
|||
return true;
|
||||
}
|
||||
|
||||
string Get(EMetadataType type)
|
||||
string Get(EMetadataType type) const
|
||||
{
|
||||
auto it = m_metadata.find(type);
|
||||
return (it == m_metadata.end()) ? string() : it->second;
|
||||
|
@ -102,7 +102,5 @@ namespace feature
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -44,6 +44,31 @@ bool BaseChecker::operator() (vector<uint32_t> const & types) const
|
|||
return false;
|
||||
}
|
||||
|
||||
IsATMChecker::IsATMChecker()
|
||||
{
|
||||
Classificator const & c = classif();
|
||||
m_types.push_back(c.GetTypeByPath({ "amenity", "atm" }));
|
||||
}
|
||||
|
||||
IsATMChecker const & IsATMChecker::Instance()
|
||||
{
|
||||
static const IsATMChecker inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
IsFuelStationChecker::IsFuelStationChecker()
|
||||
{
|
||||
Classificator const & c = classif();
|
||||
m_types.push_back(c.GetTypeByPath({ "amenity", "fuel" }));
|
||||
}
|
||||
|
||||
IsFuelStationChecker const & IsFuelStationChecker::Instance()
|
||||
{
|
||||
static const IsFuelStationChecker inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
||||
IsStreetChecker::IsStreetChecker()
|
||||
{
|
||||
Classificator const & c = classif();
|
||||
|
|
|
@ -30,6 +30,22 @@ public:
|
|||
static uint32_t PrepareToMatch(uint32_t type, uint8_t level);
|
||||
};
|
||||
|
||||
class IsATMChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsATMChecker();
|
||||
|
||||
static IsATMChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsFuelStationChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
IsFuelStationChecker();
|
||||
|
||||
static IsFuelStationChecker const & Instance();
|
||||
};
|
||||
|
||||
class IsStreetChecker : public BaseChecker
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue