forked from organicmaps/organicmaps
[generator] Add non-const GetMetadata(), GetParams() to FeatureBuilder to avoid copies.
This commit is contained in:
parent
356ac18032
commit
cac79f6091
12 changed files with 27 additions and 34 deletions
|
@ -62,20 +62,20 @@ void BookingDataset::PreprocessMatchedOsmObject(ObjectId, FeatureBuilder1 & fb,
|
|||
if (fb.GetGeomType() == feature::GEOM_AREA)
|
||||
{
|
||||
// Remove all information about the hotel.
|
||||
auto params = fb.GetParams();
|
||||
params.ClearName();
|
||||
auto & meta = params.GetMetadata();
|
||||
auto & meta = fb.GetMetadata();
|
||||
meta.Drop(feature::Metadata::EType::FMD_STARS);
|
||||
meta.Drop(feature::Metadata::EType::FMD_WEBSITE);
|
||||
meta.Drop(feature::Metadata::EType::FMD_PHONE_NUMBER);
|
||||
|
||||
auto & params = fb.GetParams();
|
||||
params.ClearName();
|
||||
|
||||
auto const tourism = classif().GetTypeByPath({"tourism"});
|
||||
base::EraseIf(params.m_types, [tourism](uint32_t type)
|
||||
{
|
||||
ftype::TruncValue(type, 1);
|
||||
return type == tourism;
|
||||
});
|
||||
fb.SetParams(params);
|
||||
}
|
||||
|
||||
fn(fb);
|
||||
|
@ -86,17 +86,17 @@ void BookingDataset::BuildObject(Object const & hotel,
|
|||
std::function<void(FeatureBuilder1 &)> const & fn) const
|
||||
{
|
||||
FeatureBuilder1 fb;
|
||||
FeatureParams params;
|
||||
|
||||
fb.SetCenter(MercatorBounds::FromLatLon(hotel.m_latLon.lat, hotel.m_latLon.lon));
|
||||
|
||||
auto & metadata = params.GetMetadata();
|
||||
auto & metadata = fb.GetMetadata();
|
||||
metadata.Set(feature::Metadata::FMD_SPONSORED_ID, strings::to_string(hotel.m_id.Get()));
|
||||
metadata.Set(feature::Metadata::FMD_WEBSITE, hotel.m_descUrl);
|
||||
metadata.Set(feature::Metadata::FMD_RATING, strings::to_string(hotel.m_ratingUser));
|
||||
metadata.Set(feature::Metadata::FMD_STARS, strings::to_string(hotel.m_stars));
|
||||
metadata.Set(feature::Metadata::FMD_PRICE_RATE, strings::to_string(hotel.m_priceCategory));
|
||||
|
||||
auto & params = fb.GetParams();
|
||||
// params.AddAddress(hotel.address);
|
||||
// TODO(mgsergio): addr:full ???
|
||||
|
||||
|
@ -175,8 +175,6 @@ void BookingDataset::BuildObject(Object const & hotel,
|
|||
default: params.AddType(clf.GetTypeByPath({"tourism", "hotel"})); break;
|
||||
}
|
||||
|
||||
fb.SetParams(params);
|
||||
|
||||
fn(fb);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ string PrintBuilder(FeatureBuilder1 const & fb)
|
|||
s << "Id: " << DebugPrint(fb.GetMostGenericOsmId()) << '\t'
|
||||
<< "Name: " << fb.GetName(StringUtf8Multilang::kDefaultCode) << '\t';
|
||||
|
||||
auto const params = fb.GetParams();
|
||||
auto const & params = fb.GetParams();
|
||||
auto const street = params.GetStreet();
|
||||
auto const house = params.house.Get();
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
|
||||
|
||||
feature::Metadata const & GetMetadata() const { return m_params.GetMetadata(); }
|
||||
feature::Metadata & GetMetadataForTesting() { return m_params.GetMetadata(); }
|
||||
feature::Metadata & GetMetadata() { return m_params.GetMetadata(); }
|
||||
Geometry const & GetGeometry() const { return m_polygons; }
|
||||
PointSeq const & GetOuterGeometry() const { return m_polygons.front(); }
|
||||
feature::EGeomType GetGeomType() const { return m_params.GetGeomType(); }
|
||||
|
@ -169,6 +169,7 @@ public:
|
|||
void SetParams(FeatureParams const & params) { m_params.SetParams(params); }
|
||||
|
||||
FeatureParams const & GetParams() const { return m_params; }
|
||||
FeatureParams & GetParams() { return m_params; }
|
||||
|
||||
/// @name For OSM debugging and osm objects replacement, store original OSM id
|
||||
//@{
|
||||
|
|
|
@ -83,7 +83,7 @@ void TestFeature::Serialize(FeatureBuilder1 & fb) const
|
|||
if (m_metadata.Has(type))
|
||||
{
|
||||
auto const value = m_metadata.Get(type);
|
||||
fb.GetMetadataForTesting().Set(type, value);
|
||||
fb.GetMetadata().Set(type, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ bool TestMwmBuilder::Add(FeatureBuilder1 & fb)
|
|||
|
||||
if (ftypes::IsCityTownOrVillage(fb.GetTypes()) && fb.GetGeomType() == feature::GEOM_AREA)
|
||||
{
|
||||
auto const & metadata = fb.GetMetadataForTesting();
|
||||
auto const & metadata = fb.GetMetadata();
|
||||
uint64_t testId;
|
||||
CHECK(strings::to_uint64(metadata.Get(feature::Metadata::FMD_TEST_ID), testId), ());
|
||||
m_boundariesTable.Append(testId, indexer::CityBoundary(fb.GetOuterGeometry()));
|
||||
|
|
|
@ -47,12 +47,11 @@ template <>
|
|||
void OpentableDataset::PreprocessMatchedOsmObject(ObjectId const matchedObjId, FeatureBuilder1 & fb,
|
||||
function<void(FeatureBuilder1 &)> const fn) const
|
||||
{
|
||||
FeatureParams params = fb.GetParams();
|
||||
|
||||
auto const & restaurant = m_storage.GetObjectById(matchedObjId);
|
||||
auto & metadata = params.GetMetadata();
|
||||
auto & metadata = fb.GetMetadata();
|
||||
metadata.Set(feature::Metadata::FMD_SPONSORED_ID, strings::to_string(restaurant.m_id.Get()));
|
||||
|
||||
FeatureParams & params = fb.GetParams();
|
||||
// params.AddAddress(restaurant.address);
|
||||
// TODO(mgsergio): addr:full ???
|
||||
|
||||
|
@ -62,8 +61,6 @@ void OpentableDataset::PreprocessMatchedOsmObject(ObjectId const matchedObjId, F
|
|||
auto const & clf = classif();
|
||||
params.AddType(clf.GetTypeByPath({"sponsored", "opentable"}));
|
||||
|
||||
fb.SetParams(params);
|
||||
|
||||
fn(fb);
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ void TranslatorGeocoderBase::Emit(FeatureBuilder1 & fb, OsmElement const * p)
|
|||
}
|
||||
|
||||
void TranslatorGeocoderBase::BuildFeatureAndEmitFromRelation(OsmElement const * p,
|
||||
FeatureParams & params)
|
||||
FeatureParams const & params)
|
||||
{
|
||||
HolesRelation helper(m_holder);
|
||||
helper.Build(p);
|
||||
|
@ -117,7 +117,7 @@ void TranslatorGeocoderBase::BuildFeatureAndEmitFromRelation(OsmElement const *
|
|||
}
|
||||
|
||||
void TranslatorGeocoderBase::BuildFeatureAndEmitFromWay(OsmElement const * p,
|
||||
FeatureParams & params)
|
||||
FeatureParams const & params)
|
||||
{
|
||||
FeatureBuilder1 fb;
|
||||
m2::PointD pt;
|
||||
|
@ -139,7 +139,7 @@ void TranslatorGeocoderBase::BuildFeatureAndEmitFromWay(OsmElement const * p,
|
|||
}
|
||||
|
||||
void TranslatorGeocoderBase::BuildFeatureAndEmitFromNode(OsmElement const * p,
|
||||
FeatureParams & params)
|
||||
FeatureParams const & params)
|
||||
{
|
||||
m2::PointD const pt = MercatorBounds::FromLatLon(p->lat, p->lon);
|
||||
FeatureBuilder1 fb;
|
||||
|
|
|
@ -45,9 +45,9 @@ protected:
|
|||
virtual bool IsSuitableElement(OsmElement const * p) const = 0;
|
||||
|
||||
bool ParseParams(OsmElement * p, FeatureParams & params) const;
|
||||
void BuildFeatureAndEmitFromRelation(OsmElement const * p, FeatureParams & params);
|
||||
void BuildFeatureAndEmitFromWay(OsmElement const * p, FeatureParams & params);
|
||||
void BuildFeatureAndEmitFromNode(OsmElement const * p, FeatureParams & params);
|
||||
void BuildFeatureAndEmitFromRelation(OsmElement const * p, FeatureParams const & params);
|
||||
void BuildFeatureAndEmitFromWay(OsmElement const * p, FeatureParams const & params);
|
||||
void BuildFeatureAndEmitFromNode(OsmElement const * p, FeatureParams const & params);
|
||||
|
||||
private:
|
||||
void Emit(FeatureBuilder1 & fb, OsmElement const * p);
|
||||
|
|
|
@ -94,17 +94,14 @@ void ViatorDataset::PreprocessMatchedOsmObject(ViatorCity::ObjectId const matche
|
|||
FeatureBuilder1 & fb,
|
||||
function<void(FeatureBuilder1 &)> const fn) const
|
||||
{
|
||||
FeatureParams params = fb.GetParams();
|
||||
|
||||
auto const & city = m_storage.GetObjectById(matchedObjId);
|
||||
auto & metadata = params.GetMetadata();
|
||||
auto & metadata = fb.GetMetadata();
|
||||
metadata.Set(feature::Metadata::FMD_SPONSORED_ID, strings::to_string(city.m_id.Get()));
|
||||
|
||||
auto const & clf = classif();
|
||||
FeatureParams & params = fb.GetParams();
|
||||
params.AddType(clf.GetTypeByPath({"sponsored", "viator"}));
|
||||
|
||||
fb.SetParams(params);
|
||||
|
||||
fn(fb);
|
||||
}
|
||||
} // namespace generator
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
FeatureBuilder1 fb;
|
||||
fb.SetParams(params);
|
||||
fb.SetCenter(pt);
|
||||
fb.GetMetadataForTesting().Set(feature::Metadata::FMD_TEST_ID, strings::to_string(m_lastId));
|
||||
fb.GetMetadata().Set(feature::Metadata::FMD_TEST_ID, strings::to_string(m_lastId));
|
||||
++m_lastId;
|
||||
|
||||
TEST(builder.Add(fb), (fb));
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
{
|
||||
TestPOI::Serialize(fb);
|
||||
|
||||
auto & metadata = fb.GetMetadataForTesting();
|
||||
auto & metadata = fb.GetMetadata();
|
||||
metadata.Set(feature::Metadata::FMD_RATING, strings::to_string(m_rating));
|
||||
metadata.Set(feature::Metadata::FMD_PRICE_RATE, strings::to_string(m_priceRate));
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
{
|
||||
TestCafe::Serialize(fb);
|
||||
|
||||
auto & metadata = fb.GetMetadataForTesting();
|
||||
auto & metadata = fb.GetMetadata();
|
||||
metadata.Set(feature::Metadata::FMD_CUISINE, m_cuisine);
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
{
|
||||
TestPOI::Serialize(fb);
|
||||
|
||||
auto & metadata = fb.GetMetadataForTesting();
|
||||
auto & metadata = fb.GetMetadata();
|
||||
metadata.Set(feature::Metadata::FMD_AIRPORT_IATA, m_iata);
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
{
|
||||
TestPOI::Serialize(fb);
|
||||
|
||||
auto & metadata = fb.GetMetadataForTesting();
|
||||
auto & metadata = fb.GetMetadata();
|
||||
metadata.Set(feature::Metadata::FMD_OPERATOR, m_operator);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
// TestFeature overrides:
|
||||
void Serialize(FeatureBuilder1 & fb) const override
|
||||
{
|
||||
fb.GetMetadataForTesting().Set(feature::Metadata::FMD_TEST_ID, strings::to_string(m_id));
|
||||
fb.GetMetadata().Set(feature::Metadata::FMD_TEST_ID, strings::to_string(m_id));
|
||||
fb.SetCenter(m_center);
|
||||
|
||||
if (!m_name.empty())
|
||||
|
|
Loading…
Add table
Reference in a new issue