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
diff options
context:
space:
mode:
authorVladiMihaylenko <vxmihaylenko@gmail.com>2017-10-20 14:29:26 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2017-10-20 16:43:29 +0300
commit053e801d616f0766d4d8eba30c611ebd9635d163 (patch)
treec19c699311a1e957accf07e4fe727a8419cec650
parent19e0693b6c7ab5466abee423acc1f64c051d4214 (diff)
Send type from ugc_types.csv
-rw-r--r--generator/ugc_section_builder.cpp6
-rw-r--r--indexer/ftraits.hpp68
-rw-r--r--indexer/ftypes_mapping.hpp5
-rw-r--r--indexer/indexer_tests/ugc_types_test.cpp27
-rw-r--r--indexer/indexer_tests/wheelchair_tests.cpp19
-rw-r--r--indexer/map_object.cpp3
-rw-r--r--ugc/storage.cpp6
-rw-r--r--ugc/storage.hpp2
-rw-r--r--ugc/ugc_tests/storage_tests.cpp3
9 files changed, 104 insertions, 35 deletions
diff --git a/generator/ugc_section_builder.cpp b/generator/ugc_section_builder.cpp
index 7116b40199..d792660e81 100644
--- a/generator/ugc_section_builder.cpp
+++ b/generator/ugc_section_builder.cpp
@@ -36,9 +36,11 @@ bool BuildUgcMwmSection(std::string const & srcDbFilename, std::string const & m
std::vector<IndexUGC> content;
feature::ForEachFromDat(mwmFile, [&](FeatureType const & f, uint32_t featureId) {
- auto const ugcMasks = ftraits::UGC::GetValue({f}).m_mask;
+ ftraits::UGCItem item;
+ if (!ftraits::UGC::GetValue({f}, item))
+ return;
- if (!ftraits::UGC::IsUGCAvailable(ugcMasks))
+ if (!ftraits::UGC::IsUGCAvailable(item.m_mask))
return;
auto const it = featureToOsmId.find(featureId);
diff --git a/indexer/ftraits.hpp b/indexer/ftraits.hpp
index 7900f43afc..35ac7f3241 100644
--- a/indexer/ftraits.hpp
+++ b/indexer/ftraits.hpp
@@ -23,22 +23,49 @@ template <typename Base, typename Value>
class TraitsBase
{
public:
- static Value GetValue(feature::TypesHolder const & types)
+ static bool GetValue(feature::TypesHolder const & types, Value & value)
{
- static Base instance;
+ auto const & instance = Instance();
+ auto const it = Find(types);
+ if (!instance.m_matcher.IsValid(it))
+ return false;
- auto const excluded = instance.m_excluded.Find(types);
- if (instance.m_excluded.IsValid(excluded))
- return Base::GetEmptyValue();
+ value = it->second;
+ return true;
+ }
- auto const it = instance.m_matcher.Find(types);
+ static bool GetType(feature::TypesHolder const & types, uint32_t & type)
+ {
+ auto const & instance = Instance();
+ auto const it = Find(types);
if (!instance.m_matcher.IsValid(it))
- return Base::GetEmptyValue();
+ return false;
- return it->second;
+ type = it->first;
+ return true;
+ }
+
+private:
+ using ConstIterator = typename ftypes::HashMapMatcher<uint32_t, Value>::ConstIterator;
+
+ static ConstIterator Find(feature::TypesHolder const & types)
+ {
+ auto const & instance = Instance();
+
+ auto const excluded = instance.m_excluded.Find(types);
+ if (instance.m_excluded.IsValid(excluded))
+ return instance.m_matcher.End();
+
+ return instance.m_matcher.Find(types);
}
protected:
+ static TraitsBase const & Instance()
+ {
+ static Base instance;
+ return instance;
+ }
+
ftypes::HashMapMatcher<uint32_t, Value> m_matcher;
ftypes::HashSetMatcher<uint32_t> m_excluded;
};
@@ -121,12 +148,6 @@ class UGC : public TraitsBase<UGC, UGCItem>
}
public:
- static UGCItem const & GetEmptyValue()
- {
- static const UGCItem item;
- return item;
- }
-
static bool IsUGCAvailable(UGCTypeMask mask) { return mask != UGCTYPE_NONE; }
static bool IsRatingAvailable(UGCTypeMask mask) { return mask & UGCTYPE_RATING; }
static bool IsReviewsAvailable(UGCTypeMask mask) { return mask & UGCTYPE_REVIEWS; }
@@ -134,23 +155,29 @@ public:
static bool IsUGCAvailable(feature::TypesHolder const & types)
{
- return IsUGCAvailable(GetValue(types).m_mask);
+ UGCItem item;
+ return GetValue(types, item) ? IsUGCAvailable(item.m_mask) : false;
}
static bool IsRatingAvailable(feature::TypesHolder const & types)
{
- return IsRatingAvailable(GetValue(types).m_mask);
+ UGCItem item;
+ return GetValue(types, item) ? IsRatingAvailable(item.m_mask) : false;
}
static bool IsReviewsAvailable(feature::TypesHolder const & types)
{
- return IsReviewsAvailable(GetValue(types).m_mask);
+ UGCItem item;
+ return GetValue(types, item) ? IsReviewsAvailable(item.m_mask) : false;
}
static bool IsDetailsAvailable(feature::TypesHolder const & types)
{
- return IsDetailsAvailable(GetValue(types).m_mask);
+ UGCItem item;
+ return GetValue(types, item) ? IsDetailsAvailable(item.m_mask) : false;
}
static UGCRatingCategories GetCategories(feature::TypesHolder const & types)
{
- return GetValue(types).m_categories;
+ UGCItem item;
+ GetValue(types, item);
+ return item.m_categories;
}
};
@@ -184,9 +211,6 @@ class Wheelchair : public TraitsBase<Wheelchair, WheelchairAvailability>
m_matcher.Append<TypesInitializer>({{"wheelchair", "limited"}},
WheelchairAvailability::Limited);
}
-
-public:
- static WheelchairAvailability GetEmptyValue() { return WheelchairAvailability::No; }
};
} // namespace ftraits
diff --git a/indexer/ftypes_mapping.hpp b/indexer/ftypes_mapping.hpp
index 346dd48f51..4abdf31cde 100644
--- a/indexer/ftypes_mapping.hpp
+++ b/indexer/ftypes_mapping.hpp
@@ -35,6 +35,11 @@ public:
return m_mapping.cend();
}
+ ConstIterator End() const
+ {
+ return m_mapping.cend();
+ }
+
bool IsValid(ConstIterator it) const
{
return it != m_mapping.cend();
diff --git a/indexer/indexer_tests/ugc_types_test.cpp b/indexer/indexer_tests/ugc_types_test.cpp
index 12e7492809..477e199583 100644
--- a/indexer/indexer_tests/ugc_types_test.cpp
+++ b/indexer/indexer_tests/ugc_types_test.cpp
@@ -13,35 +13,52 @@ UNIT_TEST(UgcTypes_Full)
feature::TypesHolder holder;
{
- holder.Assign(c.GetTypeByPath({"amenity", "bank"}));
+ auto const type = c.GetTypeByPath({"amenity", "bank"});
+ holder.Assign(type);
TEST(UGC::IsUGCAvailable(holder), ());
TEST(UGC::IsRatingAvailable(holder), ());
TEST(UGC::IsReviewsAvailable(holder), ());
TEST(!UGC::IsDetailsAvailable(holder), ());
ftraits::UGCRatingCategories expected = {"quality", "service", "value_for_money"};
TEST_EQUAL(UGC::GetCategories(holder), expected, ());
+ uint32_t matchingType;
+ TEST(UGC::GetType(holder, matchingType), ());
+ TEST_EQUAL(matchingType, type, ());
+ TEST_EQUAL(c.GetReadableObjectName(matchingType), "amenity-bank", ());
}
{
- holder.Assign(c.GetTypeByPath({"tourism", "information", "office"}));
+ auto const type = c.GetTypeByPath({"tourism", "information", "office"});
+ holder.Assign(type);
TEST(UGC::IsUGCAvailable(holder), ());
TEST(UGC::IsRatingAvailable(holder), ());
TEST(UGC::IsReviewsAvailable(holder), ());
TEST(!UGC::IsDetailsAvailable(holder), ());
ftraits::UGCRatingCategories expected = {"quality", "service", "value_for_money"};
TEST_EQUAL(UGC::GetCategories(holder), expected, ());
+ uint32_t matchingType;
+ TEST(UGC::GetType(holder, matchingType), ());
+ TEST_EQUAL(matchingType, type, ());
+ TEST_EQUAL(c.GetReadableObjectName(matchingType), "tourism-information-office", ());
}
{
- holder.Assign(c.GetTypeByPath({"amenity", "hospital"}));
+ auto const type = c.GetTypeByPath({"amenity", "hospital"});
+ holder.Assign(type);
TEST(UGC::IsUGCAvailable(holder), ());
TEST(UGC::IsRatingAvailable(holder), ());
TEST(UGC::IsReviewsAvailable(holder), ());
TEST(!UGC::IsDetailsAvailable(holder), ());
ftraits::UGCRatingCategories expected = {"expertise", "equipment", "value_for_money"};
TEST_EQUAL(UGC::GetCategories(holder), expected, ());
+ uint32_t matchingType;
+ TEST(UGC::GetType(holder, matchingType), ());
+ TEST_EQUAL(matchingType, type, ());
+ TEST_EQUAL(c.GetReadableObjectName(matchingType), "amenity-hospital", ());
}
{
holder.Assign(c.GetTypeByPath({"traffic_calming", "bump"}));
TEST(!UGC::IsUGCAvailable(holder), ());
+ uint32_t matchingType;
+ TEST(!UGC::GetType(holder, matchingType), ());
}
{
holder.Assign(c.GetTypeByPath({"sponsored", "booking"}));
@@ -51,6 +68,8 @@ UNIT_TEST(UgcTypes_Full)
TEST(!UGC::IsDetailsAvailable(holder), ());
ftraits::UGCRatingCategories expected = {};
TEST_EQUAL(UGC::GetCategories(holder), expected, ());
+ uint32_t matchingType;
+ TEST(!UGC::GetType(holder, matchingType), ());
holder.Assign(c.GetTypeByPath({"sponsored", "booking"}));
holder.Add(c.GetTypeByPath({"amenity", "hospital"}));
@@ -59,6 +78,7 @@ UNIT_TEST(UgcTypes_Full)
TEST(!UGC::IsReviewsAvailable(holder), ());
TEST(!UGC::IsDetailsAvailable(holder), ());
TEST_EQUAL(UGC::GetCategories(holder), expected, ());
+ TEST(!UGC::GetType(holder, matchingType), ());
holder.Assign(c.GetTypeByPath({"amenity", "hospital"}));
holder.Add(c.GetTypeByPath({"sponsored", "booking"}));
@@ -67,5 +87,6 @@ UNIT_TEST(UgcTypes_Full)
TEST(!UGC::IsReviewsAvailable(holder), ());
TEST(!UGC::IsDetailsAvailable(holder), ());
TEST_EQUAL(UGC::GetCategories(holder), expected, ());
+ TEST(!UGC::GetType(holder, matchingType), ());
}
}
diff --git a/indexer/indexer_tests/wheelchair_tests.cpp b/indexer/indexer_tests/wheelchair_tests.cpp
index 921f9452dd..b73e1d1db0 100644
--- a/indexer/indexer_tests/wheelchair_tests.cpp
+++ b/indexer/indexer_tests/wheelchair_tests.cpp
@@ -15,23 +15,32 @@ UNIT_TEST(Wheelchair_GetType)
feature::TypesHolder holder;
{
holder.Assign(c.GetTypeByPath({"wheelchair", "no"}));
- TEST_EQUAL(Wheelchair::GetValue(holder), WheelchairAvailability::No, ());
+ WheelchairAvailability a;
+ TEST(Wheelchair::GetValue(holder, a), ());
+ TEST_EQUAL(a, WheelchairAvailability::No, ());
}
{
holder.Assign(c.GetTypeByPath({"wheelchair", "yes"}));
- TEST_EQUAL(Wheelchair::GetValue(holder), WheelchairAvailability::Yes, ());
+ WheelchairAvailability a;
+ TEST(Wheelchair::GetValue(holder, a), ());
+ TEST_EQUAL(a, WheelchairAvailability::Yes, ());
}
{
holder.Assign(c.GetTypeByPath({"wheelchair", "limited"}));
- TEST_EQUAL(Wheelchair::GetValue(holder), WheelchairAvailability::Limited, ());
+ WheelchairAvailability a;
+ TEST(Wheelchair::GetValue(holder, a), ());
+ TEST_EQUAL(a, WheelchairAvailability::Limited, ());
}
{
holder.Assign(c.GetTypeByPath({"amenity", "dentist"}));
- TEST_EQUAL(Wheelchair::GetValue(holder), WheelchairAvailability::No, ());
+ WheelchairAvailability a;
+ TEST(!Wheelchair::GetValue(holder, a), ());
}
{
holder.Assign(c.GetTypeByPath({"amenity", "dentist"}));
holder.Add(c.GetTypeByPath({"wheelchair", "yes"}));
- TEST_EQUAL(Wheelchair::GetValue(holder), WheelchairAvailability::Yes, ());
+ WheelchairAvailability a;
+ TEST(Wheelchair::GetValue(holder, a), ());
+ TEST_EQUAL(a, WheelchairAvailability::Yes, ());
}
}
diff --git a/indexer/map_object.cpp b/indexer/map_object.cpp
index 8a77c09973..fe7492184d 100644
--- a/indexer/map_object.cpp
+++ b/indexer/map_object.cpp
@@ -203,7 +203,8 @@ string MapObject::GetBuildingLevels() const
ftraits::WheelchairAvailability MapObject::GetWheelchairType() const
{
- return ftraits::Wheelchair::GetValue(m_types);
+ ftraits::WheelchairAvailability ret;
+ return ftraits::Wheelchair::GetValue(m_types, ret) ? ret : ftraits::WheelchairAvailability::No;
}
feature::Metadata const & MapObject::GetMetadata() const { return m_metadata; }
diff --git a/ugc/storage.cpp b/ugc/storage.cpp
index c1adf56f11..a9544879ef 100644
--- a/ugc/storage.cpp
+++ b/ugc/storage.cpp
@@ -5,6 +5,7 @@
#include "indexer/classificator.hpp"
#include "indexer/feature_algo.hpp"
#include "indexer/feature_decl.hpp"
+#include "indexer/ftraits.hpp"
#include "indexer/index.hpp"
#include "platform/platform.hpp"
@@ -121,6 +122,8 @@ void Storage::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc)
auto const mercator = feature::GetCenter(*feature);
feature::TypesHolder th(*feature);
th.SortBySpec();
+ uint32_t matchingType = 0;
+ CHECK(ftraits::UGC::GetType(th, matchingType), ());
auto const type = th.GetBestType();
for (auto & index : m_UGCIndexes)
{
@@ -140,6 +143,7 @@ void Storage::SetUGCUpdate(FeatureID const & id, UGCUpdate const & ugc)
index.m_mercator = mercator;
index.m_type = type;
+ index.m_matchingType = matchingType;
index.m_mwmName = id.GetMwmName();
index.m_dataVersion = id.GetMwmVersion();
index.m_featureId = id.m_index;
@@ -297,7 +301,7 @@ string Storage::GetUGCToSend() const
ToJSONObject(*embeddedNode.get(), "data_version", index.m_dataVersion);
ToJSONObject(*embeddedNode.get(), "mwm_name", index.m_mwmName);
ToJSONObject(*embeddedNode.get(), "feature_id", index.m_featureId);
- ToJSONObject(*embeddedNode.get(), "feature_type", classif().GetReadableObjectName(index.m_type));
+ ToJSONObject(*embeddedNode.get(), "feature_type", classif().GetReadableObjectName(index.m_matchingType));
ToJSONObject(*serializedUgc.get(), "feature", *embeddedNode.release());
json_array_append_new(array.get(), serializedUgc.get_deep_copy());
}
diff --git a/ugc/storage.hpp b/ugc/storage.hpp
index 355881ef4e..958df79cd3 100644
--- a/ugc/storage.hpp
+++ b/ugc/storage.hpp
@@ -23,12 +23,14 @@ public:
struct UGCIndex
{
DECLARE_VISITOR(visitor.VisitPoint(m_mercator, "x", "y"), visitor(m_type, "type"),
+ visitor(m_matchingType, "matching_type"),
visitor(m_offset, "offset"), visitor(m_deleted, "deleted"),
visitor(m_synchronized, "synchronized"), visitor(m_mwmName, "mwm_name"),
visitor(m_dataVersion, "data_version"), visitor(m_featureId, "feature_id"))
m2::PointD m_mercator{};
uint32_t m_type = 0;
+ uint32_t m_matchingType = 0;
uint64_t m_offset = 0;
bool m_deleted = false;
bool m_synchronized = false;
diff --git a/ugc/ugc_tests/storage_tests.cpp b/ugc/ugc_tests/storage_tests.cpp
index ff5433c966..19f9fda6a7 100644
--- a/ugc/ugc_tests/storage_tests.cpp
+++ b/ugc/ugc_tests/storage_tests.cpp
@@ -307,7 +307,7 @@ UNIT_CLASS_TEST(StorageTest, ContentTest)
ToJSONObject(*embeddedNode.get(), "data_version", lastIndex.m_dataVersion);
ToJSONObject(*embeddedNode.get(), "mwm_name", lastIndex.m_mwmName);
ToJSONObject(*embeddedNode.get(), "feature_id", lastIndex.m_featureId);
- ToJSONObject(*embeddedNode.get(), "feature_type", classif().GetReadableObjectName(lastIndex.m_type));
+ ToJSONObject(*embeddedNode.get(), "feature_type", classif().GetReadableObjectName(lastIndex.m_matchingType));
ToJSONObject(*ugcNode.get(), "feature", *embeddedNode.release());
auto array = my::NewJSONArray();
@@ -320,4 +320,5 @@ UNIT_CLASS_TEST(StorageTest, ContentTest)
storage.MarkAllAsSynchronized();
TEST(firstIndex.m_synchronized, ());
TEST(lastIndex.m_synchronized, ());
+ TEST(DeleteIndexFile(), ());
}