From f149ee439347f649630a419a70bf1cc9f48c9f72 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Fri, 13 Oct 2017 13:54:53 +0300 Subject: [PATCH] Review fixes. --- generator/routing_generator.cpp | 18 +++++++++--------- generator/transit_generator.cpp | 19 +++++++++---------- generator/transit_generator.hpp | 2 +- generator/utils.cpp | 2 +- generator/utils.hpp | 2 ++ routing/index_router.cpp | 4 ++-- routing/index_router.hpp | 6 +++--- routing_common/transit_types.hpp | 31 ++++++++++++------------------- 8 files changed, 39 insertions(+), 45 deletions(-) diff --git a/generator/routing_generator.cpp b/generator/routing_generator.cpp index 26c80bc152..2bfb24c586 100644 --- a/generator/routing_generator.cpp +++ b/generator/routing_generator.cpp @@ -254,12 +254,12 @@ void BuildCrossRoutingIndex(std::string const & baseDir, std::string const & cou LOG(LINFO, ("Cross mwm routing section builder")); classificator::Load(); - SingleMwmIndex singleIndex(my::JoinFoldersToPath(baseDir, countryName + DATA_FILE_EXTENSION)); + SingleMwmIndex index(my::JoinFoldersToPath(baseDir, countryName + DATA_FILE_EXTENSION)); LOG(LINFO, ("Loading indexes...")); osrm::NodeDataVectorT nodeData; gen::OsmID2FeatureID osm2ft; - if (!LoadIndexes(singleIndex.GetPath(MapOptions::Map), osrmFile, nodeData, osm2ft)) + if (!LoadIndexes(index.GetPath(MapOptions::Map), osrmFile, nodeData, osm2ft)) return; LOG(LINFO, ("Loading countries borders...")); @@ -269,10 +269,10 @@ void BuildCrossRoutingIndex(std::string const & baseDir, std::string const & cou LOG(LINFO, ("Finding cross nodes...")); routing::CrossRoutingContextWriter crossContext; - FindCrossNodes(nodeData, osm2ft, countries, countryName, singleIndex.GetIndex(), - singleIndex.GetMwmId(), crossContext); + FindCrossNodes(nodeData, osm2ft, countries, countryName, index.GetIndex(), + index.GetMwmId(), crossContext); - std::string const mwmPath = singleIndex.GetPath(MapOptions::Map); + std::string const mwmPath = index.GetPath(MapOptions::Map); CalculateCrossAdjacency(mwmPath, crossContext); WriteCrossSection(crossContext, mwmPath); } @@ -282,11 +282,11 @@ void BuildRoutingIndex(std::string const & baseDir, std::string const & countryN classificator::Load(); // Correct mwm version doesn't matter here - we just need access to mwm files via Index. - SingleMwmIndex singleIndex(my::JoinFoldersToPath(baseDir, countryName + DATA_FILE_EXTENSION)); + SingleMwmIndex index(my::JoinFoldersToPath(baseDir, countryName + DATA_FILE_EXTENSION)); osrm::NodeDataVectorT nodeData; gen::OsmID2FeatureID osm2ft; - if (!LoadIndexes(singleIndex.GetPath(MapOptions::Map), osrmFile, nodeData, osm2ft)) + if (!LoadIndexes(index.GetPath(MapOptions::Map), osrmFile, nodeData, osm2ft)) return; OsrmFtSegMappingBuilder mapping; @@ -315,7 +315,7 @@ void BuildRoutingIndex(std::string const & baseDir, std::string const & countryN } FeatureType ft; - Index::FeaturesLoaderGuard loader(singleIndex.GetIndex(), singleIndex.GetMwmId()); + Index::FeaturesLoaderGuard loader(index.GetIndex(), index.GetMwmId()); if (!loader.GetFeatureByIndex(fID, ft)) { LOG(LWARNING, ("Can't read feature with id:", fID, "for way:", seg.wayId)); @@ -445,7 +445,7 @@ void BuildRoutingIndex(std::string const & baseDir, std::string const & countryN LOG(LINFO, ("Collect all data into one file...")); - std::string const mwmPath = singleIndex.GetPath(MapOptions::Map); + std::string const mwmPath = index.GetPath(MapOptions::Map); std::string const mwmWithoutRoutingPath = mwmPath + NOROUTING_FILE_EXTENSION; // Backup mwm file without routing. diff --git a/generator/transit_generator.cpp b/generator/transit_generator.cpp index 1e81b4eac6..4d439959d5 100644 --- a/generator/transit_generator.cpp +++ b/generator/transit_generator.cpp @@ -75,7 +75,7 @@ void DeserializeGatesFromJson(my::Json const & root, string const & mwmDir, stri DeserializeFromJson(root, "gates", gates); // Creating IndexRouter. - SingleMwmIndex singleIndex(my::JoinFoldersToPath(mwmDir, countryId + DATA_FILE_EXTENSION)); + SingleMwmIndex index(my::JoinFoldersToPath(mwmDir, countryId + DATA_FILE_EXTENSION)); auto infoGetter = storage::CountryInfoReader::CreateCountryInfoReader(GetPlatform()); CHECK(infoGetter, ()); @@ -89,15 +89,15 @@ void DeserializeGatesFromJson(my::Json const & root, string const & mwmDir, stri return infoGetter->GetLimitRectForLeaf(c); }; - CHECK_EQUAL(singleIndex.GetMwmId().GetInfo()->GetType(), MwmInfo::COUNTRY, ()); + CHECK_EQUAL(index.GetMwmId().GetInfo()->GetType(), MwmInfo::COUNTRY, ()); auto numMwmIds = make_shared(); numMwmIds->RegisterFile(CountryFile(countryId)); - // Note. |indexRouter| is valid until |index| is valid. + // Note. |indexRouter| is valid while |index| is valid. IndexRouter indexRouter(VehicleType::Pedestrian, false /* load altitudes */, CountryParentNameGetterFn(), countryFileGetter, getMwmRectByName, numMwmIds, MakeNumMwmTree(*numMwmIds, *infoGetter), - traffic::TrafficCache(), singleIndex.GetIndex()); + traffic::TrafficCache(), index.GetIndex()); // Looking for the best segment for every gate. for (auto & gate : gates) @@ -108,20 +108,19 @@ void DeserializeGatesFromJson(my::Json const & root, string const & mwmDir, stri Segment bestSegment; try { - if (indexRouter.FindBestSegmentAtSingleMwm(gate.GetPoint(), + if (indexRouter.FindBestSegmentInSingleMwm(gate.GetPoint(), m2::PointD::Zero() /* direction */, true /* isOutgoing */, bestSegment)) { - CHECK_EQUAL(bestSegment.GetMwmId(), 0, - ("Best segment num mwm id ==", bestSegment.GetMwmId(), ", but should be zero")); + CHECK_EQUAL(bestSegment.GetMwmId(), 0, ()); gate.SetBestPedestrianSegment(SingleMwmSegment( bestSegment.GetFeatureId(), bestSegment.GetSegmentIdx(), bestSegment.IsForward())); } } catch (RootException const & e) { - LOG(LDEBUG, ("Point of a gate belongs to several mwm or doesn't belong any mwm. gate:", gate, - e.what(), e.Msg())); + LOG(LDEBUG, ("Point of a gate belongs to several mwms or doesn't belong to any mwm. Gate:", + gate, e.what())); } } } @@ -197,7 +196,7 @@ void BuildTransit(string const & mwmPath, string const & transitDir) my::Json root(jsonBuffer.c_str()); CHECK(root.get() != nullptr, ("Cannot parse the json file:", graphFullPath)); - // Note. |gates| has to be deserialized from json before to start writing transit section to mwm since + // Note. |gates| has to be deserialized from json before starting writing transit section to mwm since // the mwm is used to filled |gates|. vector gates; DeserializeGatesFromJson(root, my::GetDirectory(mwmPath), countryId, gates); diff --git a/generator/transit_generator.hpp b/generator/transit_generator.hpp index 85cc7f0b80..06d45a3ab8 100644 --- a/generator/transit_generator.hpp +++ b/generator/transit_generator.hpp @@ -85,7 +85,7 @@ private: /// \param transitDir a path to directory with json files with transit graphs. /// \note An mwm pointed by |mwmPath| should contain: /// * feature geometry -/// * index graph (ROUTING_FILE_TAG) and restriction sections (RESTRICTIONS_FILE_TAG) +/// * index graph (ROUTING_FILE_TAG) void BuildTransit(std::string const & mwmPath, std::string const & transitDir); } // namespace transit } // namespace routing diff --git a/generator/utils.cpp b/generator/utils.cpp index 59e1441fcd..0634d03245 100644 --- a/generator/utils.cpp +++ b/generator/utils.cpp @@ -16,7 +16,7 @@ SingleMwmIndex::SingleMwmIndex(std::string const & mwmPath) m_countryFile.SyncWithDisk(); CHECK_EQUAL( m_countryFile.GetFiles(), MapOptions::MapWithCarRouting, - ("No correct mwm corresponding local country file:", m_countryFile, ". Path:", mwmPath)); + ("No correct mwm corresponding to local country file:", m_countryFile, ". Path:", mwmPath)); auto const result = m_index.Register(m_countryFile); CHECK_EQUAL(result.second, MwmSet::RegResult::Success, ()); diff --git a/generator/utils.hpp b/generator/utils.hpp index 51aab679b9..1fb454bf2f 100644 --- a/generator/utils.hpp +++ b/generator/utils.hpp @@ -18,9 +18,11 @@ namespace generator { +/// \brief This class is wrapper around |Index| if only one mwm is registered in Index. class SingleMwmIndex { public: + /// \param mwmPath is a path to mwm which should be registerd in Index. explicit SingleMwmIndex(std::string const & mwmPath); Index & GetIndex() { return m_index; } diff --git a/routing/index_router.cpp b/routing/index_router.cpp index cc2bd462c3..763ea8fd18 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -315,8 +315,8 @@ IndexRouter::IndexRouter(VehicleType vehicleType, bool loadAltitudes, CHECK(m_directionsEngine, ()); } -bool IndexRouter::FindBestSegmentAtSingleMwm(m2::PointD const & point, m2::PointD const & direction, - bool isOutgoing, Segment & bestSegment) +bool IndexRouter::FindBestSegmentInSingleMwm(m2::PointD const &point, m2::PointD const &direction, + bool isOutgoing, Segment &bestSegment) { auto worldGraph = MakeWorldGraph(); worldGraph->SetMode(WorldGraph::Mode::SingleMwm); diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 9d5f5bc101..3eb579a52c 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -63,8 +63,8 @@ public: shared_ptr numMwmIds, unique_ptr> numMwmTree, traffic::TrafficCache const & trafficCache, Index & index); - bool FindBestSegmentAtSingleMwm(m2::PointD const & point, m2::PointD const & direction, - bool isOutgoing, Segment & bestSegment); + bool FindBestSegmentInSingleMwm(m2::PointD const &point, m2::PointD const &direction, + bool isOutgoing, Segment &bestSegment); // IRouter overrides: std::string GetName() const override { return m_name; } @@ -89,7 +89,7 @@ private: /// \brief Finds the best segment (edge) which may be considered as the start of the finish of the route. /// According to current implementation if a segment is near |point| and is almost codirectional - /// to |direction|, the segment will be better than others. If there's no an almost codirectional + /// to |direction|, the segment will be better than others. If there's no almost codirectional /// segment in the neighbourhood then the closest segment to |point| will be chosen. /// \param isOutgoing == true if |point| is considered as the start of the route. /// isOutgoing == false if |point| is considered as the finish of the route. diff --git a/routing_common/transit_types.hpp b/routing_common/transit_types.hpp index 22f61dd9ce..2d2d8fc215 100644 --- a/routing_common/transit_types.hpp +++ b/routing_common/transit_types.hpp @@ -31,7 +31,7 @@ ShapeId constexpr kInvalidShapeId = std::numeric_limits::max(); // To convert double to uint32_t at better accuracy |kInvalidWeight| should be close to real weight. Weight constexpr kInvalidWeight = -1.0; -#define TRANSIT_TYPE_FRIENDS \ +#define DECLARE_TRANSIT_TYPE_FRIENDS \ template friend class Serializer; \ template friend class Deserializer; \ friend class DeserializerFromJson; \ @@ -41,8 +41,6 @@ Weight constexpr kInvalidWeight = -1.0; struct TransitHeader { - TRANSIT_TYPE_FRIENDS - TransitHeader() { Reset(); } TransitHeader(uint16_t version, uint32_t gatesOffset, uint32_t edgesOffset, uint32_t transfersOffset, uint32_t linesOffset, uint32_t shapesOffset, @@ -51,6 +49,7 @@ struct TransitHeader bool IsEqualForTesting(TransitHeader const & header) const; private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT( TransitHeader, visitor(m_version, "version"), visitor(m_reserve, "reserve"), visitor(m_gatesOffset, "gatesOffset"), visitor(m_edgesOffset, "edgesOffset"), @@ -74,8 +73,6 @@ static_assert(sizeof(TransitHeader) == 32, "Wrong header size of transit section class Stop { - TRANSIT_TYPE_FRIENDS - public: Stop() = default; Stop(StopId id, FeatureId featureId, TransferId transferId, std::vector const & lineIds, @@ -89,6 +86,7 @@ public: m2::PointD const & GetPoint() const { return m_point; } private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(Stop, visitor(m_id, "id"), visitor(m_featureId, "osm_id"), visitor(m_transferId, "transfer_id"), visitor(m_lineIds, "line_ids"), visitor(m_point, "point")) @@ -104,8 +102,6 @@ private: class SingleMwmSegment { - TRANSIT_TYPE_FRIENDS - public: SingleMwmSegment() = default; SingleMwmSegment(FeatureId featureId, uint32_t segmentIdx, bool forward); @@ -115,6 +111,7 @@ public: bool GetForward() const { return m_forward; } private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(SingleMwmSegment, visitor(m_featureId, "feature_id"), visitor(m_segmentIdx, "segment_idx"), visitor(m_forward, "forward")) @@ -126,8 +123,6 @@ private: class Gate { - TRANSIT_TYPE_FRIENDS - public: Gate() = default; Gate(FeatureId featureId, bool entrance, bool exit, double weight, std::vector const & stopIds, @@ -144,6 +139,7 @@ public: m2::PointD const & GetPoint() const { return m_point; } private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(Gate, visitor(m_featureId, "osm_id"), visitor(m_bestPedestrianSegment, "best_pedestrian_segment"), visitor(m_entrance, "entrance"), visitor(m_exit, "exit"), @@ -163,8 +159,6 @@ private: class Edge { - TRANSIT_TYPE_FRIENDS - public: Edge() = default; Edge(StopId startStopId, StopId finishStopId, double weight, LineId lineId, bool transfer, @@ -181,6 +175,7 @@ public: bool operator<(Edge const & rhs) const; private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(Edge, visitor(m_startStopId, "start_stop_id"), visitor(m_finishStopId, "finish_stop_id"), visitor(m_weight, "weight"), visitor(m_lineId, "line_id"), @@ -196,8 +191,6 @@ private: class Transfer { - TRANSIT_TYPE_FRIENDS - public: Transfer() = default; Transfer(StopId id, m2::PointD const & point, std::vector const & stopIds); @@ -208,6 +201,7 @@ public: std::vector const & GetStopIds() const { return m_stopIds; } private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(Transfer, visitor(m_id, "id"), visitor(m_point, "point"), visitor(m_stopIds, "stop_ids")) @@ -221,8 +215,6 @@ private: class Line { - TRANSIT_TYPE_FRIENDS - public: Line() = default; Line(LineId id, std::string const & number, std::string const & title, std::string const & type, @@ -237,6 +229,7 @@ public: std::vector const & GetStopIds() const { return m_stopIds; } private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(Line, visitor(m_id, "id"), visitor(m_number, "number"), visitor(m_title, "title"), visitor(m_type, "type"), visitor(m_networkId, "network_id"), @@ -252,8 +245,6 @@ private: class Shape { - TRANSIT_TYPE_FRIENDS - public: Shape() = default; Shape(ShapeId id, StopId stop1_id, StopId stop2_id, std::vector const & polyline); @@ -265,6 +256,7 @@ public: std::vector const & GetPolyline() const { return m_polyline; } private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(Shape, visitor(m_id, "id"), visitor(m_stop1_id, "stop1_id"), visitor(m_stop2_id, "stop2_id"), visitor(m_polyline, "polyline")) @@ -276,8 +268,6 @@ private: class Network { - TRANSIT_TYPE_FRIENDS - public: Network() = default; Network(NetworkId id, std::string const & title); @@ -287,10 +277,13 @@ public: std::string const & GetTitle() const { return m_title; } private: + DECLARE_TRANSIT_TYPE_FRIENDS DECLARE_VISITOR_AND_DEBUG_PRINT(Network, visitor(m_id, "id"), visitor(m_title, "title")) NetworkId m_id; std::string m_title; }; + +#undef DECLARE_TRANSIT_TYPE_FRIENDS } // namespace transit } // namespace routing