From 10283fd2d86fbb1a085cd88d22fa5b12a4e723ad Mon Sep 17 00:00:00 2001 From: gmoryes Date: Wed, 26 Feb 2020 12:37:53 +0300 Subject: [PATCH] [routing] review fixes --- routing/index_graph.hpp | 5 +---- routing/index_graph_loader.cpp | 8 +------- routing/road_access.cpp | 11 +++++++++++ routing/road_access.hpp | 11 ++++++----- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/routing/index_graph.hpp b/routing/index_graph.hpp index 99dc19b2b8..59ea61d9d1 100644 --- a/routing/index_graph.hpp +++ b/routing/index_graph.hpp @@ -17,13 +17,11 @@ #include "geometry/point2d.hpp" -#include #include #include #include #include #include -#include #include namespace routing @@ -187,8 +185,7 @@ private: RoutingOptions m_avoidRoutingOptions; std::function m_currentTimeGetter = []() { - using system_clock = std::chrono::system_clock; - return system_clock::to_time_t(system_clock::now()); + return GetCurrentTimestamp(); }; }; diff --git a/routing/index_graph_loader.cpp b/routing/index_graph_loader.cpp index fd1c251c89..f96d784e78 100644 --- a/routing/index_graph_loader.cpp +++ b/routing/index_graph_loader.cpp @@ -2,8 +2,8 @@ #include "routing/city_roads.hpp" #include "routing/index_graph_serialization.hpp" -#include "routing/maxspeeds.hpp" #include "routing/restriction_loader.hpp" +#include "routing/road_access.hpp" #include "routing/road_access_serialization.hpp" #include "routing/route.hpp" #include "routing/routing_exceptions.hpp" @@ -26,12 +26,6 @@ namespace using namespace routing; using namespace std; -time_t GetCurrentTimestamp() -{ - using system_clock = std::chrono::system_clock; - return system_clock::to_time_t(system_clock::now()); -} - class IndexGraphLoaderImpl final : public IndexGraphLoader { public: diff --git a/routing/road_access.cpp b/routing/road_access.cpp index b7d69c515a..5c13428850 100644 --- a/routing/road_access.cpp +++ b/routing/road_access.cpp @@ -3,6 +3,7 @@ #include "base/assert.hpp" #include +#include #include using namespace std; @@ -32,6 +33,10 @@ void PrintKV(ostringstream & oss, KV const & kvs, size_t maxKVToShow) namespace routing { // RoadAccess -------------------------------------------------------------------------------------- +RoadAccess::RoadAccess() : m_currentTimeGetter([](){ return GetCurrentTimestamp(); }) +{ +} + RoadAccess::Type RoadAccess::GetAccess(uint32_t featureId) const { // todo(@m) This may or may not be too slow. Consider profiling this and using @@ -60,6 +65,12 @@ bool RoadAccess::operator==(RoadAccess const & rhs) const } // Functions --------------------------------------------------------------------------------------- +time_t GetCurrentTimestamp() +{ + using system_clock = std::chrono::system_clock; + return system_clock::to_time_t(system_clock::now()); +} + string ToString(RoadAccess::Type type) { if (type <= RoadAccess::Type::Count) diff --git a/routing/road_access.hpp b/routing/road_access.hpp index 004326bd9e..33fda17b7b 100644 --- a/routing/road_access.hpp +++ b/routing/road_access.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include "3party/skarupke/flat_hash_map.hpp" #include "3party/opening_hours/opening_hours.hpp" @@ -87,8 +86,11 @@ public: using WayToAccessConditional = ska::flat_hash_map; using PointToAccessConditional = ska::flat_hash_map; + RoadAccess(); + WayToAccess const & GetWayToAccess() const { return m_wayToAccess; } PointToAccess const & GetPointToAccess() const { return m_pointToAccess; } + WayToAccessConditional const & GetWayToAccessConditional() const { return m_wayToAccessConditional; @@ -129,10 +131,7 @@ public: void SetCurrentTimeGetter(T && getter) { m_currentTimeGetter = std::forward(getter); } private: - std::function m_currentTimeGetter = []() { - using system_clock = std::chrono::system_clock; - return system_clock::to_time_t(system_clock::now()); - }; + std::function m_currentTimeGetter; // If segmentIdx of a key in this map is 0, it means the // entire feature has the corresponding access type. // Otherwise, the information is about the segment with number (segmentIdx-1). @@ -142,6 +141,8 @@ private: PointToAccessConditional m_pointToAccessConditional; }; +time_t GetCurrentTimestamp(); + std::string ToString(RoadAccess::Type type); void FromString(std::string const & s, RoadAccess::Type & result);