diff --git a/generator/feature_generator.cpp b/generator/feature_generator.cpp index a756e48533..2215033bad 100644 --- a/generator/feature_generator.cpp +++ b/generator/feature_generator.cpp @@ -103,11 +103,13 @@ uint32_t FeaturesCollector::WriteFeatureBase(vector const & bytes, Feature return m_featureID++; } -void FeaturesCollector::operator()(FeatureBuilder1 const & fb) +uint32_t FeaturesCollector::operator()(FeatureBuilder1 const & fb) { FeatureBuilder1::TBuffer bytes; fb.Serialize(bytes); (void)WriteFeatureBase(bytes, fb); + CHECK_LESS(0, m_featureID, ()); + return m_featureID - 1; } FeaturesAndRawGeometryCollector::FeaturesAndRawGeometryCollector(string const & featuresFileName, @@ -124,12 +126,12 @@ FeaturesAndRawGeometryCollector::~FeaturesAndRawGeometryCollector() LOG(LINFO, ("Write", m_rawGeometryCounter, "geometries into", m_rawGeometryFileStream.GetName())); } -void FeaturesAndRawGeometryCollector::operator()(FeatureBuilder1 const & fb) +uint32_t FeaturesAndRawGeometryCollector::operator()(FeatureBuilder1 const & fb) { - FeaturesCollector::operator()(fb); + uint32_t const featureId = FeaturesCollector::operator()(fb); FeatureBuilder1::TGeometry const & geom = fb.GetGeometry(); if (geom.empty()) - return; + return featureId; ++m_rawGeometryCounter; @@ -142,5 +144,6 @@ void FeaturesAndRawGeometryCollector::operator()(FeatureBuilder1 const & fb) m_rawGeometryFileStream.Write(points.data(), sizeof(FeatureBuilder1::TPointSeq::value_type) * points.size()); } + return featureId; } } diff --git a/generator/feature_generator.hpp b/generator/feature_generator.hpp index f050d2bcd3..f9e4c6ac71 100644 --- a/generator/feature_generator.hpp +++ b/generator/feature_generator.hpp @@ -22,6 +22,8 @@ protected: FileWriter m_datFile; m2::RectD m_bounds; + uint32_t GetNextFeatureId() const { return m_featureID; } + private: void Write(char const * src, size_t size); void FlushBuffer(); @@ -40,9 +42,9 @@ public: string const & GetFilePath() const { return m_datFile.GetName(); } - uint32_t GetNextFeatureId() const { return m_featureID; } - - virtual void operator()(FeatureBuilder1 const & f); + /// \brief Serializes |f|. + /// \returns feature id of serialized feature. + virtual uint32_t operator()(FeatureBuilder1 const & f); }; class FeaturesAndRawGeometryCollector : public FeaturesCollector @@ -55,6 +57,6 @@ public: string const & rawGeometryFileName); ~FeaturesAndRawGeometryCollector(); - void operator()(FeatureBuilder1 const & f) override; + uint32_t operator()(FeatureBuilder1 const & f) override; }; } diff --git a/generator/feature_sorter.cpp b/generator/feature_sorter.cpp index 3e373d900c..4837b20352 100644 --- a/generator/feature_sorter.cpp +++ b/generator/feature_sorter.cpp @@ -446,7 +446,7 @@ namespace feature bool IsCountry() const { return m_header.GetType() == feature::DataHeader::country; } public: - void operator() (FeatureBuilder2 & fb) + uint32_t operator() (FeatureBuilder2 & fb) { GeometryHolder holder(*this, fb, m_header); @@ -542,7 +542,10 @@ namespace feature uint64_t const osmID = fb.GetWayIDForRouting(); if (osmID != 0) m_osm2ft.Add(make_pair(osmID, ftID)); - } + }; + // Note. GetNextFeatureId() returns 0 in the first call of + // fb.PreSerialize(holder.m_buffer) returns false. + return GetNextFeatureId() == 0 ? 0 : GetNextFeatureId(); } }; diff --git a/generator/generator_tests/restriction_test.cpp b/generator/generator_tests/restriction_test.cpp index bc64079940..8539203cbd 100644 --- a/generator/generator_tests/restriction_test.cpp +++ b/generator/generator_tests/restriction_test.cpp @@ -109,10 +109,10 @@ UNIT_TEST(RestrictionGenerationTest_OneRestriction) UNIT_TEST(RestrictionGenerationTest_ThreeRestriction) { string const restrictionContent = R"(No, 10, 10, - Only, 10, 20, + Only, 10, 20 Only, 30, 40)"; string const featureIdToOsmIdsContent = R"(1, 10, - 2, 20, + 2, 20 3, 30, 4, 40)"; TestRestrictionBuilding(restrictionContent, featureIdToOsmIdsContent); diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 30ad13d308..89f0f33c4b 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -534,13 +534,13 @@ private: void SyncOfstream::Open(string const & fullPath) { - lock_guard gard(m_mutex); + lock_guard guard(m_mutex); m_stream.open(fullPath, std::ofstream::out); } bool SyncOfstream::IsOpened() { - lock_guard gard(m_mutex); + lock_guard guard(m_mutex); return m_stream.is_open() && !m_stream.fail(); } @@ -549,7 +549,7 @@ void SyncOfstream::Write(uint32_t featureId, vector const & osmIds) if (!IsOpened()) return; - lock_guard gard(m_mutex); + lock_guard guard(m_mutex); m_stream << featureId << ","; for (osm::Id const & osmId : osmIds) m_stream << osmId.OsmId() << ","; diff --git a/generator/polygonizer.hpp b/generator/polygonizer.hpp index 91449ed4b3..877f7e4247 100644 --- a/generator/polygonizer.hpp +++ b/generator/polygonizer.hpp @@ -168,8 +168,7 @@ namespace feature m_currentNames += country->m_name; auto & bucket = *(m_Buckets[country->m_index]); - bucket(fb); - uint32_t const nextFeatureId = bucket.GetNextFeatureId(); + uint32_t const nextFeatureId = bucket(fb); CHECK_LESS(0, nextFeatureId, ("GetNextFeatureId() is called before WriteFeatureBase(...)")); if (fb.IsLine()) diff --git a/generator/restriction_collector.cpp b/generator/restriction_collector.cpp index c4c1a6df0c..22add4b1fc 100644 --- a/generator/restriction_collector.cpp +++ b/generator/restriction_collector.cpp @@ -11,8 +11,8 @@ namespace { -string const kNoStr = "No"; -string const kOnlyStr = "Only"; +char const kNo[] = "No"; +char const kOnly[] = "Only"; bool ParseLineOfNumbers(istringstream & stream, vector & numbers) { @@ -116,7 +116,7 @@ bool RestrictionCollector::ParseRestrictions(string const & restrictionPath) void RestrictionCollector::ComposeRestrictions() { - // Going throught all osm id saved in |m_restrictionIndex| (mentioned in restrictions). + // Going through all osm id saved in |m_restrictionIndex| (mentioned in restrictions). size_t const restrictionSz = m_restrictions.size(); for (pair const & osmIdAndIndex : m_restrictionIndex) { @@ -176,9 +176,9 @@ string ToString(Restriction::Type const & type) switch (type) { case Restriction::Type::No: - return kNoStr; + return kNo; case Restriction::Type::Only: - return kOnlyStr; + return kOnly; } return "Unknown"; } @@ -186,12 +186,12 @@ string ToString(Restriction::Type const & type) bool FromString(string str, Restriction::Type & type) { str.erase(remove_if(str.begin(), str.end(), isspace), str.end()); - if (str == kNoStr) + if (str == kNo) { type = Restriction::Type::No; return true; } - if (str == kOnlyStr) + if (str == kOnly) { type = Restriction::Type::Only; return true; diff --git a/generator/restriction_collector.hpp b/generator/restriction_collector.hpp index 432bcf8dc0..d30c75c70f 100644 --- a/generator/restriction_collector.hpp +++ b/generator/restriction_collector.hpp @@ -24,8 +24,10 @@ public: /// \brief Addresses a link in vector. struct Index { - size_t m_restrictionNumber; // Restriction number in restriction vector. - size_t m_linkNumber; // Link number for a restriction. It's equal to zero or one for most cases. + Index(size_t restrictionNumber, size_t linkNumber) + : m_restrictionNumber(restrictionNumber), m_linkNumber(linkNumber) {} + size_t m_restrictionNumber = 0; // Restriction number in restriction vector. + size_t m_linkNumber = 0; // Link number for a restriction. It's equal to zero or one for most cases. bool operator==(Index const & index) const { diff --git a/tools/unix/generate_mwm.sh b/tools/unix/generate_mwm.sh index 56dcf059c2..13c47bff28 100755 --- a/tools/unix/generate_mwm.sh +++ b/tools/unix/generate_mwm.sh @@ -104,7 +104,7 @@ if [ "$SOURCE_TYPE" == "pbf" -o "$SOURCE_TYPE" == "bz2" -o "$SOURCE_TYPE" == "os fi if [ "$SOURCE_TYPE" == "o5m" ]; then $GENERATOR_TOOL $INTDIR_FLAG --osm_file_type=o5m --osm_file_name="$SOURCE_FILE" --preprocess=true || fail "Preprocessing failed" - $GENERATOR_TOOL $INTDIR_FLAG --osm_file_type=o5m --osm_file_name="$SOURCE_FILE" --restriction_name="restrictions.csv" --feature_id_to_osm_ids_name="feature_id_to_osm_ids.csv" --generate_outgoing_edge_index --data_path="$TARGET" --user_resource_path="$DATA_PATH" $GENERATE_EVERYTHING --output="$BASE_NAME" + $GENERATOR_TOOL $INTDIR_FLAG --osm_file_type=o5m --osm_file_name="$SOURCE_FILE" --data_path="$TARGET" --user_resource_path="$DATA_PATH" $GENERATE_EVERYTHING --output="$BASE_NAME" else fail "Unsupported source type: $SOURCE_TYPE" fi