diff --git a/generator/routing_helpers.cpp b/generator/routing_helpers.cpp index 6e6d1cf983..62570d0823 100644 --- a/generator/routing_helpers.cpp +++ b/generator/routing_helpers.cpp @@ -41,14 +41,14 @@ bool ParseOsmIdToFeatureIdMapping(string const & osmIdsToFeatureIdPath, } bool ParseFeatureIdToOsmIdMapping(string const & osmIdsToFeatureIdPath, - map & featureIdToOsmId) + map & featureIdToOsmId) { featureIdToOsmId.clear(); bool idsAreOk = true; bool const readSuccess = ForEachRoadFromFile(osmIdsToFeatureIdPath, [&](uint32_t featureId, osm::Id osmId) { - auto const emplaced = featureIdToOsmId.emplace(featureId, osmId.OsmId()); + auto const emplaced = featureIdToOsmId.emplace(featureId, connector::OsmId(osmId.OsmId())); if (emplaced.second) return; diff --git a/generator/routing_helpers.hpp b/generator/routing_helpers.hpp index c9b5223a2e..1c02c4913a 100644 --- a/generator/routing_helpers.hpp +++ b/generator/routing_helpers.hpp @@ -4,6 +4,8 @@ #include "generator/road_access_generator.hpp" #include "generator/restriction_writer.hpp" +#include "routing/cross_mwm_ids.hpp" + #include #include #include @@ -31,5 +33,5 @@ void AddFeatureId(osm::Id osmId, uint32_t featureId, std::map bool ParseOsmIdToFeatureIdMapping(std::string const & osmIdsToFeatureIdPath, std::map & osmIdToFeatureId); bool ParseFeatureIdToOsmIdMapping(std::string const & osmIdsToFeatureIdPath, - std::map & featureIdToOsmId); + std::map & featureIdToOsmId); } // namespace routing diff --git a/generator/routing_index_generator.cpp b/generator/routing_index_generator.cpp index 4905c74e11..d3435042b9 100644 --- a/generator/routing_index_generator.cpp +++ b/generator/routing_index_generator.cpp @@ -233,7 +233,7 @@ void CalcCrossMwmTransitions( ("Can't parse feature id to osm id mapping. File:", mappingFile)); auto it = featureIdToOsmId.find(featureId); CHECK(it != featureIdToOsmId.end(), ("Can't find osm id for feature id", featureId)); - auto const crossMwmId = it->second; + auto const osmId = it->second; bool prevPointIn = m2::RegionsContain(borders, f.GetPoint(0)); @@ -246,7 +246,7 @@ void CalcCrossMwmTransitions( auto const segmentIdx = base::asserted_cast(i - 1); VehicleMask const oneWayMask = maskMaker.CalcOneWayMask(f); - transitions.emplace_back(crossMwmId, featureId, segmentIdx, roadMask, oneWayMask, currPointIn, + transitions.emplace_back(osmId, featureId, segmentIdx, roadMask, oneWayMask, currPointIn, f.GetPoint(i - 1), f.GetPoint(i)); prevPointIn = currPointIn; @@ -254,6 +254,7 @@ void CalcCrossMwmTransitions( }); } +/// \brief Fills |transitions| for transit id case. That means for VehicleType::Transit. void CalcCrossMwmTransitions(string const & mwmFile, string const & mappingFile, vector const & borders, string const & country, CountryParentNameGetterFn const & countryParentNameGetterFn, diff --git a/routing/cross_mwm_connector_serialization.hpp b/routing/cross_mwm_connector_serialization.hpp index ca83f3e4ea..362b6f86ad 100644 --- a/routing/cross_mwm_connector_serialization.hpp +++ b/routing/cross_mwm_connector_serialization.hpp @@ -56,7 +56,7 @@ public: template void WriteCrossMwmId(connector::OsmId const & id, uint8_t n, BitWriter & w) const { - w.WriteAtMost64Bits(id, n); + w.WriteAtMost64Bits(id.Get(), n); } template @@ -94,7 +94,7 @@ public: template void ReadCrossMwmId(uint8_t n, BitReader & reader, connector::OsmId & readed) { - readed = reader.ReadAtMost64Bits(n); + readed.Set(reader.ReadAtMost64Bits(n)); } template @@ -123,7 +123,7 @@ public: VehicleMask GetOneWayMask() const { return m_oneWayMask; } private: - CrossMwmId m_crossMwmId = 0; + CrossMwmId m_crossMwmId = CrossMwmId(); uint32_t m_featureId = 0; uint32_t m_segmentIdx = 0; m2::PointD m_backPoint = m2::PointD::Zero(); @@ -410,11 +410,11 @@ private: static uint32_t CalcBitsPerCrossMwmId( std::vector> const & transitions) { - connector::OsmId osmId = 0; + connector::OsmId osmId(0ULL); for (Transition const & transition : transitions) osmId = std::max(osmId, transition.GetCrossMwmId()); - return bits::NumUsedBits(osmId); + return bits::NumUsedBits(osmId.Get()); } static uint32_t CalcBitsPerCrossMwmId( diff --git a/routing/cross_mwm_ids.hpp b/routing/cross_mwm_ids.hpp index 6f6a716a64..853a0b083e 100644 --- a/routing/cross_mwm_ids.hpp +++ b/routing/cross_mwm_ids.hpp @@ -2,6 +2,7 @@ #include "routing_common/transit_types.hpp" +#include "base/newtype.hpp" #include "base/visitor.hpp" #include @@ -12,7 +13,8 @@ namespace connector { // Identifier to find a border edge in neighbouring mwm while cross mwm transition // for pedestrian, bicycle and car routing. -using OsmId = uint64_t; +NEWTYPE(uint64_t, OsmId); +NEWTYPE_SIMPLE_OUTPUT(OsmId); // Identifier to find a border edge in neighbouring mwm while cross mwm transition // for transit routing. @@ -50,7 +52,7 @@ struct HashKey { size_t operator()(OsmId const & key) const { - return std::hash()(key); + return std::hash()(key.Get()); } size_t operator()(TransitId const & key) const diff --git a/routing/routing_tests/cross_mwm_connector_test.cpp b/routing/routing_tests/cross_mwm_connector_test.cpp index cbea901f8c..74190aeba1 100644 --- a/routing/routing_tests/cross_mwm_connector_test.cpp +++ b/routing/routing_tests/cross_mwm_connector_test.cpp @@ -43,7 +43,7 @@ namespace routing_test { UNIT_TEST(OneWayEnter) { - OsmId constexpr osmId = 1; + OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; CrossMwmConnector connector(mwmId); @@ -69,7 +69,7 @@ UNIT_TEST(OneWayEnter) UNIT_TEST(OneWayExit) { - OsmId constexpr osmId = 1; + OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; CrossMwmConnector connector(mwmId); @@ -95,7 +95,7 @@ UNIT_TEST(OneWayExit) UNIT_TEST(TwoWayEnter) { - OsmId constexpr osmId = 1; + OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; CrossMwmConnector connector(mwmId); @@ -121,7 +121,7 @@ UNIT_TEST(TwoWayEnter) UNIT_TEST(TwoWayExit) { - OsmId constexpr osmId = 1; + OsmId constexpr osmId(1ULL); uint32_t constexpr featureId = 1; uint32_t constexpr segmentIdx = 1; CrossMwmConnector connector(mwmId); @@ -153,9 +153,9 @@ UNIT_TEST(Serialization) { vector> transitions = { /* osmId featureId, segmentIdx, roadMask, oneWayMask, forwardIsEnter, backPoint, frontPoint */ - {100, 10, 1, kCarMask, kCarMask, true, m2::PointD(1.1, 1.2), m2::PointD(1.3, 1.4)}, - {200, 20, 2, kCarMask, 0, true, m2::PointD(2.1, 2.2), m2::PointD(2.3, 2.4)}, - {300, 30, 3, kPedestrianMask, kCarMask, true, m2::PointD(3.1, 3.2), m2::PointD(3.3, 3.4)}}; + {OsmId(100ULL), 10, 1, kCarMask, kCarMask, true, m2::PointD(1.1, 1.2), m2::PointD(1.3, 1.4)}, + {OsmId(200ULL), 20, 2, kCarMask, 0, true, m2::PointD(2.1, 2.2), m2::PointD(2.3, 2.4)}, + {OsmId(300ULL), 30, 3, kPedestrianMask, kCarMask, true, m2::PointD(3.1, 3.2), m2::PointD(3.3, 3.4)}}; CrossMwmConnectorPerVehicleType connectors; CrossMwmConnector & carConnector = connectors[static_cast(VehicleType::Car)]; @@ -261,7 +261,7 @@ UNIT_TEST(WeightsSerialization) for (uint32_t featureId = 0; featureId < kNumTransitions; ++featureId) { auto const osmId = static_cast(featureId * 10); - transitions.emplace_back(osmId, featureId, 1 /* segmentIdx */, kCarMask, 0 /* oneWayMask */, + transitions.emplace_back(connector::OsmId(osmId), featureId, 1 /* segmentIdx */, kCarMask, 0 /* oneWayMask */, true /* forwardIsEnter */, m2::PointD::Zero(), m2::PointD::Zero()); }