Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/3party
diff options
context:
space:
mode:
authorLev Dragunov <l.dragunov@corp.mail.ru>2015-12-17 19:28:59 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:16:13 +0300
commit9b42eed7cc8160ab2224df12213f8bb9d41a69d1 (patch)
tree6928058662da4efa984f562c9e35c29f1bce94fb /3party
parent71bf45d883912386890de5a3e86710ea21191eab (diff)
OSRM plugin review fixes.
Diffstat (limited to '3party')
-rw-r--r--3party/osrm/osrm-backend/plugins/WayIdPlugin.hpp217
1 files changed, 108 insertions, 109 deletions
diff --git a/3party/osrm/osrm-backend/plugins/WayIdPlugin.hpp b/3party/osrm/osrm-backend/plugins/WayIdPlugin.hpp
index dba6bf23c0..acebfd9254 100644
--- a/3party/osrm/osrm-backend/plugins/WayIdPlugin.hpp
+++ b/3party/osrm/osrm-backend/plugins/WayIdPlugin.hpp
@@ -21,138 +21,137 @@
#include <unordered_map>
#include <vector>
-template <class DataFacadeT> class WayIdPlugin final : public BasePlugin
+template <class DataFacadeT>
+class WayIdPlugin final : public BasePlugin
{
public:
- explicit WayIdPlugin(DataFacadeT *facade, std::string const & nodeDataFile)
- : m_descriptorString("wayid"), m_facade(facade)
- {
+ WayIdPlugin(DataFacadeT * facade, std::string const & nodeDataFile)
+ : m_descriptorString("wayid"), m_facade(facade)
+ {
#ifndef MT_STRUCTURES
- SimpleLogger().Write(logWARNING) << "Multitreaded storage was not set on compile time!!! Do not use osrm-routed in several threads."
+ SimpleLogger().Write(logWARNING) << "Multitreaded storage was not set on compile time!!! Do "
+ "not use osrm-routed in several threads."
#endif
if (!osrm::LoadNodeDataFromFile(nodeDataFile, m_nodeData))
- {
- SimpleLogger().Write(logDEBUG) << "Can't load node data";
- return;
- }
- m_searchEngine = osrm::make_unique<SearchEngine<DataFacadeT>>(facade);
+ {
+ SimpleLogger().Write(logDEBUG) << "Can't load node data";
+ return;
+ }
+ m_searchEngine = osrm::make_unique<SearchEngine<DataFacadeT>>(facade);
+ }
+
+ const std::string GetDescriptor() const override final { return m_descriptorString; }
+ int HandleRequest(const RouteParameters & route_parameters,
+ osrm::json::Object & reply) override final
+ {
+ // We process only two points case
+ if (route_parameters.coordinates.size() != 2)
+ return 400;
+
+ if (!check_all_coordinates(route_parameters.coordinates))
+ {
+ return 400;
}
- virtual ~WayIdPlugin() {}
-
- const std::string GetDescriptor() const override final { return m_descriptorString; }
+ std::vector<phantom_node_pair> phantom_node_pair_list(route_parameters.coordinates.size());
- int HandleRequest(const RouteParameters &route_parameters, osrm::json::Object &reply) override final
+ for (const auto i : osrm::irange<std::size_t>(0, route_parameters.coordinates.size()))
{
- //We process only two points case
- if (route_parameters.coordinates.size() != 2)
- return 400;
-
- if (!check_all_coordinates(route_parameters.coordinates))
+ std::vector<PhantomNode> phantom_node_vector;
+ // FixedPointCoordinate &coordinate = route_parameters.coordinates[i];
+ if (m_facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates[i],
+ phantom_node_vector, 1))
+ {
+ BOOST_ASSERT(!phantom_node_vector.empty());
+ phantom_node_pair_list[i].first = phantom_node_vector.front();
+ if (phantom_node_vector.size() > 1)
{
- return 400;
+ phantom_node_pair_list[i].second = phantom_node_vector.back();
}
+ }
+ }
- std::vector<phantom_node_pair> phantom_node_pair_list(route_parameters.coordinates.size());
-
- for (const auto i : osrm::irange<std::size_t>(0, route_parameters.coordinates.size()))
- {
- std::vector<PhantomNode> phantom_node_vector;
- //FixedPointCoordinate &coordinate = route_parameters.coordinates[i];
- if (m_facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates[i],
- phantom_node_vector, 1))
- {
- BOOST_ASSERT(!phantom_node_vector.empty());
- phantom_node_pair_list[i].first = phantom_node_vector.front();
- if (phantom_node_vector.size() > 1)
- {
- phantom_node_pair_list[i].second = phantom_node_vector.back();
- }
- }
- }
+ auto check_component_id_is_tiny = [](const phantom_node_pair & phantom_pair)
+ {
+ return phantom_pair.first.component_id != 0;
+ };
- auto check_component_id_is_tiny = [](const phantom_node_pair &phantom_pair)
- {
- return phantom_pair.first.component_id != 0;
- };
+ const bool every_phantom_is_in_tiny_cc =
+ std::all_of(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
+ check_component_id_is_tiny);
- const bool every_phantom_is_in_tiny_cc =
- std::all_of(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
- check_component_id_is_tiny);
+ // are all phantoms from a tiny cc?
+ const auto component_id = phantom_node_pair_list.front().first.component_id;
- // are all phantoms from a tiny cc?
- const auto component_id = phantom_node_pair_list.front().first.component_id;
+ auto check_component_id_is_equal = [component_id](const phantom_node_pair & phantom_pair)
+ {
+ return component_id == phantom_pair.first.component_id;
+ };
- auto check_component_id_is_equal = [component_id](const phantom_node_pair &phantom_pair)
- {
- return component_id == phantom_pair.first.component_id;
- };
+ const bool every_phantom_has_equal_id =
+ std::all_of(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
+ check_component_id_is_equal);
- const bool every_phantom_has_equal_id =
- std::all_of(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
- check_component_id_is_equal);
+ auto swap_phantom_from_big_cc_into_front = [](phantom_node_pair & phantom_pair)
+ {
+ if (0 != phantom_pair.first.component_id)
+ {
+ using namespace std;
+ swap(phantom_pair.first, phantom_pair.second);
+ }
+ };
+
+ // this case is true if we take phantoms from the big CC
+ if (!every_phantom_is_in_tiny_cc || !every_phantom_has_equal_id)
+ {
+ std::for_each(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
+ swap_phantom_from_big_cc_into_front);
+ }
- auto swap_phantom_from_big_cc_into_front = [](phantom_node_pair &phantom_pair)
- {
- if (0 != phantom_pair.first.component_id)
- {
- using namespace std;
- swap(phantom_pair.first, phantom_pair.second);
- }
- };
-
- // this case is true if we take phantoms from the big CC
- if (!every_phantom_is_in_tiny_cc || !every_phantom_has_equal_id)
- {
- std::for_each(std::begin(phantom_node_pair_list), std::end(phantom_node_pair_list),
- swap_phantom_from_big_cc_into_front);
- }
+ InternalRouteResult raw_route;
+ auto build_phantom_pairs = [&raw_route](const phantom_node_pair & first_pair,
+ const phantom_node_pair & second_pair)
+ {
+ raw_route.segment_end_coordinates.emplace_back(
+ PhantomNodes{first_pair.first, second_pair.first});
+ };
- InternalRouteResult raw_route;
- auto build_phantom_pairs =
- [&raw_route](const phantom_node_pair &first_pair, const phantom_node_pair &second_pair)
- {
- raw_route.segment_end_coordinates.emplace_back(
- PhantomNodes{first_pair.first, second_pair.first});
- };
+ osrm::for_each_pair(phantom_node_pair_list, build_phantom_pairs);
- osrm::for_each_pair(phantom_node_pair_list, build_phantom_pairs);
+ vector<bool> uturns;
+ m_searchEngine->shortest_path(raw_route.segment_end_coordinates, uturns, raw_route);
+ if (INVALID_EDGE_WEIGHT == raw_route.shortest_path_length)
+ {
+ SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found";
+ return 400;
+ }
- vector<bool> uturns;
- m_searchEngine->shortest_path(raw_route.segment_end_coordinates, uturns, raw_route);
- if (INVALID_EDGE_WEIGHT == raw_route.shortest_path_length)
- {
- SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found";
- return 400;
- }
- // Get mwm names
- set<uint32_t> wayIds;
+ // Get ids of ways used in path.
+ set<uint32_t> wayIds;
- for (auto i : osrm::irange<std::size_t>(0, raw_route.unpacked_path_segments.size()))
- {
- size_t const n = raw_route.unpacked_path_segments[i].size();
- for (size_t j = 0; j < n; ++j)
- {
- PathData const &path_data = raw_route.unpacked_path_segments[i][j];
- auto const & data = m_nodeData[path_data.node];
- for (auto const & seg : data.m_segments)
- wayIds.insert(seg.wayId);
- }
- }
+ for (auto i : osrm::irange<std::size_t>(0, raw_route.unpacked_path_segments.size()))
+ {
+ size_t const n = raw_route.unpacked_path_segments[i].size();
+ for (size_t j = 0; j < n; ++j)
+ {
+ PathData const & path_data = raw_route.unpacked_path_segments[i][j];
+ auto const & data = m_nodeData[path_data.node];
+ for (auto const & seg : data.m_segments)
+ wayIds.insert(seg.wayId);
+ }
+ }
- osrm::json::Array json_array;
- for (auto & id : wayIds)
- {
- json_array.values.push_back(id);
- }
- reply.values["way_ids"] = json_array;
+ // Format answer.
+ osrm::json::Array json_array;
+ json_array.values.assign(wayIds.begin(), wayIds.end());
+ reply.values["way_ids"] = move(json_array);
- return 200;
- }
+ return 200;
+ }
- private:
- std::unique_ptr<SearchEngine<DataFacadeT>> m_searchEngine;
- std::string m_descriptorString;
- DataFacadeT * m_facade;
- osrm::NodeDataVectorT m_nodeData;
+private:
+ std::unique_ptr<SearchEngine<DataFacadeT>> m_searchEngine;
+ std::string m_descriptorString;
+ DataFacadeT * m_facade;
+ osrm::NodeDataVectorT m_nodeData;
};