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:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-11-03 10:59:57 +0300
committerVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-11-10 18:58:21 +0300
commit0ef7cf7b74c76af4a5c1948bf7e629d346dd6fed (patch)
treee6f0f149276c5a584e9f49d278ad3f310a5efa61 /generator
parent154f78152bba1463d7bb5c49a77b314b3ddf4702 (diff)
Review fixes.
Diffstat (limited to 'generator')
-rw-r--r--generator/feature_generator.cpp11
-rw-r--r--generator/feature_generator.hpp10
-rw-r--r--generator/feature_sorter.cpp7
-rw-r--r--generator/generator_tests/restriction_test.cpp4
-rw-r--r--generator/osm_source.cpp6
-rw-r--r--generator/polygonizer.hpp3
-rw-r--r--generator/restriction_collector.cpp14
-rw-r--r--generator/restriction_collector.hpp6
8 files changed, 35 insertions, 26 deletions
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<char> 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<mutex> gard(m_mutex);
+ lock_guard<mutex> guard(m_mutex);
m_stream.open(fullPath, std::ofstream::out);
}
bool SyncOfstream::IsOpened()
{
- lock_guard<mutex> gard(m_mutex);
+ lock_guard<mutex> guard(m_mutex);
return m_stream.is_open() && !m_stream.fail();
}
@@ -549,7 +549,7 @@ void SyncOfstream::Write(uint32_t featureId, vector<osm::Id> const & osmIds)
if (!IsOpened())
return;
- lock_guard<mutex> gard(m_mutex);
+ lock_guard<mutex> 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<uint64_t> & 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<uint64_t, Index> 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<Restriction>.
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
{