diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-11-08 09:00:17 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-11-10 18:58:22 +0300 |
commit | af3a06ed94434f4e417b56ad3a5c497c7e6d0c40 (patch) | |
tree | 5db29db93a0f5966f49d84363dfe366151992fb9 /generator | |
parent | 4b920ba9cf3d856f40a3afea1b3ef5a7b1554ddb (diff) |
Using SimpleTokenizer and some other review fixes.
Diffstat (limited to 'generator')
-rw-r--r-- | generator/generator_tests/restriction_collector_test.cpp | 6 | ||||
-rw-r--r-- | generator/restriction_collector.cpp | 49 | ||||
-rw-r--r-- | generator/restriction_collector.hpp | 4 |
3 files changed, 25 insertions, 34 deletions
diff --git a/generator/generator_tests/restriction_collector_test.cpp b/generator/generator_tests/restriction_collector_test.cpp index c0d537ec29..562b10b2d9 100644 --- a/generator/generator_tests/restriction_collector_test.cpp +++ b/generator/generator_tests/restriction_collector_test.cpp @@ -123,13 +123,13 @@ UNIT_TEST(RestrictionTest_ParseFeatureId2OsmIdsMapping) restrictionCollector.ParseFeatureId2OsmIdsMapping( my::JoinFoldersToPath(platform.WritableDir(), kFeatureIdToOsmIdsPath)); - vector<pair<uint64_t, Restriction::FeatureId>> const expectedOsmIds2FeatureId = { + vector<pair<uint64_t, uint32_t>> const expectedOsmIds2FeatureId = { {10, 1}, {20, 2}, {30, 3}, {5423239545, 779703}}; - vector<pair<uint64_t, Restriction::FeatureId>> osmIds2FeatureId( + vector<pair<uint64_t, uint32_t>> osmIds2FeatureId( restrictionCollector.m_osmIds2FeatureId.cbegin(), restrictionCollector.m_osmIds2FeatureId.cend()); sort(osmIds2FeatureId.begin(), osmIds2FeatureId.end(), - my::LessBy(&pair<uint64_t, Restriction::FeatureId>::first)); + my::LessBy(&pair<uint64_t, uint32_t>::first)); TEST_EQUAL(osmIds2FeatureId, expectedOsmIds2FeatureId, ()); } diff --git a/generator/restriction_collector.cpp b/generator/restriction_collector.cpp index 72eda3168f..774c08a787 100644 --- a/generator/restriction_collector.cpp +++ b/generator/restriction_collector.cpp @@ -7,29 +7,21 @@ #include "std/algorithm.hpp" #include "std/fstream.hpp" -#include "std/sstream.hpp" namespace { char const kNo[] = "No"; char const kOnly[] = "Only"; -bool ParseLineOfNumbers(istringstream & stream, vector<uint64_t> & numbers) +bool ParseLineOfNumbers(strings::SimpleTokenizer & iter, vector<uint64_t> & numbers) { - string numberStr; - uint64_t number; - - while (stream) + uint64_t number = 0; + while (iter) { - if (!getline(stream, numberStr, ',')) - return true; - if (numberStr.empty()) - return true; - - if (!strings::to_uint64(numberStr, number)) + if (!strings::to_uint64(*iter, number)) return false; - numbers.push_back(number); + ++iter; } return true; } @@ -72,17 +64,17 @@ bool RestrictionCollector::ParseFeatureId2OsmIdsMapping(string const & featureId if (!getline(featureId2OsmIdsStream, line)) return true; - istringstream lineStream(line); - vector<uint64_t> ids; - if (!ParseLineOfNumbers(lineStream, ids)) + vector<uint64_t> osmIds; + strings::SimpleTokenizer iter(line, ","); + if (!ParseLineOfNumbers(iter, osmIds)) return false; - if (ids.size() <= 1) + if (osmIds.size() < 2) return false; // Every line should contain at least feature id and osm id. - Restriction::FeatureId const featureId = static_cast<Restriction::FeatureId>(ids.front()); - ids.erase(ids.begin()); - AddFeatureId(featureId, ids); + uint32_t const featureId = static_cast<uint32_t>(osmIds.front()); + osmIds.erase(osmIds.begin()); + AddFeatureId(featureId, osmIds); } return true; } @@ -98,15 +90,15 @@ bool RestrictionCollector::ParseRestrictions(string const & restrictionPath) string line; if (!getline(restrictionsStream, line)) return true; - istringstream lineStream(line); - string typeStr; - getline(lineStream, typeStr, ','); + + strings::SimpleTokenizer iter(line, ","); Restriction::Type type; - if (!FromString(typeStr, type)) + if (!FromString(*iter, type)) return false; + ++iter; vector<uint64_t> osmIds; - if (!ParseLineOfNumbers(lineStream, osmIds)) + if (!ParseLineOfNumbers(iter, osmIds)) return false; AddRestriction(type, osmIds); @@ -116,7 +108,7 @@ bool RestrictionCollector::ParseRestrictions(string const & restrictionPath) void RestrictionCollector::ComposeRestrictions() { - // Going through all osm id saved in |m_restrictionIndex| (mentioned in restrictions). + // Going through all osm ids saved in |m_restrictionIndex| (mentioned in restrictions). size_t const numRestrictions = m_restrictions.size(); for (auto const & osmIdAndIndex : m_restrictionIndex) { @@ -138,7 +130,7 @@ void RestrictionCollector::ComposeRestrictions() if (distance(rangeId.first, rangeId.second) != 1) continue; // |osmId| mentioned in restrictions was included in more than one feature. - Restriction::FeatureId const & featureId = rangeId.first->second; + uint32_t const & featureId = rangeId.first->second; // Adding feature id to restriction coresponded to the osm id. restriction.m_links[index.m_linkNumber] = featureId; } @@ -163,8 +155,7 @@ void RestrictionCollector::AddRestriction(Restriction::Type type, vector<uint64_ m_restrictionIndex.emplace_back(osmIds[i], LinkIndex({restrictionCount, i})); } -void RestrictionCollector::AddFeatureId(Restriction::FeatureId featureId, - vector<uint64_t> const & osmIds) +void RestrictionCollector::AddFeatureId(uint32_t featureId, vector<uint64_t> const & osmIds) { // Note. One |featureId| could correspond to several osm ids. // but for road feature |featureId| corresponds exactly one osm id. diff --git a/generator/restriction_collector.hpp b/generator/restriction_collector.hpp index 9b1e984d1d..1d22c85e2d 100644 --- a/generator/restriction_collector.hpp +++ b/generator/restriction_collector.hpp @@ -83,7 +83,7 @@ private: /// \brief Adds feature id and corresponding vector of |osmIds| to |m_osmId2FeatureId|. /// \note One feature id (|featureId|) may correspond to several osm ids (|osmIds|). - void AddFeatureId(Restriction::FeatureId featureId, vector<uint64_t> const & osmIds); + void AddFeatureId(uint32_t featureId, vector<uint64_t> const & osmIds); /// \brief Adds a restriction (vector of osm id). /// \param type is a type of restriction @@ -95,7 +95,7 @@ private: RestrictionVec m_restrictions; vector<pair<uint64_t, LinkIndex>> m_restrictionIndex; - unordered_multimap<uint64_t, Restriction::FeatureId> m_osmIds2FeatureId; + unordered_multimap<uint64_t, uint32_t> m_osmIds2FeatureId; }; string ToString(Restriction::Type const & type); |