Review fixes

This commit is contained in:
Maksim Andrianov 2019-08-20 13:32:18 +03:00 committed by Tatiana Yan
parent 5c7a076a69
commit e91592ac74
44 changed files with 231 additions and 318 deletions

View file

@ -38,10 +38,10 @@ set(
collection_base.hpp
collector_addresses.cpp
collector_addresses.hpp
collector_city_area.cpp
collector_city_area.hpp
collector_camera.cpp
collector_camera.hpp
collector_city_area.cpp
collector_city_area.hpp
collector_collection.cpp
collector_collection.hpp
collector_interface.hpp
@ -53,18 +53,6 @@ set(
descriptions_section_builder.hpp
dumper.cpp
dumper.hpp
processor_booking.hpp
processor_coastline.cpp
processor_coastline.hpp
processor_country.cpp
processor_country.hpp
processor_factory.hpp
processor_interface.hpp
processor_noop.hpp
processor_simple.cpp
processor_simple.hpp
processor_world.cpp
processor_world.hpp
factory_utils.hpp
feature_builder.cpp
feature_builder.hpp
@ -97,14 +85,14 @@ set(
final_processor_intermediate_mwm.hpp
gen_mwm_info.hpp
generate_info.hpp
geo_objects/geo_objects_generator.cpp
geo_objects/geo_objects_generator.hpp
geo_objects/geo_objects_maintainer.cpp
geo_objects/geo_objects_maintainer.hpp
geo_objects/geo_objects.cpp
geo_objects/geo_objects.hpp
geo_objects/geo_objects_filter.cpp
geo_objects/geo_objects_filter.hpp
geo_objects/geo_objects_generator.cpp
geo_objects/geo_objects_generator.hpp
geo_objects/geo_objects_maintainer.cpp
geo_objects/geo_objects_maintainer.hpp
geometry_holder.hpp
holes.cpp
holes.hpp
@ -141,15 +129,27 @@ set(
osm_xml_source.hpp
place.cpp
place.hpp
place_node.hpp
place_processor.cpp
place_processor.hpp
place_node.hpp
platform_helpers.cpp
platform_helpers.hpp
popular_places_section_builder.cpp
popular_places_section_builder.hpp
popularity.cpp
popularity.hpp
processor_booking.hpp
processor_coastline.cpp
processor_coastline.hpp
processor_country.cpp
processor_country.hpp
processor_factory.hpp
processor_interface.hpp
processor_noop.hpp
processor_simple.cpp
processor_simple.hpp
processor_world.cpp
processor_world.hpp
promo_catalog_cities.hpp
ratings_section_builder.cpp
ratings_section_builder.hpp
@ -230,12 +230,12 @@ set(
tesselator.hpp
towns_dumper.cpp
towns_dumper.hpp
translation.hpp
translation.cpp
traffic_generator.cpp
traffic_generator.hpp
transit_generator.cpp
transit_generator.hpp
translation.cpp
translation.hpp
translator.cpp
translator.hpp
translator_coastline.cpp

View file

@ -1,9 +1,10 @@
#include "generator/booking_dataset.hpp"
#include "generator/processor_booking.hpp"
#include "generator/feature_builder.hpp"
#include "generator/raw_generator.hpp"
#include "generator/opentable_dataset.hpp"
#include "generator/osm_source.hpp"
#include "generator/processor_booking.hpp"
#include "generator/raw_generator.hpp"
#include "generator/sponsored_scoring.hpp"
#include "generator/translator_collection.hpp"
#include "generator/translator_factory.hpp"
@ -330,7 +331,7 @@ void RunImpl(GenerateInfo & info)
LOG_SHORT(LINFO, ("OSM data:", FLAGS_osm));
generator::cache::IntermediateData cacheLoader(info);
auto translators = std::make_shared<TranslatorCollection>();
auto translators = make_shared<TranslatorCollection>();
auto processor = make_shared<ProcessorBooking<Dataset>>(dataset, features);
translators->Append(CreateTranslator(TranslatorType::Country, processor, cacheLoader.GetCache(), info));
RawGenerator generator(info);

View file

@ -2,6 +2,8 @@
#include "generator/feature_builder.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "coding/point_coding.hpp"
#include "geometry/region2d/binary_operators.hpp"
@ -21,10 +23,8 @@ using RegionT = m2::RegionI;
using PointT = m2::PointI;
using RectT = m2::RectI;
CoastlineFeaturesGenerator::CoastlineFeaturesGenerator(uint32_t coastType)
: m_merger(kPointCoordBits), m_coastType(coastType)
{
}
CoastlineFeaturesGenerator::CoastlineFeaturesGenerator()
: m_merger(kPointCoordBits) {}
namespace
{
@ -333,7 +333,8 @@ void CoastlineFeaturesGenerator::GetFeatures(vector<FeatureBuilder> & features)
cellData.AssignGeometry(fb);
fb.SetArea();
fb.AddType(m_coastType);
static auto const kCoastType = ftypes::IsCoastlineChecker::Instance().GetCoastlineType();
fb.AddType(kCoastType);
// Should represent non-empty geometry
CHECK_GREATER(fb.GetPolygonsCount(), 0, ());

View file

@ -3,7 +3,6 @@
#include "generator/feature_merger.hpp"
#include "indexer/cell_id.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "geometry/tree4d.hpp"
#include "geometry/region2d.hpp"
@ -22,10 +21,8 @@ class CoastlineFeaturesGenerator
using TTree = m4::Tree<m2::RegionI>;
TTree m_tree;
uint32_t m_coastType;
public:
CoastlineFeaturesGenerator(uint32_t coastType = ftypes::IsCoastlineChecker::Instance().GetCoastlineType());
CoastlineFeaturesGenerator();
void AddRegionToTree(feature::FeatureBuilder const & fb);

View file

@ -65,6 +65,9 @@ void TransformAreaToPoint(FeatureBuilder & feature)
feature.ResetGeometry();
feature.SetOsmId(id);
feature.SetCenter(center);
auto & params = feature.GetParams();
if (!params.house.IsEmpty())
params.SetGeomTypePointEx();
}
void TransformAreaToLine(FeatureBuilder & feature)

View file

@ -26,6 +26,7 @@ public:
void SetCache(std::shared_ptr<cache::IntermediateData> const & cache);
// Reference on element is non const because ftype::GetNameAndType will be call.
virtual bool Add(OsmElement & element);
// The function returns true when the receiving feature was successful and a false when not successful.
bool GetNextFeature(feature::FeatureBuilder & feature);

View file

@ -122,7 +122,7 @@ double MergedFeatureBuilder::GetPriority() const
}
FeatureMergeProcessor::key_t FeatureMergeProcessor::get_key(m2::PointD const & p)
FeatureMergeProcessor::Key FeatureMergeProcessor::GetKey(m2::PointD const & p)
{
return PointToInt64Obsolete(p, m_coordBits);
}
@ -139,8 +139,8 @@ void FeatureMergeProcessor::operator() (FeatureBuilder const & fb)
void FeatureMergeProcessor::operator() (MergedFeatureBuilder * p)
{
key_t const k1 = get_key(p->FirstPoint());
key_t const k2 = get_key(p->LastPoint());
Key const k1 = GetKey(p->FirstPoint());
Key const k2 = GetKey(p->LastPoint());
m_map[k1].push_back(p);
if (k1 != k2)
@ -156,15 +156,15 @@ void FeatureMergeProcessor::operator() (MergedFeatureBuilder * p)
void FeatureMergeProcessor::Insert(m2::PointD const & pt, MergedFeatureBuilder * p)
{
m_map[get_key(pt)].push_back(p);
m_map[GetKey(pt)].push_back(p);
}
void FeatureMergeProcessor::Remove(key_t key, MergedFeatureBuilder const * p)
void FeatureMergeProcessor::Remove(Key key, MergedFeatureBuilder const * p)
{
map_t::iterator i = m_map.find(key);
auto i = m_map.find(key);
if (i != m_map.end())
{
vector_t & v = i->second;
MergedFeatureBuilders & v = i->second;
v.erase(remove(v.begin(), v.end(), p), v.end());
if (v.empty()) m_map.erase(i);
}
@ -172,8 +172,8 @@ void FeatureMergeProcessor::Remove(key_t key, MergedFeatureBuilder const * p)
void FeatureMergeProcessor::Remove(MergedFeatureBuilder const * p)
{
key_t const k1 = get_key(p->FirstPoint());
key_t const k2 = get_key(p->LastPoint());
Key const k1 = GetKey(p->FirstPoint());
Key const k2 = GetKey(p->LastPoint());
Remove(k1, p);
if (k1 != k2)
@ -191,7 +191,7 @@ void FeatureMergeProcessor::DoMerge(FeatureEmitterIFace & emitter)
while (!m_map.empty())
{
// Get any starting feature.
vector_t & vS = m_map.begin()->second;
MergedFeatureBuilders & vS = m_map.begin()->second;
CHECK(!vS.empty(), ());
MergedFeatureBuilder * p = vS.front(); // may be 'back' is better
@ -213,7 +213,7 @@ void FeatureMergeProcessor::DoMerge(FeatureEmitterIFace & emitter)
while (ind < curr.GetKeyPointsCount()) // GetKeyPointsCount() can be different on each iteration
{
std::pair<m2::PointD, bool> const pt = curr.GetKeyPoint(ind++);
map_t::const_iterator it = m_map.find(get_key(pt.first));
auto it = m_map.find(GetKey(pt.first));
MergedFeatureBuilder * pp = 0;
if (it != m_map.end())

View file

@ -57,21 +57,21 @@ public:
/// Feature merger.
class FeatureMergeProcessor
{
typedef int64_t key_t;
key_t get_key(m2::PointD const & p);
using Key = int64_t ;
Key GetKey(m2::PointD const & p);
MergedFeatureBuilder m_last;
typedef std::vector<MergedFeatureBuilder *> vector_t;
typedef std::map<key_t, vector_t> map_t;
map_t m_map;
using MergedFeatureBuilders = std::vector<MergedFeatureBuilder *>;
using KeyToMergedFeatureBuilders = std::map<Key, MergedFeatureBuilders>;
KeyToMergedFeatureBuilders m_map;
void Insert(m2::PointD const & pt, MergedFeatureBuilder * p);
void Remove(key_t key, MergedFeatureBuilder const * p);
void Remove(Key key, MergedFeatureBuilder const * p);
inline void Remove1(m2::PointD const & pt, MergedFeatureBuilder const * p)
{
Remove(get_key(pt), p);
Remove(GetKey(pt), p);
}
void Remove(MergedFeatureBuilder const * p);

View file

@ -42,23 +42,6 @@ std::string LogBuffer::GetAsString() const
return m_buffer.str();
}
std::shared_ptr<LayerBase> LayerBase::CloneRecursive() const
{
auto temp = shared_from_this();
std::shared_ptr<LayerBase> clone;
if (temp)
{
clone = temp->Clone();
temp = temp->m_next;
}
while (temp)
{
clone->Add(temp->Clone());
temp = temp->m_next;
}
return clone;
}
void LayerBase::Handle(FeatureBuilder & fb)
{
if (m_next)
@ -72,8 +55,10 @@ void LayerBase::Merge(std::shared_ptr<LayerBase> const & other)
m_logBuffer.AppendLine(other->GetAsString());
}
void LayerBase::MergeRecursive(std::shared_ptr<LayerBase> const & other)
void LayerBase::MergeChain(std::shared_ptr<LayerBase> const & other)
{
CHECK_EQUAL(GetChainSize(), other->GetChainSize(), ());
auto left = shared_from_this();
auto right = other;
while (left && right)
@ -84,6 +69,19 @@ void LayerBase::MergeRecursive(std::shared_ptr<LayerBase> const & other)
}
}
size_t LayerBase::GetChainSize() const
{
size_t size = 0;
auto current = shared_from_this();
while (current)
{
++size;
current = current->m_next;
}
return size;
}
void LayerBase::SetNext(std::shared_ptr<LayerBase> next)
{
m_next = next;
@ -106,21 +104,15 @@ std::string LayerBase::GetAsString() const
std::string LayerBase::GetAsStringRecursive() const
{
std::ostringstream m_buffer;
std::ostringstream buffer;
auto temp = shared_from_this();
while (temp)
{
m_buffer << temp->GetAsString();
buffer << temp->GetAsString();
temp = temp->m_next;
}
return m_buffer.str();
}
std::shared_ptr<LayerBase> RepresentationLayer::Clone() const
{
return std::make_shared<RepresentationLayer>();
return buffer.str();
}
void RepresentationLayer::Handle(FeatureBuilder & fb)
@ -209,11 +201,6 @@ bool RepresentationLayer::CanBeLine(FeatureParams const & params)
return feature::HasUsefulType(params.m_types, feature::GeomType::Line);
}
std::shared_ptr<LayerBase> PrepareFeatureLayer::Clone() const
{
return std::make_shared<PrepareFeatureLayer>();
}
void PrepareFeatureLayer::Handle(FeatureBuilder & fb)
{
auto const type = fb.GetGeomType();
@ -225,11 +212,6 @@ void PrepareFeatureLayer::Handle(FeatureBuilder & fb)
LayerBase::Handle(fb);
}
std::shared_ptr<LayerBase> RepresentationCoastlineLayer::Clone() const
{
return std::make_shared<RepresentationCoastlineLayer>();
}
void RepresentationCoastlineLayer::Handle(FeatureBuilder & fb)
{
auto const sourceType = fb.GetMostGenericOsmId().GetType();
@ -243,8 +225,6 @@ void RepresentationCoastlineLayer::Handle(FeatureBuilder & fb)
switch (geomType)
{
case feature::GeomType::Area:
LayerBase::Handle(fb);
break;
case feature::GeomType::Line:
LayerBase::Handle(fb);
break;
@ -262,10 +242,6 @@ void RepresentationCoastlineLayer::Handle(FeatureBuilder & fb)
}
}
std::shared_ptr<LayerBase> PrepareCoastlineFeatureLayer::Clone() const
{
return std::make_shared<PrepareCoastlineFeatureLayer>();
}
void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder & fb)
{
@ -283,38 +259,22 @@ void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder & fb)
}
WorldLayer::WorldLayer(std::string const & popularityFilename)
: m_popularityFilename(popularityFilename)
, m_filter(popularityFilename)
: m_filter(popularityFilename)
{
}
std::shared_ptr<LayerBase> WorldLayer::Clone() const
{
return std::make_shared<WorldLayer>(m_popularityFilename);
}
void WorldLayer::Handle(FeatureBuilder & fb)
{
if (fb.RemoveInvalidTypes() && m_filter.IsAccepted(fb))
LayerBase::Handle(fb);
}
std::shared_ptr<LayerBase> CountryLayer::Clone() const
{
return std::make_shared<CountryLayer>();
}
void CountryLayer::Handle(feature::FeatureBuilder & fb)
{
if (fb.RemoveInvalidTypes() && PreprocessForCountryMap(fb))
LayerBase::Handle(fb);
}
std::shared_ptr<LayerBase> PreserializeLayer::Clone() const
{
return std::make_shared<PreserializeLayer>();
}
void PreserializeLayer::Handle(FeatureBuilder & fb)
{
if (fb.PreSerialize())

View file

@ -60,14 +60,13 @@ public:
LayerBase() = default;
virtual ~LayerBase() = default;
virtual std::shared_ptr<LayerBase> Clone() const = 0;
std::shared_ptr<LayerBase> CloneRecursive() const;
// The function works in linear time from the number of layers that exist after that.
virtual void Handle(feature::FeatureBuilder & fb);
void Merge(std::shared_ptr<LayerBase> const & other);
void MergeRecursive(std::shared_ptr<LayerBase> const & other);
void MergeChain(std::shared_ptr<LayerBase> const & other);
size_t GetChainSize() const;
void SetNext(std::shared_ptr<LayerBase> next);
std::shared_ptr<LayerBase> Add(std::shared_ptr<LayerBase> next);
@ -82,8 +81,6 @@ public:
std::string GetAsStringRecursive() const;
private:
void FailIfMethodUnsuppirted() const { CHECK(false, ("This method is unsupported.")); }
LogBuffer m_logBuffer;
std::shared_ptr<LayerBase> m_next;
};
@ -97,8 +94,6 @@ private:
class RepresentationLayer : public LayerBase
{
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override;
void Handle(feature::FeatureBuilder & fb) override;
private:
@ -107,7 +102,6 @@ private:
static bool CanBeLine(FeatureParams const & params);
void HandleArea(feature::FeatureBuilder & fb, FeatureParams const & params);
std::shared_ptr<PlaceProcessor> m_processor;
};
// Responsibility of class PrepareFeatureLayer is the removal of unused types and names,
@ -116,8 +110,6 @@ class PrepareFeatureLayer : public LayerBase
{
public:
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override;
void Handle(feature::FeatureBuilder & fb) override;
};
@ -127,8 +119,6 @@ class RepresentationCoastlineLayer : public LayerBase
{
public:
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override;
void Handle(feature::FeatureBuilder & fb) override;
};
@ -138,8 +128,6 @@ class PrepareCoastlineFeatureLayer : public LayerBase
{
public:
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override;
void Handle(feature::FeatureBuilder & fb) override;
};
@ -149,12 +137,9 @@ public:
explicit WorldLayer(std::string const & popularityFilename);
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override;
void Handle(feature::FeatureBuilder & fb) override;
private:
std::string m_popularityFilename;
FilterWorld m_filter;
};
@ -162,8 +147,6 @@ class CountryLayer : public LayerBase
{
public:
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override;
void Handle(feature::FeatureBuilder & fb) override;
};
@ -171,59 +154,47 @@ class PreserializeLayer : public LayerBase
{
public:
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override;
void Handle(feature::FeatureBuilder & fb) override;
};
template <class SerializePolicy = feature::serialization_policy::MaxAccuracy>
class AffilationsFeatureLayer : public LayerBase
class AffiliationsFeatureLayer : public LayerBase
{
public:
AffilationsFeatureLayer(size_t bufferSize, std::shared_ptr<feature::AffiliationInterface> const & affilation)
AffiliationsFeatureLayer(size_t bufferSize, std::shared_ptr<feature::AffiliationInterface> const & affiliation,
std::shared_ptr<FeatureProcessorQueue> const & queue)
: m_bufferSize(bufferSize)
, m_affilation(affilation)
, m_affiliation(affiliation)
, m_queue(queue)
{
m_buffer.reserve(m_bufferSize);
}
// LayerBase overrides:
std::shared_ptr<LayerBase> Clone() const override
{
return std::make_shared<AffilationsFeatureLayer<SerializePolicy>>(m_bufferSize, m_affilation);
}
void Handle(feature::FeatureBuilder & fb) override
{
feature::FeatureBuilder::Buffer buffer;
SerializePolicy::Serialize(fb, buffer);
m_buffer.emplace_back(std::move(buffer), m_affilation->GetAffiliations(fb));
}
bool AddBufferToQueue(std::shared_ptr<FeatureProcessorQueue> const & queue)
{
if (!m_buffer.empty())
{
queue->Push(std::move(m_buffer));
m_buffer = {};
m_buffer.reserve(m_bufferSize);
return true;
}
return false;
}
bool AddBufferToQueueIfFull(std::shared_ptr<FeatureProcessorQueue> const & queue)
{
m_buffer.emplace_back(std::move(buffer), m_affiliation->GetAffiliations(fb));
if (m_buffer.size() >= m_bufferSize)
return AddBufferToQueue(queue);
AddBufferToQueue();
}
return false;
bool AddBufferToQueue()
{
if (m_buffer.empty())
return false;
m_queue->Push(std::move(m_buffer));
m_buffer.clear();
m_buffer.reserve(m_bufferSize);
return true;
}
private:
size_t const m_bufferSize;
std::vector<ProcessedData> m_buffer;
std::shared_ptr<feature::AffiliationInterface> m_affilation;
std::shared_ptr<feature::AffiliationInterface> m_affiliation;
std::shared_ptr<FeatureProcessorQueue> m_queue;
};
} // namespace generator

View file

@ -11,7 +11,7 @@
namespace generator
{
size_t static const kAffilationsBufferSize = 512;
size_t static const kAffiliationsBufferSize = 512;
struct ProcessedData
{

View file

@ -29,7 +29,7 @@ public:
{
// You can get features-2019_07_17__13_39_20 by running:
// rsync -v -p testdata.mapsme.cloud.devmail.ru::testdata/features-2019_07_17__13_39_20.zip .
Init("features-2019_07_17__13_39_20" /* arhiveName */);
Init("features-2019_07_17__13_39_20" /* archiveName */);
}
~FeatureIntegrationTests()
@ -39,8 +39,8 @@ public:
void BuildCoasts()
{
auto const worldCoastsGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME".geom");
auto const worldCoastsRawGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME".rawgeom");
auto const worldCoastsGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME ".geom");
auto const worldCoastsRawGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME ".rawgeom");
CHECK(!Platform::IsFileExistsByFullPath(worldCoastsGeom), ());
CHECK(!Platform::IsFileExistsByFullPath(worldCoastsRawGeom), ());
@ -51,7 +51,7 @@ public:
TEST(Platform::IsFileExistsByFullPath(worldCoastsGeom), ());
TEST(Platform::IsFileExistsByFullPath(worldCoastsRawGeom), ());
size_t fileSize = 0;
uint64_t fileSize = 0;
CHECK(Platform::GetFileSizeByFullPath(worldCoastsGeom, fileSize), ());
TEST_GREATER(fileSize, 0, ());
CHECK(Platform::GetFileSizeByFullPath(worldCoastsRawGeom, fileSize), ());
@ -129,16 +129,16 @@ public:
TestCountry(northAuckland, 1811971 /* fbsCnt */, 12195948 /* pointsCnt */, 1007372 /* pointCnt */,
205469 /* lineCnt */, 599130 /* areaCnt */, 212087 /* poiCnt */,
521 /* cityTownOrVillageCnt */, 43 /* popularAttractionCnt */, 3557 /* bookingHotelsCnt */);
521 /* cityTownOrVillageCnt */, 3557 /* bookingHotelsCnt */);
TestCountry(northWellington, 797778 /* fbsCnt */, 7772270 /* pointsCnt */, 460446 /* pointCnt */,
87058 /* lineCnt */, 250274 /* areaCnt */, 95651 /* poiCnt */,
297 /* cityTownOrVillageCnt */, 16 /* popularAttractionCnt */, 1062 /* bookingHotelsCnt */);
297 /* cityTownOrVillageCnt */, 1062 /* bookingHotelsCnt */);
TestCountry(southCanterbury, 636934 /* fbsCnt */, 6984360 /* pointsCnt */, 397634 /* pointCnt */,
81712 /* lineCnt */, 157588 /* areaCnt */, 89249 /* poiCnt */,
331 /* cityTownOrVillageCnt */, 40 /* popularAttractionCnt */, 2085 /* bookingHotelsCnt */);
331 /* cityTownOrVillageCnt */, 2085 /* bookingHotelsCnt */);
TestCountry(southSouthland, 340491 /* fbsCnt */, 5342804 /* pointsCnt */, 185845 /* pointCnt */,
40124 /* lineCnt */, 114522 /* areaCnt */, 40497 /* poiCnt */,
297 /* cityTownOrVillageCnt */, 37 /* popularAttractionCnt */, 1621 /* bookingHotelsCnt */);
297 /* cityTownOrVillageCnt */, 1621 /* bookingHotelsCnt */);
}
void CheckGeneratedData()
@ -166,7 +166,7 @@ public:
TestGeneratedFile(cameraToWays, 0 /* fileSize */);
TestGeneratedFile(citiesAreas, 18601 /* fileSize */);
TestGeneratedFile(maxSpeeds, 1301515 /* fileSize */);
TestGeneratedFile(metalines, 306228 /* fileSize */);
TestGeneratedFile(metalines, 288032 /* fileSize */);
TestGeneratedFile(restrictions, 273283 /* fileSize */);
TestGeneratedFile(roadAccess, 1918315 /* fileSize */);
TestGeneratedFile(m_genInfo.m_citiesBoundariesFilename, 2435 /* fileSize */);
@ -193,7 +193,7 @@ public:
private:
void TestCountry(std::string const & path, size_t fbsCnt, size_t pointsCnt, size_t pointCnt,
size_t lineCnt, size_t areaCnt, size_t poiCnt, size_t cityTownOrVillageCnt,
size_t popularAttractionCnt, size_t bookingHotelsCnt)
size_t bookingHotelsCnt)
{
CHECK(Platform::IsFileExistsByFullPath(path), ());
auto const fbs = feature::ReadAllDatRawFormat(path);
@ -203,7 +203,6 @@ private:
size_t areaCntReal = 0;
size_t poiCntReal = 0;
size_t cityTownOrVillageCntReal = 0;
size_t popularAttractionCntReal = 0;
size_t bookingHotelsCntReal = 0;
for (auto const & fb : fbs)
{
@ -219,9 +218,6 @@ private:
if (poiChecker(fb.GetTypes()))
++poiCntReal;
if (generator::FilterWorld::IsPopularAttraction(fb, m_genInfo.m_popularPlacesFilename))
++popularAttractionCntReal;
if (ftypes::IsCityTownOrVillage(fb.GetTypes()))
++cityTownOrVillageCntReal;
@ -237,19 +233,18 @@ private:
TEST_EQUAL(areaCntReal, areaCnt, ());
TEST_EQUAL(poiCntReal, poiCnt, ());
TEST_EQUAL(cityTownOrVillageCntReal, cityTownOrVillageCnt, ());
TEST_EQUAL(popularAttractionCntReal, popularAttractionCnt, ());
TEST_EQUAL(bookingHotelsCntReal, bookingHotelsCnt, ());
}
void TestGeneratedFile(std::string const & path, size_t fileSize)
{
TEST(Platform::IsFileExistsByFullPath(path), (path));
size_t fileSizeReal = 0;
uint64_t fileSizeReal = 0;
CHECK(Platform::GetFileSizeByFullPath(path, fileSizeReal), (path));
TEST_EQUAL(fileSizeReal, fileSize, (path));
}
void Init(std::string const & arhiveName)
void Init(std::string const & archiveName)
{
classificator::Load();
auto const & options = GetTestingOptions();
@ -260,13 +255,13 @@ private:
m_testPath = base::JoinPath(platform.WritableDir(), "gen-test");
m_genInfo.SetNodeStorageType("map");
m_genInfo.SetOsmFileType("o5m");
m_genInfo.m_intermediateDir = base::JoinPath(m_testPath, arhiveName, "intermediate_data");
m_genInfo.m_intermediateDir = base::JoinPath(m_testPath, archiveName, "intermediate_data");
m_genInfo.m_targetDir = m_genInfo.m_intermediateDir;
m_genInfo.m_tmpDir = base::JoinPath(m_genInfo.m_intermediateDir, "tmp");
m_genInfo.m_osmFileName = base::JoinPath(m_testPath, "planet.o5m");
m_genInfo.m_popularPlacesFilename = m_genInfo.GetIntermediateFileName("popular_places.csv");
m_genInfo.m_idToWikidataFilename = m_genInfo.GetIntermediateFileName("wiki_urls.csv");
DecompressZipArchive(base::JoinPath(options.m_dataPath, arhiveName + ".zip"), m_testPath);
DecompressZipArchive(base::JoinPath(options.m_dataPath, archiveName + ".zip"), m_testPath);
}
size_t m_threadCount;

View file

@ -27,6 +27,7 @@
#include "defines.hpp"
#include <cstdint>
#include <memory>
#include <set>
#include <string>
#include <utility>
@ -54,15 +55,15 @@ feature::FeatureBuilder MakeFeatureBuilderWithParams(OsmElement & element)
class TranslatorForTest : public Translator
{
public:
explicit TranslatorForTest(std::shared_ptr<FeatureProcessorInterface> const & processor,
std::shared_ptr<generator::cache::IntermediateData> const & cache)
: Translator(processor, cache, std::make_shared<FeatureMaker>(cache))
explicit TranslatorForTest(shared_ptr<FeatureProcessorInterface> const & processor,
shared_ptr<generator::cache::IntermediateData> const & cache)
: Translator(processor, cache, make_shared<FeatureMaker>(cache))
{
SetFilter(make_shared<FilterPlanet>());
}
// TranslatorInterface overrides:
std::shared_ptr<TranslatorInterface> Clone() const override
shared_ptr<TranslatorInterface> Clone() const override
{
CHECK(false, ());
return {};
@ -84,8 +85,8 @@ class TestCameraCollector
{
public:
// Directory name for creating test mwm and temprary files.
std::string static const kTestDir;
std::string static const kOsmFileName;
string static const kTestDir;
string static const kOsmFileName;
TestCameraCollector()
{
@ -113,10 +114,10 @@ public:
CHECK(GenerateIntermediateData(genInfo), ());
// Test load this data from cached file.
auto collector = std::make_shared<CameraCollector>(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME));
auto cache = std::make_shared<generator::cache::IntermediateData>(genInfo, true /* forceReload */);
auto collector = make_shared<CameraCollector>(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME));
auto cache = make_shared<generator::cache::IntermediateData>(genInfo, true /* forceReload */);
auto processor = CreateProcessor(ProcessorType::Noop);
auto translator = std::make_shared<TranslatorForTest>(processor, cache);
auto translator = make_shared<TranslatorForTest>(processor, cache);
translator->SetCollector(collector);
RawGenerator rawGenerator(genInfo);
rawGenerator.GenerateCustom(translator);
@ -127,9 +128,7 @@ public:
answers.emplace(camera.m_id, w);
});
return answers == trueAnswers;
}
void TestMergeCollectors()
@ -140,7 +139,7 @@ public:
// Generate intermediate data.
genInfo.m_intermediateDir = writableDir;
auto const filename = genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME);
auto collector1 = std::make_shared<CameraCollector>(filename);
auto collector1 = make_shared<CameraCollector>(filename);
auto collector2 = collector1->Clone();
{
OsmElement el;
@ -202,12 +201,12 @@ public:
answers.emplace(camera.m_id, w);
});
TEST(answers == trueAnswers, ());
TEST_EQUAL(answers, trueAnswers, ());
}
};
std::string const TestCameraCollector::kTestDir = "camera_test";
std::string const TestCameraCollector::kOsmFileName = "planet" OSM_DATA_FILE_EXTENSION;
string const TestCameraCollector::kTestDir = "camera_test";
string const TestCameraCollector::kOsmFileName = "planet" OSM_DATA_FILE_EXTENSION;
} // namespace generator_tests
using namespace generator_tests;

View file

@ -1,8 +1,8 @@
#include "testing/testing.hpp"
#include "generator/generator_tests/common.hpp"
#include "generator/collector_city_area.hpp"
#include "generator/feature_builder.hpp"
#include "generator/generator_tests/common.hpp"
#include "generator/osm2type.hpp"
#include "generator/osm_element.hpp"
@ -12,8 +12,8 @@
#include "geometry/point2d.hpp"
#include "base/scope_guard.hpp"
#include "base/geo_object_id.hpp"
#include "base/scope_guard.hpp"
#include <algorithm>
#include <memory>
@ -34,7 +34,7 @@ feature::FeatureBuilder MakeFbForTest(OsmElement element)
return result;
}
bool FindId(std::vector<feature::FeatureBuilder> const & fbs, uint64_t id) {
bool HasRelationWithId(std::vector<feature::FeatureBuilder> const & fbs, uint64_t id) {
return std::find_if(std::begin(fbs), std::end(fbs), [&](auto const & fb) {
return fb.GetMostGenericOsmId() == base::MakeOsmRelation(id);
}) != std::end(fbs);
@ -46,7 +46,7 @@ auto const o3 = MakeOsmElement(3 /* id */, {{"place", "village"}} /* tags */, Os
auto const o4 = MakeOsmElement(4 /* id */, {{"place", "country"}} /* tags */, OsmElement::EntityType::Relation);
} // namespace
UNIT_TEST(CollectorCityArea_Case1)
UNIT_TEST(CollectorCityArea_Merge)
{
classificator::Load();
auto const filename = generator_tests::GetFileName();
@ -65,7 +65,7 @@ UNIT_TEST(CollectorCityArea_Case1)
auto const fbs = feature::ReadAllDatRawFormat<feature::serialization_policy::MaxAccuracy>(filename);
TEST_EQUAL(fbs.size(), 3, ());
TEST(FindId(fbs, 1 /* id */), ());
TEST(FindId(fbs, 2 /* id */), ());
TEST(FindId(fbs, 3 /* id */), ());
TEST(HasRelationWithId(fbs, 1 /* id */), ());
TEST(HasRelationWithId(fbs, 2 /* id */), ());
TEST(HasRelationWithId(fbs, 3 /* id */), ());
}

View file

@ -30,8 +30,6 @@ OsmElement MakeOsmElement(uint64_t id, Tags const & tags, OsmElement::EntityType
std::string GetFileName(std::string const & filename)
{
auto & platform = GetPlatform();
auto const tmpDir = platform.TmpDir();
platform.SetWritableDirForTests(tmpDir);
return filename.empty() ? platform.TmpPathForFile() : platform.TmpPathForFile(filename);
}
@ -43,10 +41,9 @@ bool MakeFakeBordersFile(std::string const & intemediatePath, std::string const
if (code != Platform::EError::ERR_OK && code != Platform::EError::ERR_FILE_ALREADY_EXISTS)
return false;
std::ofstream file;
file.exceptions(std::ios::failbit | std::ios::badbit);
file.open(base::JoinPath(borderPath, filename + ".poly"));
file << filename << "\n1\n\t-180.0 -90.0\n\t180.0 -90.0\n\t180.0 90.0\n\t-180.0 90.0\n\t-180.0 -90.0\nEND\nEND";
std::vector<m2::PointD> points = {{-180.0, -90.0}, {180.0, -90.0}, {180.0, 90.0}, {-180.0, 90.0},
{-180.0, -90.0}};
borders::DumpBorderToPolyFile(borderPath, filename, {m2::RegionD{points}});
return true;
}
@ -77,7 +74,7 @@ feature::FeatureBuilder FeatureBuilderFromOmsElementData(OsmElementData const &
auto const & p1 = elementData.m_polygon[0];
auto const & p2 = elementData.m_polygon[1];
vector<m2::PointD> poly = {
{p1.x, p1.y}, {p1.x, p2.y}, {p2.x, p2.y}, {p2.x, p1.y}, {p1.x, p1.y}};
{p1.x, p1.y}, {p1.x, p2.y}, {p2.x, p2.y}, {p2.x, p1.y}, {p1.x, p1.y}};
fb.AddPolygon(poly);
fb.SetHoles({});
fb.SetArea();

View file

@ -231,7 +231,7 @@ UNIT_CLASS_TEST(TestWithClassificator, FeatureParams_Parsing)
}
}
UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder2_SerializeLocalityObjectForBuildingPoint)
UNIT_CLASS_TEST(TestWithClassificator, FeatureBuilder_SerializeLocalityObjectForBuildingPoint)
{
FeatureBuilder fb;
FeatureParams params;

View file

@ -373,11 +373,11 @@ UNIT_TEST(MaxspeedSection_Big)
TestMaxspeedsSection(roads, maxspeedsCsvContent, featureIdToOsmId);
}
UNIT_TEST(MaxspeedCollector_Case1)
UNIT_TEST(MaxspeedCollector_Merge)
{
classificator::Load();
auto const filename = GetFileName();
SCOPE_GUARD(_, bind(Platform::RemoveFileIfExists, cref(filename)));
SCOPE_GUARD(_, std::bind(Platform::RemoveFileIfExists, std::cref(filename)));
auto c1 = std::make_shared<MaxspeedsCollector>(filename);
auto c2 = c1->Clone();

View file

@ -24,7 +24,7 @@ namespace
auto const kEmptyValidator = [](auto const &) { return true; };
}
UNIT_TEST(MergeCollector_Case1)
UNIT_TEST(MergeCollector_MergeCase1)
{
auto const filename = GetFileName();
std::string const tagKey = "admin_level";
@ -59,7 +59,7 @@ UNIT_TEST(MergeCollector_Case1)
TEST_EQUAL(line, answers[pos++], ());
}
UNIT_TEST(MergeCollector_Case2)
UNIT_TEST(MergeCollector_MergeCase2)
{
auto const filename = GetFileName();
std::string const tagKey = "admin_level";

View file

@ -9,6 +9,8 @@
#include "platform/platform.hpp"
#include "coding/read_write_utils.hpp"
#include "base/scope_guard.hpp"
#include <cstddef>
@ -164,7 +166,7 @@ UNIT_TEST(MetalinesTest_Case6)
TEST_EQUAL(outputData.at(keyB).size(), 1 /* ways count */, ());
}
UNIT_TEST(MetalinesTest_MetalinesBuilder)
UNIT_TEST(MetalinesTest_MetalinesBuilderMarge)
{
classificator::Load();
auto const filename = generator_tests::GetFileName();
@ -186,9 +188,8 @@ UNIT_TEST(MetalinesTest_MetalinesBuilder)
std::set<std::vector<int32_t>> s;
while (src.Size() > 0)
{
uint16_t size = ReadPrimitiveFromSource<uint16_t>(src);
std::vector<int32_t> ways(size);
src.Read(ways.data(), size * sizeof(int32_t));
std::vector<int32_t> ways;
rw::ReadVectorOfPOD(src, ways);
s.emplace(std::move(ways));
}

View file

@ -138,7 +138,7 @@ UNIT_TEST(RegionInfoCollector_Exists)
UNIT_TEST(RegionInfoCollector_MergeAndSave)
{
auto const filename = generator_tests::GetFileName();
SCOPE_GUARD(_, bind(Platform::RemoveFileIfExists, cref(filename)));
SCOPE_GUARD(_, std::bind(Platform::RemoveFileIfExists, std::cref(filename)));
auto c1 = std::make_shared<CollectorRegionInfo>(filename);
auto c2 = c1->Clone();

View file

@ -17,6 +17,7 @@
#include "base/scope_guard.hpp"
#include "base/stl_helpers.hpp"
#include <map>
#include <memory>
#include <string>
#include <utility>
@ -214,7 +215,7 @@ UNIT_CLASS_TEST(TestRestrictionCollector, InvalidCase_FeaturesNotIntersecting)
TestRestrictionCollector::InvalidCase_FeaturesNotIntersecting();
}
UNIT_TEST(RestrictionWriter_Case1)
UNIT_TEST(RestrictionWriter_Merge)
{
classificator::Load();
auto const filename = generator_tests::GetFileName();

View file

@ -180,7 +180,7 @@ UNIT_TEST(RoadAccess_Access_Multiple_Vehicle_Types)
TEST_EQUAL(bicycleRoadAccess.GetFeatureType(3 /* featureId */), RoadAccess::Type::No, ());
}
UNIT_TEST(RoadAccessWriter_Case1)
UNIT_TEST(RoadAccessWriter_Merge)
{
classificator::Load();
auto const filename = generator_tests::GetFileName();

View file

@ -1,7 +1,6 @@
#include "testing/testing.hpp"
#include "generator/camera_info_collector.hpp"
#include "generator/processor_factory.hpp"
#include "generator/feature_sorter.hpp"
#include "generator/generate_info.hpp"
#include "generator/generator_tests/common.hpp"
@ -10,8 +9,9 @@
#include "generator/intermediate_data.hpp"
#include "generator/maxspeeds_parser.hpp"
#include "generator/metalines_builder.hpp"
#include "generator/raw_generator.hpp"
#include "generator/osm_source.hpp"
#include "generator/processor_factory.hpp"
#include "generator/raw_generator.hpp"
#include "generator/translator_collection.hpp"
#include "generator/translator_factory.hpp"

View file

@ -6,11 +6,9 @@
#include "generator/cities_boundaries_builder.hpp"
#include "generator/cities_ids_builder.hpp"
#include "generator/city_roads_generator.hpp"
#include "generator/descriptions_section_builder.hpp"
#include "generator/data_version.hpp"
#include "generator/descriptions_section_builder.hpp"
#include "generator/dumper.hpp"
#include "generator/osm_source.hpp"
#include "generator/processor_factory.hpp"
#include "generator/feature_generator.hpp"
#include "generator/feature_sorter.hpp"
#include "generator/generate_info.hpp"
@ -18,9 +16,11 @@
#include "generator/locality_sorter.hpp"
#include "generator/maxspeeds_builder.hpp"
#include "generator/metalines_builder.hpp"
#include "generator/osm_source.hpp"
#include "generator/platform_helpers.hpp"
#include "generator/popular_places_section_builder.hpp"
#include "generator/popularity.hpp"
#include "generator/processor_factory.hpp"
#include "generator/ratings_section_builder.hpp"
#include "generator/raw_generator.hpp"
#include "generator/regions/collector_region_info.hpp"
@ -117,12 +117,12 @@ DEFINE_uint64(planet_version, base::SecondsSinceEpoch(),
DEFINE_bool(preprocess, false, "1st pass - create nodes/ways/relations data.");
DEFINE_bool(generate_features, false, "2nd pass - generate intermediate features.");
DEFINE_bool(no_ads, false, "generation without ads.");
DEFINE_string(generate_region_features, "",
"Generate intermediate features for regions to use in regions index and borders generation.");
DEFINE_string(generate_streets_features, "",
"Generate intermediate features for streets to use in server-side forward geocoder.");
DEFINE_string(generate_geo_objects_features, "",
"Generate intermediate features for geo objects to use in geo objects index.");
DEFINE_bool(generate_region_features, false,
"Generate intermediate features for regions to use in regions index and borders generation.");
DEFINE_bool(generate_streets_features, false,
"Generate intermediate features for streets to use in server-side forward geocoder.");
DEFINE_bool(generate_geo_objects_features, false,
"Generate intermediate features for geo objects to use in geo objects index.");
DEFINE_bool(generate_geometry, false,
"3rd pass - split and simplify geometry and triangles for features.");
DEFINE_bool(generate_index, false, "4rd pass - generate index.");
@ -222,14 +222,13 @@ DEFINE_string(regions_features, "", "Input tmp.mwm file with regions.");
DEFINE_string(popularity_csv, "", "Output csv for popularity.");
DEFINE_bool(dump_mwm_tmp, false, "Prints features builder objects from .mwm.tmp");
DEFINE_bool(dump_mwm_tmp, false, "Prints feature builder objects from .mwm.tmp");
// Common.
DEFINE_bool(verbose, false, "Provide more detailed output.");
using namespace generator;
int GeneratorToolMain(int argc, char ** argv)
{
CHECK(IsLittleEndian(), ("Only little-endian architectures are supported."));
@ -312,9 +311,9 @@ int GeneratorToolMain(int argc, char ** argv)
if (FLAGS_generate_features ||
FLAGS_generate_world ||
FLAGS_make_coasts ||
!FLAGS_generate_region_features.empty() ||
!FLAGS_generate_streets_features.empty() ||
!FLAGS_generate_geo_objects_features.empty())
FLAGS_generate_region_features ||
FLAGS_generate_streets_features ||
FLAGS_generate_geo_objects_features)
{
RawGenerator rawGenerator(genInfo, threadsCount);
if (FLAGS_generate_features)
@ -323,12 +322,12 @@ int GeneratorToolMain(int argc, char ** argv)
rawGenerator.GenerateWorld(FLAGS_no_ads);
if (FLAGS_make_coasts)
rawGenerator.GenerateCoasts();
if (!FLAGS_generate_region_features.empty())
rawGenerator.GenerateRegionFeatures(FLAGS_generate_region_features);
if (!FLAGS_generate_streets_features.empty())
rawGenerator.GenerateStreetsFeatures(FLAGS_generate_streets_features);
if (!FLAGS_generate_geo_objects_features.empty())
rawGenerator.GenerateGeoObjectsFeatures(FLAGS_generate_geo_objects_features);
if (FLAGS_generate_region_features)
rawGenerator.GenerateRegionFeatures(FLAGS_output);
if (FLAGS_generate_streets_features)
rawGenerator.GenerateStreetsFeatures(FLAGS_output);
if (FLAGS_generate_geo_objects_features)
rawGenerator.GenerateGeoObjectsFeatures(FLAGS_output);
if (!rawGenerator.Execute())
return EXIT_FAILURE;

View file

@ -6,6 +6,7 @@
#include "indexer/classificator.hpp"
#include "coding/file_container.hpp"
#include "coding/read_write_utils.hpp"
#include "coding/varint.hpp"
#include "coding/write_to_sink.hpp"
@ -104,7 +105,7 @@ LineStringMerger::OutputData LineStringMerger::Merge(InputData const & data)
bool LineStringMerger::TryMerge(LinePtr const & lineString, Buffer & buffer)
{
bool merged = false;
while(TryMergeOne(lineString, buffer))
while (TryMergeOne(lineString, buffer))
merged = true;
buffer.emplace(lineString->GetStart(), lineString);
@ -200,11 +201,8 @@ void MetalinesBuilder::Save()
for (auto const & lineString : p.second)
{
auto const & ways = lineString->GetWays();
uint16_t size = base::checked_cast<uint16_t>(ways.size());
WriteToSink(writer, size);
rw::WriteVectorOfPOD(writer, ways);
countWays += ways.size();
for (int32_t const way : ways)
WriteToSink(writer, way);
++countLines;
}
}
@ -240,9 +238,8 @@ bool WriteMetalinesSection(std::string const & mwmPath, std::string const & meta
while (src.Size() > 0)
{
std::vector<int32_t> featureIds;
uint16_t size = ReadPrimitiveFromSource<uint16_t>(src);
std::vector<int32_t> ways(size);
src.Read(ways.data(), size * sizeof(int32_t));
std::vector<int32_t> ways;
rw::ReadVectorOfPOD(src, ways);
for (auto const wayId : ways)
{
// We get a negative wayId when a feature direction should be reversed.

View file

@ -19,9 +19,9 @@ ProcessorCoastline::ProcessorCoastline(std::shared_ptr<FeatureProcessorQueue> co
{
m_processingChain = std::make_shared<RepresentationCoastlineLayer>();
m_processingChain->Add(std::make_shared<PrepareCoastlineFeatureLayer>());
auto affilation = std::make_shared<feature::SingleAffiliation>(WORLD_COASTS_FILE_NAME);
m_affilationsLayer = std::make_shared<AffilationsFeatureLayer<>>(kAffilationsBufferSize, affilation);
m_processingChain->Add(m_affilationsLayer);
auto affiliation = std::make_shared<feature::SingleAffiliation>(WORLD_COASTS_FILE_NAME);
m_affiliationsLayer = std::make_shared<AffiliationsFeatureLayer<>>(kAffiliationsBufferSize, affiliation, m_queue);
m_processingChain->Add(m_affiliationsLayer);
}
std::shared_ptr<FeatureProcessorInterface> ProcessorCoastline::Clone() const
@ -32,12 +32,11 @@ std::shared_ptr<FeatureProcessorInterface> ProcessorCoastline::Clone() const
void ProcessorCoastline::Process(feature::FeatureBuilder & feature)
{
m_processingChain->Handle(feature);
m_affilationsLayer->AddBufferToQueueIfFull(m_queue);
}
void ProcessorCoastline::Finish()
{
m_affilationsLayer->AddBufferToQueue(m_queue);
m_affiliationsLayer->AddBufferToQueue();
}
void ProcessorCoastline::Merge(FeatureProcessorInterface const & other)
@ -47,6 +46,6 @@ void ProcessorCoastline::Merge(FeatureProcessorInterface const & other)
void ProcessorCoastline::MergeInto(ProcessorCoastline & other) const
{
other.m_processingChain->Merge(m_processingChain);
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator

View file

@ -24,7 +24,7 @@ public:
void MergeInto(ProcessorCoastline & other) const override;
private:
std::shared_ptr<AffilationsFeatureLayer<>> m_affilationsLayer;
std::shared_ptr<AffiliationsFeatureLayer<>> m_affiliationsLayer;
std::shared_ptr<FeatureProcessorQueue> m_queue;
std::shared_ptr<LayerBase> m_processingChain;
};

View file

@ -20,9 +20,9 @@ ProcessorCountry::ProcessorCountry(std::shared_ptr<FeatureProcessorQueue> const
m_processingChain = std::make_shared<RepresentationLayer>();
m_processingChain->Add(std::make_shared<PrepareFeatureLayer>());
m_processingChain->Add(std::make_shared<CountryLayer>());
auto affilation = std::make_shared<feature::CountriesFilesAffiliation>(bordersPath, haveBordersForWholeWorld);
m_affilationsLayer = std::make_shared<AffilationsFeatureLayer<>>(kAffilationsBufferSize, affilation);
m_processingChain->Add(m_affilationsLayer);
auto affiliation = std::make_shared<feature::CountriesFilesAffiliation>(bordersPath, haveBordersForWholeWorld);
m_affiliationsLayer = std::make_shared<AffiliationsFeatureLayer<>>(kAffiliationsBufferSize, affiliation, m_queue);
m_processingChain->Add(m_affiliationsLayer);
}
@ -34,12 +34,11 @@ std::shared_ptr<FeatureProcessorInterface> ProcessorCountry::Clone() const
void ProcessorCountry::Process(feature::FeatureBuilder & feature)
{
m_processingChain->Handle(feature);
m_affilationsLayer->AddBufferToQueueIfFull(m_queue);
}
void ProcessorCountry::Finish()
{
m_affilationsLayer->AddBufferToQueue(m_queue);
m_affiliationsLayer->AddBufferToQueue();
}
void ProcessorCountry::WriteDump()
@ -58,6 +57,6 @@ void ProcessorCountry::Merge(FeatureProcessorInterface const & other)
void ProcessorCountry::MergeInto(ProcessorCountry & other) const
{
other.m_processingChain->Merge(m_processingChain);
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator

View file

@ -37,7 +37,7 @@ private:
std::string m_bordersPath;
std::string m_layerLogFilename;
std::shared_ptr<AffilationsFeatureLayer<>> m_affilationsLayer;
std::shared_ptr<AffiliationsFeatureLayer<>> m_affiliationsLayer;
std::shared_ptr<FeatureProcessorQueue> m_queue;
std::shared_ptr<LayerBase> m_processingChain;
bool m_haveBordersForWholeWorld;

View file

@ -12,10 +12,11 @@ ProcessorSimple::ProcessorSimple(std::shared_ptr<FeatureProcessorQueue> const &
: m_name(name)
, m_queue(queue)
{
m_processingChain->Add(std::make_shared<PreserializeLayer>());
auto affilation = std::make_shared<feature::SingleAffiliation>(name);
m_affilationsLayer = std::make_shared<AffilationsFeatureLayer<feature::serialization_policy::MinSize>>(kAffilationsBufferSize, affilation);
m_processingChain->Add(m_affilationsLayer);
m_processingChain = std::make_shared<PreserializeLayer>();
auto affiliation = std::make_shared<feature::SingleAffiliation>(name);
m_affiliationsLayer = std::make_shared<AffiliationsFeatureLayer<
feature::serialization_policy::MinSize>>(kAffiliationsBufferSize, affiliation, m_queue);
m_processingChain->Add(m_affiliationsLayer);
}
std::shared_ptr<FeatureProcessorInterface>ProcessorSimple::Clone() const
@ -26,12 +27,11 @@ std::shared_ptr<FeatureProcessorInterface>ProcessorSimple::Clone() const
void ProcessorSimple::Process(feature::FeatureBuilder & fb)
{
m_processingChain->Handle(fb);
m_affilationsLayer->AddBufferToQueueIfFull(m_queue);
}
void ProcessorSimple::Finish()
{
m_affilationsLayer->AddBufferToQueue(m_queue);
m_affiliationsLayer->AddBufferToQueue();
}
void ProcessorSimple::Merge(FeatureProcessorInterface const & other)
@ -41,6 +41,6 @@ void ProcessorSimple::Merge(FeatureProcessorInterface const & other)
void ProcessorSimple::MergeInto(ProcessorSimple & other) const
{
other.m_processingChain->Merge(m_processingChain);
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator

View file

@ -30,7 +30,7 @@ public:
private:
std::string m_name;
std::shared_ptr<AffilationsFeatureLayer<feature::serialization_policy::MinSize>> m_affilationsLayer;
std::shared_ptr<AffiliationsFeatureLayer<feature::serialization_policy::MinSize>> m_affiliationsLayer;
std::shared_ptr<FeatureProcessorQueue> m_queue;
std::shared_ptr<LayerBase> m_processingChain;
};

View file

@ -16,9 +16,9 @@ ProcessorWorld::ProcessorWorld(std::shared_ptr<FeatureProcessorQueue> const & qu
m_processingChain = std::make_shared<RepresentationLayer>();
m_processingChain->Add(std::make_shared<PrepareFeatureLayer>());
m_processingChain->Add(std::make_shared<WorldLayer>(popularityFilename));
auto affilation = std::make_shared<feature::SingleAffiliation>(WORLD_FILE_NAME);
m_affilationsLayer = std::make_shared<AffilationsFeatureLayer<>>(kAffilationsBufferSize, affilation);
m_processingChain->Add(m_affilationsLayer);
auto affiliation = std::make_shared<feature::SingleAffiliation>(WORLD_FILE_NAME);
m_affiliationsLayer = std::make_shared<AffiliationsFeatureLayer<>>(kAffiliationsBufferSize, affiliation, m_queue);
m_processingChain->Add(m_affiliationsLayer);
}
std::shared_ptr<FeatureProcessorInterface> ProcessorWorld::Clone() const
@ -29,12 +29,11 @@ std::shared_ptr<FeatureProcessorInterface> ProcessorWorld::Clone() const
void ProcessorWorld::Process(feature::FeatureBuilder & feature)
{
m_processingChain->Handle(feature);
m_affilationsLayer->AddBufferToQueueIfFull(m_queue);
}
void ProcessorWorld::Finish()
{
m_affilationsLayer->AddBufferToQueue(m_queue);
m_affiliationsLayer->AddBufferToQueue();
}
void ProcessorWorld::Merge(FeatureProcessorInterface const & other)
@ -44,6 +43,6 @@ void ProcessorWorld::Merge(FeatureProcessorInterface const & other)
void ProcessorWorld::MergeInto(ProcessorWorld & other) const
{
other.m_processingChain->Merge(m_processingChain);
other.m_processingChain->MergeChain(m_processingChain);
}
} // namespace generator

View file

@ -33,7 +33,7 @@ public:
private:
std::string m_popularityFilename;
std::shared_ptr<AffilationsFeatureLayer<>> m_affilationsLayer;
std::shared_ptr<AffiliationsFeatureLayer<>> m_affiliationsLayer;
std::shared_ptr<FeatureProcessorQueue> m_queue;
std::shared_ptr<LayerBase> m_processingChain;
};

View file

@ -18,7 +18,7 @@
class WaysParserHelper
{
public:
WaysParserHelper(std::map<uint64_t, std::string> & ways) : m_ways(ways) {}
explicit WaysParserHelper(std::map<uint64_t, std::string> & ways) : m_ways(ways) {}
void ParseStream(std::istream & input)
{
@ -43,7 +43,7 @@ private:
class CapitalsParserHelper
{
public:
CapitalsParserHelper(std::set<uint64_t> & capitals) : m_capitals(capitals) {}
explicit CapitalsParserHelper(std::set<uint64_t> & capitals) : m_capitals(capitals) {}
void ParseStream(std::istream & input)
{
@ -81,7 +81,7 @@ class TagAdmixer
public:
TagAdmixer() = default;
TagAdmixer(std::string const & waysFile, std::string const & capitalsFile) : m_ferryTag("route", "ferry")
explicit TagAdmixer(std::string const & waysFile, std::string const & capitalsFile)
{
{
std::ifstream reader(waysFile);
@ -97,7 +97,7 @@ public:
}
TagAdmixer(TagAdmixer const & other)
: m_ways(other.m_ways), m_capitals(other.m_capitals), m_ferryTag(other.m_ferryTag) {}
: m_ways(other.m_ways), m_capitals(other.m_capitals) {}
TagAdmixer & operator=(TagAdmixer const & other)
{
@ -105,7 +105,6 @@ public:
{
m_ways = other.m_ways;
m_capitals = other.m_capitals;
m_ferryTag = other.m_ferryTag;
}
return *this;
@ -116,7 +115,8 @@ public:
if (element.m_type == OsmElement::EntityType::Way && m_ways.find(element.m_id) != m_ways.end())
{
// Exclude ferry routes.
if (find(element.Tags().begin(), element.Tags().end(), m_ferryTag) == element.Tags().end())
static OsmElement::Tag const kFerryTag = {"route", "ferry"};
if (find(element.Tags().begin(), element.Tags().end(), kFerryTag) == element.Tags().end())
element.AddTag("highway", m_ways[element.m_id]);
}
else if (element.m_type == OsmElement::EntityType::Node && m_capitals.find(element.m_id) != m_capitals.end())
@ -136,7 +136,6 @@ public:
private:
std::map<uint64_t, std::string> m_ways;
std::set<uint64_t> m_capitals;
OsmElement::Tag m_ferryTag;
};
class TagReplacer
@ -144,7 +143,7 @@ class TagReplacer
public:
TagReplacer() = default;
TagReplacer(std::string const & filePath)
explicit TagReplacer(std::string const & filePath)
{
std::ifstream stream(filePath);
@ -209,7 +208,7 @@ class OsmTagMixer
public:
OsmTagMixer() = default;
OsmTagMixer(std::string const & filePath)
explicit OsmTagMixer(std::string const & filePath)
{
std::ifstream stream(filePath);
std::vector<std::string> values;
@ -237,10 +236,7 @@ public:
}
if (!tags.empty())
{
std::pair<OsmElement::EntityType, uint64_t> elementPair = {entityType, id};
m_elements[elementPair].swap(tags);
}
m_elements[{entityType, id}].swap(tags);
}
}
@ -256,8 +252,7 @@ public:
void operator()(OsmElement & element)
{
std::pair<OsmElement::EntityType, uint64_t> elementId = {element.m_type, element.m_id};
auto elements = m_elements.find(elementId);
auto elements = m_elements.find({element.m_type, element.m_id});
if (elements != m_elements.end())
{
for (OsmElement::Tag tag : elements->second)

View file

@ -55,6 +55,12 @@ protected:
return std::make_shared<T>(processor, cache, featureMaker, filter, collector);
}
void MergeIntoBase(Translator & other) const
{
other.m_collector->Merge(*m_collector);
other.m_processor->Merge(*m_processor);
}
std::shared_ptr<FilterInterface> m_filter;
std::shared_ptr<CollectorInterface> m_collector;
RelationTagsEnricher m_tagsEnricher;

View file

@ -14,8 +14,6 @@
#include "base/file_name_utils.hpp"
#include <memory>
#include "defines.hpp"
using namespace feature;
@ -65,7 +63,6 @@ void TranslatorCoastline::Merge(TranslatorInterface const & other)
void TranslatorCoastline::MergeInto(TranslatorCoastline & other) const
{
other.m_collector->Merge(*m_collector);
other.m_processor->Merge(*m_processor);
MergeIntoBase(other);
}
} // namespace generator

View file

@ -28,10 +28,9 @@ public:
std::shared_ptr<TranslatorInterface> Clone() const override;
void Merge(TranslatorInterface const & other) override;
void MergeInto(TranslatorCoastline & other) const override;
protected:
using Translator::Translator;
void MergeInto(TranslatorCoastline & other) const override;
};
} // namespace generator

View file

@ -38,14 +38,14 @@ bool TranslatorCollection::Save()
});
}
void TranslatorCollection::Merge(TranslatorInterface const & collector)
void TranslatorCollection::Merge(TranslatorInterface const & other)
{
collector.MergeInto(*this);
other.MergeInto(*this);
}
void TranslatorCollection::MergeInto(TranslatorCollection & collector) const
void TranslatorCollection::MergeInto(TranslatorCollection & other) const
{
auto & otherCollection = collector.m_collection;
auto & otherCollection = other.m_collection;
CHECK_EQUAL(m_collection.size(), otherCollection.size(), ());
for (size_t i = 0; i < m_collection.size(); ++i)
otherCollection[i]->Merge(*m_collection[i]);

View file

@ -124,8 +124,7 @@ void TranslatorCountry::Merge(TranslatorInterface const & other)
void TranslatorCountry::MergeInto(TranslatorCountry & other) const
{
other.m_collector->Merge(*m_collector);
other.m_processor->Merge(*m_processor);
MergeIntoBase(other);
}
void TranslatorCountry::CollectFromRelations(OsmElement const & element)

View file

@ -32,7 +32,6 @@ void TranslatorGeoObjects::Merge(TranslatorInterface const & other)
void TranslatorGeoObjects::MergeInto(TranslatorGeoObjects & other) const
{
other.m_collector->Merge(*m_collector);
other.m_processor->Merge(*m_processor);
MergeIntoBase(other);
}
} // namespace generator

View file

@ -74,7 +74,6 @@ void TranslatorRegion::Merge(TranslatorInterface const & other)
void TranslatorRegion::MergeInto(TranslatorRegion & other) const
{
other.m_collector->Merge(*m_collector);
other.m_processor->Merge(*m_processor);
MergeIntoBase(other);
}
} // namespace generator

View file

@ -28,7 +28,6 @@ void TranslatorStreets::Merge(TranslatorInterface const & other)
void TranslatorStreets::MergeInto(TranslatorStreets & other) const
{
other.m_collector->Merge(*m_collector);
other.m_processor->Merge(*m_processor);
MergeIntoBase(other);
}
} // namespace generator

View file

@ -5,6 +5,7 @@
#include "generator/filter_collection.hpp"
#include "generator/filter_planet.hpp"
#include "generator/filter_elements.hpp"
#include "generator/filter_world.hpp"
#include "generator/generate_info.hpp"
#include "generator/intermediate_data.hpp"
#include "generator/node_mixer.hpp"
@ -56,8 +57,7 @@ void TranslatorWorld::Merge(TranslatorInterface const & other)
void TranslatorWorld::MergeInto(TranslatorWorld & other) const
{
other.m_collector->Merge(*m_collector);
other.m_processor->Merge(*m_processor);
MergeIntoBase(other);
}
TranslatorWorldWithAds::TranslatorWorldWithAds(std::shared_ptr<FeatureProcessorInterface> const & processor,

View file

@ -2,7 +2,7 @@
namespace generator
{
AreaWayMerger::AreaWayMerger( std::shared_ptr<generator::cache::IntermediateDataReader> const & cache) :
AreaWayMerger::AreaWayMerger(std::shared_ptr<cache::IntermediateDataReader> const & cache) :
m_cache(cache)
{
}