diff --git a/map/transit/transit_display.cpp b/map/transit/transit_display.cpp index 4eaf5baea5..53ee832366 100644 --- a/map/transit/transit_display.cpp +++ b/map/transit/transit_display.cpp @@ -199,8 +199,7 @@ void TransitRouteDisplay::ProcessSubroute(vector const & segments, CollectTransitDisplayInfo(segments, transitDisplayInfos); // Read transit display info. - if (!m_transitReadManager.GetTransitDisplayInfo(transitDisplayInfos)) - return; + m_transitReadManager.GetTransitDisplayInfo(transitDisplayInfos); std::vector transitMarks; diff --git a/map/transit/transit_reader.cpp b/map/transit/transit_reader.cpp index aa351a29fc..e350ef758a 100644 --- a/map/transit/transit_reader.cpp +++ b/map/transit/transit_reader.cpp @@ -6,6 +6,8 @@ #include "indexer/drules_include.hpp" #include "indexer/feature_algo.hpp" +#include "coding/reader.hpp" + #include "drape_frontend/stylist.hpp" #include "base/stl_add.hpp" @@ -13,31 +15,8 @@ using namespace routing; using namespace std; -// TransitReader ---------------------------------------------------------------------------------- -bool TransitReader::Init(MwmSet::MwmId const & mwmId) -{ - MwmSet::MwmHandle handle = m_index.GetMwmHandleById(mwmId); - if (!handle.IsAlive()) - { - LOG(LWARNING, ("Can't get mwm handle for", mwmId)); - return false; - } - MwmValue const & mwmValue = *handle.GetValue(); - if (!mwmValue.m_cont.IsExist(TRANSIT_FILE_TAG)) - return false; - - m_reader = my::make_unique(mwmValue.m_cont.GetReader(TRANSIT_FILE_TAG)); - return IsValid(); -} - -Reader & TransitReader::GetReader() -{ - CHECK(IsValid(), ()); - return *m_reader->GetPtr(); -} - // ReadTransitTask -------------------------------------------------------------------------------- -bool ReadTransitTask::Init(uint64_t id, MwmSet::MwmId const & mwmId, unique_ptr && transitInfo) +void ReadTransitTask::Init(uint64_t id, MwmSet::MwmId const & mwmId, unique_ptr && transitInfo) { m_id = id; m_mwmId = mwmId; @@ -51,16 +30,26 @@ bool ReadTransitTask::Init(uint64_t id, MwmSet::MwmId const & mwmId, unique_ptr< m_loadSubset = true; m_transitInfo = move(transitInfo); } - return m_transitReader.Init(mwmId); } void ReadTransitTask::Do() { - if (!m_transitReader.IsValid()) + MwmSet::MwmHandle handle = m_index.GetMwmHandleById(m_mwmId); + if (!handle.IsAlive()) + { + LOG(LWARNING, ("Can't get mwm handle for", m_mwmId)); + return; + } + MwmValue const & mwmValue = *handle.GetValue(); + if (!mwmValue.m_cont.IsExist(TRANSIT_FILE_TAG)) return; + auto reader = my::make_unique(mwmValue.m_cont.GetReader(TRANSIT_FILE_TAG)); + CHECK(reader, ()); + CHECK(reader->GetPtr() != nullptr, ()); + transit::GraphData graphData; - graphData.DeserializeForRendering(m_transitReader.GetReader()); + graphData.DeserializeForRendering(*reader->GetPtr()); FillItemsByIdMap(graphData.GetStops(), m_transitInfo->m_stops); for (auto const & stop : m_transitInfo->m_stops) @@ -145,7 +134,7 @@ void TransitReadManager::Stop() m_threadsPool.reset(); } -bool TransitReadManager::GetTransitDisplayInfo(TransitDisplayInfos & transitDisplayInfos) +void TransitReadManager::GetTransitDisplayInfo(TransitDisplayInfos & transitDisplayInfos) { unique_lock lock(m_mutex); auto const groupId = ++m_nextTasksGroupId; @@ -156,11 +145,7 @@ bool TransitReadManager::GetTransitDisplayInfo(TransitDisplayInfos & transitDisp { auto const & mwmId = mwmTransitPair.first; auto task = my::make_unique(m_index, m_readFeaturesFn); - if (!task->Init(groupId, mwmId, move(mwmTransitPair.second))) - { - LOG(LWARNING, ("Getting transit info failed for", mwmId)); - return false; - } + task->Init(groupId, mwmId, move(mwmTransitPair.second)); transitTasks[mwmId] = move(task); } @@ -178,7 +163,6 @@ bool TransitReadManager::GetTransitDisplayInfo(TransitDisplayInfos & transitDisp for (auto const & transitTask : transitTasks) transitDisplayInfos[transitTask.first] = transitTask.second->GetTransitInfo(); - return true; } void TransitReadManager::OnTaskCompleted(threads::IRoutine * task) diff --git a/map/transit/transit_reader.hpp b/map/transit/transit_reader.hpp index 0db8fb0ed2..8c38cf336a 100644 --- a/map/transit/transit_reader.hpp +++ b/map/transit/transit_reader.hpp @@ -5,8 +5,6 @@ #include "indexer/feature_decl.hpp" #include "indexer/index.hpp" -#include "coding/reader.hpp" - #include "base/thread.hpp" #include "base/thread_pool.hpp" @@ -18,21 +16,6 @@ #include #include -class TransitReader -{ -public: - TransitReader(Index & index) : m_index(index) {} - - bool Init(MwmSet::MwmId const & mwmId); - bool IsValid() const { return m_reader != nullptr; } - /// \note This method should be used only if IsValid() returns true. - Reader & GetReader(); - -private: - Index & m_index; - std::unique_ptr m_reader; -}; - struct TransitFeatureInfo { bool m_isGate = false; @@ -67,10 +50,10 @@ class ReadTransitTask: public threads::IRoutine public: ReadTransitTask(Index & index, TReadFeaturesFn const & readFeaturesFn) - : m_transitReader(index), m_readFeaturesFn(readFeaturesFn) + : m_index(index), m_readFeaturesFn(readFeaturesFn) {} - bool Init(uint64_t id, MwmSet::MwmId const & mwmId, std::unique_ptr && transitInfo = nullptr); + void Init(uint64_t id, MwmSet::MwmId const & mwmId, std::unique_ptr && transitInfo = nullptr); uint64_t GetId() const { return m_id; } void Do() override; @@ -97,7 +80,7 @@ private: } }; - TransitReader m_transitReader; + Index & m_index; TReadFeaturesFn m_readFeaturesFn; uint64_t m_id = 0; @@ -118,7 +101,7 @@ public: void Start(); void Stop(); - bool GetTransitDisplayInfo(TransitDisplayInfos & transitDisplayInfos); + void GetTransitDisplayInfo(TransitDisplayInfos & transitDisplayInfos); // TODO(@darina) Clear cache for deleted mwm. //void OnMwmDeregistered(MwmSet::MwmId const & mwmId); diff --git a/routing/transit_graph.cpp b/routing/transit_graph.cpp index 944fa56818..1479e4a28f 100644 --- a/routing/transit_graph.cpp +++ b/routing/transit_graph.cpp @@ -3,8 +3,6 @@ #include "routing/fake_feature_ids.hpp" #include "routing/index_graph.hpp" -#include "routing_common/transit_graph_data.hpp" - #include "indexer/feature_altitude.hpp" namespace routing diff --git a/routing/transit_graph_loader.cpp b/routing/transit_graph_loader.cpp index aa9914873c..5f237e798d 100644 --- a/routing/transit_graph_loader.cpp +++ b/routing/transit_graph_loader.cpp @@ -3,6 +3,7 @@ #include "routing/fake_ending.hpp" #include "routing/routing_exceptions.hpp" +#include "routing_common/transit_graph_data.hpp" #include "routing_common/transit_serdes.hpp" #include "routing_common/transit_types.hpp"