Updated changelog entry

This commit is contained in:
Denis Chaplygin 2019-08-15 11:40:23 +03:00
parent ff46e98d21
commit a9c187c99b
39 changed files with 591 additions and 457 deletions

View File

@ -7,6 +7,7 @@
- ADDED: data timestamp information in the response (saved in new file `.osrm.timestamp`). [#5115](https://github.com/Project-OSRM/osrm-backend/issues/5115) - ADDED: data timestamp information in the response (saved in new file `.osrm.timestamp`). [#5115](https://github.com/Project-OSRM/osrm-backend/issues/5115)
- ADDED: new API parameter - `snapping=any|default` to allow snapping to previously unsnappable edges [#5361](https://github.com/Project-OSRM/osrm-backend/pull/5361) - ADDED: new API parameter - `snapping=any|default` to allow snapping to previously unsnappable edges [#5361](https://github.com/Project-OSRM/osrm-backend/pull/5361)
- ADDED: keepalive support to the osrm-routed HTTP server [#5518](https://github.com/Project-OSRM/osrm-backend/pull/5518) - ADDED: keepalive support to the osrm-routed HTTP server [#5518](https://github.com/Project-OSRM/osrm-backend/pull/5518)
- ADDED: flatbuffers output format support [#5513](https://github.com/Project-OSRM/osrm-backend/pull/5513)
- Routing: - Routing:
- CHANGED: allow routing past `barrier=arch` [#5352](https://github.com/Project-OSRM/osrm-backend/pull/5352) - CHANGED: allow routing past `barrier=arch` [#5352](https://github.com/Project-OSRM/osrm-backend/pull/5352)
- CHANGED: default car weight was reduced to 2000 kg. [#5371](https://github.com/Project-OSRM/osrm-backend/pull/5371) - CHANGED: default car weight was reduced to 2000 kg. [#5371](https://github.com/Project-OSRM/osrm-backend/pull/5371)

View File

@ -57,7 +57,7 @@ int main(int argc, const char *argv[])
// Execute routing request, this does the heavy lifting // Execute routing request, this does the heavy lifting
const auto status = osrm.Route(params, result); const auto status = osrm.Route(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
if (status == Status::Ok) if (status == Status::Ok)
{ {
auto &routes = json_result.values["routes"].get<json::Array>(); auto &routes = json_result.values["routes"].get<json::Array>();

View File

@ -72,32 +72,42 @@ class BaseAPI
} }
} }
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> MakeWaypoints(flatbuffers::FlatBufferBuilder& builder, const std::vector<PhantomNodes> &segment_end_coordinates) const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
const std::vector<PhantomNodes> &segment_end_coordinates) const
{ {
BOOST_ASSERT(parameters.coordinates.size() > 0); BOOST_ASSERT(parameters.coordinates.size() > 0);
BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1); BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints; std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(parameters.coordinates.size()); waypoints.resize(parameters.coordinates.size());
waypoints[0] = MakeWaypoint(builder, segment_end_coordinates.front().source_phantom).Finish(); waypoints[0] =
MakeWaypoint(builder, segment_end_coordinates.front().source_phantom).Finish();
std::transform(segment_end_coordinates.begin(), segment_end_coordinates.end(), std::next(waypoints.begin()), [this, &builder](const PhantomNodes &phantom_pair) { std::transform(segment_end_coordinates.begin(),
return MakeWaypoint(builder, phantom_pair.target_phantom).Finish(); segment_end_coordinates.end(),
}); std::next(waypoints.begin()),
[this, &builder](const PhantomNodes &phantom_pair) {
return MakeWaypoint(builder, phantom_pair.target_phantom).Finish();
});
return builder.CreateVector(waypoints); return builder.CreateVector(waypoints);
} }
// FIXME: gcc 4.9 does not like MakeWaypoints to be protected // FIXME: gcc 4.9 does not like MakeWaypoints to be protected
// protected: // protected:
fbresult::WaypointBuilder MakeWaypoint(flatbuffers::FlatBufferBuilder& builder, const PhantomNode &phantom) const fbresult::WaypointBuilder MakeWaypoint(flatbuffers::FlatBufferBuilder &builder,
const PhantomNode &phantom) const
{ {
auto location = fbresult::Position(static_cast<double>(util::toFloating(phantom.location.lon)), static_cast<double>(util::toFloating(phantom.location.lat))); auto location =
fbresult::Position(static_cast<double>(util::toFloating(phantom.location.lon)),
static_cast<double>(util::toFloating(phantom.location.lat)));
fbresult::WaypointBuilder waypoint(builder); fbresult::WaypointBuilder waypoint(builder);
waypoint.add_location(&location); waypoint.add_location(&location);
waypoint.add_distance(util::coordinate_calculation::fccApproximateDistance(phantom.location, waypoint.add_distance(util::coordinate_calculation::fccApproximateDistance(
phantom.input_location)); phantom.location, phantom.input_location));
auto name_string = builder.CreateString(facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string()); auto name_string = builder.CreateString(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string());
waypoint.add_name(name_string); waypoint.add_name(name_string);
if (parameters.generate_hints) if (parameters.generate_hints)
{ {

View File

@ -14,7 +14,8 @@ namespace engine
{ {
namespace api namespace api
{ {
using ResultT = mapbox::util::variant<util::json::Object, std::string, flatbuffers::FlatBufferBuilder>; using ResultT =
mapbox::util::variant<util::json::Object, std::string, flatbuffers::FlatBufferBuilder>;
} // ns api } // ns api
} // ns engine } // ns engine
} // ns osrm } // ns osrm

View File

@ -34,10 +34,13 @@ class MatchAPI final : public RouteAPI
osrm::engine::api::ResultT &response) const osrm::engine::api::ResultT &response) const
{ {
BOOST_ASSERT(sub_matchings.size() == sub_routes.size()); BOOST_ASSERT(sub_matchings.size() == sub_routes.size());
if (response.is<flatbuffers::FlatBufferBuilder>()) { if (response.is<flatbuffers::FlatBufferBuilder>())
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>(); auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
MakeResponse(sub_matchings, sub_routes, fb_result); MakeResponse(sub_matchings, sub_routes, fb_result);
} else { }
else
{
auto &json_result = response.get<util::json::Object>(); auto &json_result = response.get<util::json::Object>();
MakeResponse(sub_matchings, sub_routes, json_result); MakeResponse(sub_matchings, sub_routes, json_result);
} }
@ -46,7 +49,9 @@ class MatchAPI final : public RouteAPI
const std::vector<InternalRouteResult> &sub_routes, const std::vector<InternalRouteResult> &sub_routes,
flatbuffers::FlatBufferBuilder &fb_result) const flatbuffers::FlatBufferBuilder &fb_result) const
{ {
auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_matchings]() { return MakeTracepoints(fb_result, sub_matchings); }); auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_matchings]() {
return MakeTracepoints(fb_result, sub_matchings);
});
fb_result.Finish(response.Finish()); fb_result.Finish(response.Finish());
} }
@ -79,7 +84,7 @@ class MatchAPI final : public RouteAPI
{ {
MatchingIndex() = default; MatchingIndex() = default;
MatchingIndex(unsigned sub_matching_index_, unsigned point_index_) MatchingIndex(unsigned sub_matching_index_, unsigned point_index_)
: sub_matching_index(sub_matching_index_), point_index(point_index_) : sub_matching_index(sub_matching_index_), point_index(point_index_)
{ {
} }
@ -94,7 +99,8 @@ class MatchAPI final : public RouteAPI
}; };
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
MakeTracepoints(flatbuffers::FlatBufferBuilder &fb_result, const std::vector<map_matching::SubMatching> &sub_matchings) const MakeTracepoints(flatbuffers::FlatBufferBuilder &fb_result,
const std::vector<map_matching::SubMatching> &sub_matchings) const
{ {
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints; std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.reserve(parameters.coordinates.size()); waypoints.reserve(parameters.coordinates.size());
@ -119,11 +125,11 @@ class MatchAPI final : public RouteAPI
continue; continue;
} }
const auto &phantom = const auto &phantom =
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index]; sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
auto waypoint = BaseAPI::MakeWaypoint(fb_result, phantom); auto waypoint = BaseAPI::MakeWaypoint(fb_result, phantom);
waypoint.add_matchings_index(matching_index.sub_matching_index); waypoint.add_matchings_index(matching_index.sub_matching_index);
waypoint.add_alternatives_count(sub_matchings[matching_index.sub_matching_index] waypoint.add_alternatives_count(sub_matchings[matching_index.sub_matching_index]
.alternatives_count[matching_index.point_index]); .alternatives_count[matching_index.point_index]);
// waypoint indices need to be adjusted if route legs were collapsed // waypoint indices need to be adjusted if route legs were collapsed
// waypoint parameter assumes there is only one match object // waypoint parameter assumes there is only one match object
if (!parameters.waypoints.empty()) if (!parameters.waypoints.empty())
@ -137,7 +143,9 @@ class MatchAPI final : public RouteAPI
{ {
waypoint.add_waypoint_index(0); waypoint.add_waypoint_index(0);
} }
} else { }
else
{
waypoint.add_waypoint_index(matching_index.point_index); waypoint.add_waypoint_index(matching_index.point_index);
} }
waypoints.push_back(waypoint.Finish()); waypoints.push_back(waypoint.Finish());
@ -198,20 +206,24 @@ class MatchAPI final : public RouteAPI
return waypoints; return waypoints;
} }
std::vector<MatchingIndex> MakeMatchingIndices(const std::vector<map_matching::SubMatching> &sub_matchings) const { std::vector<MatchingIndex>
MakeMatchingIndices(const std::vector<map_matching::SubMatching> &sub_matchings) const
{
std::vector<MatchingIndex> trace_idx_to_matching_idx(parameters.coordinates.size()); std::vector<MatchingIndex> trace_idx_to_matching_idx(parameters.coordinates.size());
for (auto sub_matching_index : for (auto sub_matching_index :
util::irange(0u, static_cast<unsigned>(sub_matchings.size()))) { util::irange(0u, static_cast<unsigned>(sub_matchings.size())))
{
for (auto point_index : util::irange( for (auto point_index : util::irange(
0u, static_cast<unsigned>(sub_matchings[sub_matching_index].indices.size()))) { 0u, static_cast<unsigned>(sub_matchings[sub_matching_index].indices.size())))
{
// tidied_to_original: index of the input coordinate that a tidied coordinate // tidied_to_original: index of the input coordinate that a tidied coordinate
// corresponds to. // corresponds to.
// sub_matching indices: index of the coordinate passed to map matching plugin that // sub_matching indices: index of the coordinate passed to map matching plugin that
// a matched node corresponds to. // a matched node corresponds to.
trace_idx_to_matching_idx[tidy_result trace_idx_to_matching_idx[tidy_result
.tidied_to_original[sub_matchings[sub_matching_index] .tidied_to_original[sub_matchings[sub_matching_index]
.indices[point_index]]] = .indices[point_index]]] =
MatchingIndex{sub_matching_index, point_index}; MatchingIndex{sub_matching_index, point_index};
} }
} }
return trace_idx_to_matching_idx; return trace_idx_to_matching_idx;

View File

@ -27,21 +27,21 @@ class NearestAPI final : public BaseAPI
} }
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes, void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
osrm::engine::api::ResultT &response) const { osrm::engine::api::ResultT &response) const
{
BOOST_ASSERT(phantom_nodes.size() == 1); BOOST_ASSERT(phantom_nodes.size() == 1);
BOOST_ASSERT(parameters.coordinates.size() == 1); BOOST_ASSERT(parameters.coordinates.size() == 1);
if(response.is<flatbuffers::FlatBufferBuilder>()) if (response.is<flatbuffers::FlatBufferBuilder>())
{ {
auto& fb_result = response.get<flatbuffers::FlatBufferBuilder>(); auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
MakeResponse(phantom_nodes, fb_result); MakeResponse(phantom_nodes, fb_result);
} }
else else
{ {
auto& json_result = response.get<util::json::Object>(); auto &json_result = response.get<util::json::Object>();
MakeResponse(phantom_nodes, json_result); MakeResponse(phantom_nodes, json_result);
} }
} }
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes, void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
@ -51,49 +51,47 @@ class NearestAPI final : public BaseAPI
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints; std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(phantom_nodes.front().size()); waypoints.resize(phantom_nodes.front().size());
std::transform( std::transform(phantom_nodes.front().begin(),
phantom_nodes.front().begin(), phantom_nodes.front().end(),
phantom_nodes.front().end(), waypoints.begin(),
waypoints.begin(), [this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) {
[this, &fb_result](const PhantomNodeWithDistance &phantom_with_distance) { auto &phantom_node = phantom_with_distance.phantom_node;
auto &phantom_node = phantom_with_distance.phantom_node;
auto node_values = MakeNodes(phantom_node); auto node_values = MakeNodes(phantom_node);
fbresult::Uint64Pair nodes{node_values.first, node_values.second}; fbresult::Uint64Pair nodes{node_values.first, node_values.second};
auto waypoint = MakeWaypoint(fb_result,phantom_node); auto waypoint = MakeWaypoint(fb_result, phantom_node);
waypoint.add_nodes(&nodes); waypoint.add_nodes(&nodes);
return waypoint.Finish(); return waypoint.Finish();
}); });
auto waypoints_vector = fb_result.CreateVector(waypoints); auto waypoints_vector = fb_result.CreateVector(waypoints);
response.add_waypoints(waypoints_vector); response.add_waypoints(waypoints_vector);
fb_result.Finish(response.Finish()); fb_result.Finish(response.Finish());
} }
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes, void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes,
util::json::Object &response) const util::json::Object &response) const
{ {
util::json::Array waypoints; util::json::Array waypoints;
waypoints.values.resize(phantom_nodes.front().size()); waypoints.values.resize(phantom_nodes.front().size());
std::transform( std::transform(phantom_nodes.front().begin(),
phantom_nodes.front().begin(), phantom_nodes.front().end(),
phantom_nodes.front().end(), waypoints.values.begin(),
waypoints.values.begin(), [this](const PhantomNodeWithDistance &phantom_with_distance) {
[this](const PhantomNodeWithDistance &phantom_with_distance) { auto &phantom_node = phantom_with_distance.phantom_node;
auto &phantom_node = phantom_with_distance.phantom_node; auto waypoint = MakeWaypoint(phantom_node);
auto waypoint = MakeWaypoint(phantom_node);
util::json::Array nodes; util::json::Array nodes;
auto node_values = MakeNodes(phantom_node); auto node_values = MakeNodes(phantom_node);
nodes.values.push_back(node_values.first); nodes.values.push_back(node_values.first);
nodes.values.push_back(node_values.second); nodes.values.push_back(node_values.second);
waypoint.values["nodes"] = std::move(nodes); waypoint.values["nodes"] = std::move(nodes);
return waypoint; return waypoint;
}); });
response.values["code"] = "Ok"; response.values["code"] = "Ok";
response.values["waypoints"] = std::move(waypoints); response.values["waypoints"] = std::move(waypoints);
@ -101,8 +99,9 @@ class NearestAPI final : public BaseAPI
const NearestParameters &parameters; const NearestParameters &parameters;
protected: protected:
std::pair<uint64_t, uint64_t> MakeNodes(const PhantomNode& phantom_node) const { std::pair<uint64_t, uint64_t> MakeNodes(const PhantomNode &phantom_node) const
{
std::uint64_t from_node = 0; std::uint64_t from_node = 0;
std::uint64_t to_node = 0; std::uint64_t to_node = 0;
@ -113,8 +112,8 @@ protected:
const auto geometry_id = facade.GetGeometryIndex(segment_id).id; const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
forward_geometry = facade.GetUncompressedForwardGeometry(geometry_id); forward_geometry = facade.GetUncompressedForwardGeometry(geometry_id);
auto osm_node_id = facade.GetOSMNodeIDOfNode( auto osm_node_id =
forward_geometry(phantom_node.fwd_segment_position)); facade.GetOSMNodeIDOfNode(forward_geometry(phantom_node.fwd_segment_position));
to_node = static_cast<std::uint64_t>(osm_node_id); to_node = static_cast<std::uint64_t>(osm_node_id);
} }
@ -124,15 +123,14 @@ protected:
const auto geometry_id = facade.GetGeometryIndex(segment_id).id; const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
const auto geometry = facade.GetUncompressedForwardGeometry(geometry_id); const auto geometry = facade.GetUncompressedForwardGeometry(geometry_id);
auto osm_node_id = auto osm_node_id =
facade.GetOSMNodeIDOfNode(geometry(phantom_node.fwd_segment_position + 1)); facade.GetOSMNodeIDOfNode(geometry(phantom_node.fwd_segment_position + 1));
from_node = static_cast<std::uint64_t>(osm_node_id); from_node = static_cast<std::uint64_t>(osm_node_id);
} }
else if (phantom_node.forward_segment_id.enabled && else if (phantom_node.forward_segment_id.enabled && phantom_node.fwd_segment_position > 0)
phantom_node.fwd_segment_position > 0)
{ {
// In the case of one way, rely on forward segment only // In the case of one way, rely on forward segment only
auto osm_node_id = facade.GetOSMNodeIDOfNode( auto osm_node_id =
forward_geometry(phantom_node.fwd_segment_position - 1)); facade.GetOSMNodeIDOfNode(forward_geometry(phantom_node.fwd_segment_position - 1));
from_node = static_cast<std::uint64_t>(osm_node_id); from_node = static_cast<std::uint64_t>(osm_node_id);
} }

View File

@ -36,23 +36,29 @@ namespace engine
namespace api namespace api
{ {
class RouteAPI : public BaseAPI { class RouteAPI : public BaseAPI
public: {
public:
RouteAPI(const datafacade::BaseDataFacade &facade_, const RouteParameters &parameters_) RouteAPI(const datafacade::BaseDataFacade &facade_, const RouteParameters &parameters_)
: BaseAPI(facade_, parameters_), parameters(parameters_) { : BaseAPI(facade_, parameters_), parameters(parameters_)
{
} }
void void
MakeResponse(const InternalManyRoutesResult &raw_routes, MakeResponse(const InternalManyRoutesResult &raw_routes,
const std::vector<PhantomNodes> const std::vector<PhantomNodes>
&all_start_end_points, // all used coordinates, ignoring waypoints= parameter &all_start_end_points, // all used coordinates, ignoring waypoints= parameter
osrm::engine::api::ResultT &response) const { osrm::engine::api::ResultT &response) const
{
BOOST_ASSERT(!raw_routes.routes.empty()); BOOST_ASSERT(!raw_routes.routes.empty());
if (response.is<flatbuffers::FlatBufferBuilder>()) { if (response.is<flatbuffers::FlatBufferBuilder>())
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>(); auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
MakeResponse(raw_routes, all_start_end_points, fb_result); MakeResponse(raw_routes, all_start_end_points, fb_result);
} else { }
else
{
auto &json_result = response.get<util::json::Object>(); auto &json_result = response.get<util::json::Object>();
MakeResponse(raw_routes, all_start_end_points, json_result); MakeResponse(raw_routes, all_start_end_points, json_result);
} }
@ -61,12 +67,13 @@ public:
void void
MakeResponse(const InternalManyRoutesResult &raw_routes, MakeResponse(const InternalManyRoutesResult &raw_routes,
const std::vector<PhantomNodes> const std::vector<PhantomNodes>
&all_start_end_points, // all used coordinates, ignoring waypoints= parameter &all_start_end_points, // all used coordinates, ignoring waypoints= parameter
flatbuffers::FlatBufferBuilder &fb_result) const flatbuffers::FlatBufferBuilder &fb_result) const
{ {
auto response = MakeFBResponse(raw_routes, fb_result, [this, &all_start_end_points, &fb_result]() { auto response =
return BaseAPI::MakeWaypoints(fb_result, all_start_end_points); MakeFBResponse(raw_routes, fb_result, [this, &all_start_end_points, &fb_result]() {
}); return BaseAPI::MakeWaypoints(fb_result, all_start_end_points);
});
auto data_timestamp = facade.GetTimestamp(); auto data_timestamp = facade.GetTimestamp();
if (!data_timestamp.empty()) if (!data_timestamp.empty())
@ -109,10 +116,9 @@ public:
protected: protected:
template <typename GetWptsFn> template <typename GetWptsFn>
fbresult::FBResultBuilder fbresult::FBResultBuilder MakeFBResponse(const InternalManyRoutesResult &raw_routes,
MakeFBResponse(const InternalManyRoutesResult &raw_routes, flatbuffers::FlatBufferBuilder &fb_result,
flatbuffers::FlatBufferBuilder &fb_result, GetWptsFn getWaypoints) const
GetWptsFn getWaypoints) const
{ {
fbresult::FBResultBuilder response(fb_result); fbresult::FBResultBuilder response(fb_result);
@ -140,37 +146,47 @@ public:
template <typename BuilderType, typename ForwardIter> template <typename BuilderType, typename ForwardIter>
void MakeGeometry(BuilderType builder, ForwardIter begin, ForwardIter end) const void MakeGeometry(BuilderType builder, ForwardIter begin, ForwardIter end) const
{ {
if (parameters.geometries == RouteParameters::GeometriesType::Polyline) { if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
{
auto polyline_string = builder.fbb_.CreateString(encodePolyline<100000>(begin, end)); auto polyline_string = builder.fbb_.CreateString(encodePolyline<100000>(begin, end));
builder.add_polyline(polyline_string); builder.add_polyline(polyline_string);
} else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6) { }
else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
{
auto polyline_string = builder.fbb_.CreateString(encodePolyline<1000000>(begin, end)); auto polyline_string = builder.fbb_.CreateString(encodePolyline<1000000>(begin, end));
builder.add_polyline(polyline_string); builder.add_polyline(polyline_string);
} else { }
else
{
std::vector<fbresult::Position> coordinates; std::vector<fbresult::Position> coordinates;
coordinates.resize(std::distance(begin, end)); coordinates.resize(std::distance(begin, end));
std::transform(begin, end, coordinates.begin(), [](const Coordinate &c) { std::transform(begin, end, coordinates.begin(), [](const Coordinate &c) {
return fbresult::Position{static_cast<float>(util::toFloating(c.lon).__value), return fbresult::Position{static_cast<float>(util::toFloating(c.lon).__value),
static_cast<float>(util::toFloating(c.lat).__value)}; static_cast<float>(util::toFloating(c.lat).__value)};
}); });
auto coordinates_vector = builder.fbb_.CreateVectorOfStructs(coordinates); auto coordinates_vector = builder.fbb_.CreateVectorOfStructs(coordinates);
builder.add_coordinates(coordinates_vector); builder.add_coordinates(coordinates_vector);
} }
} }
boost::optional<util::json::Value> MakeGeometry(boost::optional<std::vector<Coordinate>>&& annotations) const boost::optional<util::json::Value>
MakeGeometry(boost::optional<std::vector<Coordinate>> &&annotations) const
{ {
boost::optional<util::json::Value> json_geometry; boost::optional<util::json::Value> json_geometry;
if (annotations) { if (annotations)
{
auto begin = annotations->begin(); auto begin = annotations->begin();
auto end = annotations->end(); auto end = annotations->end();
if (parameters.geometries == RouteParameters::GeometriesType::Polyline) if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
{ {
json_geometry = json::makePolyline<100000>(begin, end); json_geometry = json::makePolyline<100000>(begin, end);
} else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6) }
else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
{ {
json_geometry = json::makePolyline<1000000>(begin, end); json_geometry = json::makePolyline<1000000>(begin, end);
} else { }
else
{
BOOST_ASSERT(parameters.geometries == RouteParameters::GeometriesType::GeoJSON); BOOST_ASSERT(parameters.geometries == RouteParameters::GeometriesType::GeoJSON);
json_geometry = json::makeGeoJSONGeometry(begin, end); json_geometry = json::makeGeoJSONGeometry(begin, end);
} }
@ -179,7 +195,8 @@ public:
} }
template <typename ValueType, typename GetFn> template <typename ValueType, typename GetFn>
flatbuffers::Offset<flatbuffers::Vector<ValueType>> GetAnnotations(flatbuffers::FlatBufferBuilder& fb_result, guidance::LegGeometry &leg, GetFn Get) const flatbuffers::Offset<flatbuffers::Vector<ValueType>> GetAnnotations(
flatbuffers::FlatBufferBuilder &fb_result, guidance::LegGeometry &leg, GetFn Get) const
{ {
std::vector<ValueType> annotations_store; std::vector<ValueType> annotations_store;
annotations_store.reserve(leg.annotations.size()); annotations_store.reserve(leg.annotations.size());
@ -206,76 +223,85 @@ public:
return annotations_store; return annotations_store;
} }
fbresult::ManeuverType WaypointTypeToFB(guidance::WaypointType type) const { fbresult::ManeuverType WaypointTypeToFB(guidance::WaypointType type) const
switch(type) { {
case guidance::WaypointType::Arrive: switch (type)
return fbresult::ManeuverType_Arrive; {
case guidance::WaypointType::Depart: case guidance::WaypointType::Arrive:
return fbresult::ManeuverType_Depart; return fbresult::ManeuverType_Arrive;
default: case guidance::WaypointType::Depart:
return fbresult::ManeuverType_Notification; return fbresult::ManeuverType_Depart;
default:
return fbresult::ManeuverType_Notification;
} }
} }
fbresult::ManeuverType TurnTypeToFB(osrm::guidance::TurnType::Enum turn) const { fbresult::ManeuverType TurnTypeToFB(osrm::guidance::TurnType::Enum turn) const
static std::map<osrm::guidance::TurnType::Enum, fbresult::ManeuverType> mappings={ {
{osrm::guidance::TurnType::Invalid, fbresult::ManeuverType_Notification}, static std::map<osrm::guidance::TurnType::Enum, fbresult::ManeuverType> mappings = {
{osrm::guidance::TurnType::NewName, fbresult::ManeuverType_NewName}, {osrm::guidance::TurnType::Invalid, fbresult::ManeuverType_Notification},
{osrm::guidance::TurnType::Continue, fbresult::ManeuverType_Continue}, {osrm::guidance::TurnType::NewName, fbresult::ManeuverType_NewName},
{osrm::guidance::TurnType::Turn, fbresult::ManeuverType_Turn}, {osrm::guidance::TurnType::Continue, fbresult::ManeuverType_Continue},
{osrm::guidance::TurnType::Merge, fbresult::ManeuverType_Merge}, {osrm::guidance::TurnType::Turn, fbresult::ManeuverType_Turn},
{osrm::guidance::TurnType::OnRamp, fbresult::ManeuverType_OnRamp}, {osrm::guidance::TurnType::Merge, fbresult::ManeuverType_Merge},
{osrm::guidance::TurnType::OffRamp, fbresult::ManeuverType_OffRamp}, {osrm::guidance::TurnType::OnRamp, fbresult::ManeuverType_OnRamp},
{osrm::guidance::TurnType::Fork, fbresult::ManeuverType_Fork}, {osrm::guidance::TurnType::OffRamp, fbresult::ManeuverType_OffRamp},
{osrm::guidance::TurnType::EndOfRoad, fbresult::ManeuverType_EndOfRoad}, {osrm::guidance::TurnType::Fork, fbresult::ManeuverType_Fork},
{osrm::guidance::TurnType::Notification, fbresult::ManeuverType_Notification}, {osrm::guidance::TurnType::EndOfRoad, fbresult::ManeuverType_EndOfRoad},
{osrm::guidance::TurnType::EnterRoundabout, fbresult::ManeuverType_Roundabout}, {osrm::guidance::TurnType::Notification, fbresult::ManeuverType_Notification},
{osrm::guidance::TurnType::EnterAndExitRoundabout, fbresult::ManeuverType_ExitRoundabout}, {osrm::guidance::TurnType::EnterRoundabout, fbresult::ManeuverType_Roundabout},
{osrm::guidance::TurnType::EnterRotary, fbresult::ManeuverType_Rotary}, {osrm::guidance::TurnType::EnterAndExitRoundabout,
{osrm::guidance::TurnType::EnterAndExitRotary, fbresult::ManeuverType_ExitRotary}, fbresult::ManeuverType_ExitRoundabout},
{osrm::guidance::TurnType::EnterRoundaboutIntersection, fbresult::ManeuverType_Roundabout}, {osrm::guidance::TurnType::EnterRotary, fbresult::ManeuverType_Rotary},
{osrm::guidance::TurnType::EnterAndExitRoundaboutIntersection, fbresult::ManeuverType_ExitRoundabout}, {osrm::guidance::TurnType::EnterAndExitRotary, fbresult::ManeuverType_ExitRotary},
{osrm::guidance::TurnType::NoTurn, fbresult::ManeuverType_Notification}, {osrm::guidance::TurnType::EnterRoundaboutIntersection,
{osrm::guidance::TurnType::Suppressed, fbresult::ManeuverType_Notification}, fbresult::ManeuverType_Roundabout},
{osrm::guidance::TurnType::EnterRoundaboutAtExit, fbresult::ManeuverType_Roundabout}, {osrm::guidance::TurnType::EnterAndExitRoundaboutIntersection,
{osrm::guidance::TurnType::ExitRoundabout, fbresult::ManeuverType_ExitRoundabout}, fbresult::ManeuverType_ExitRoundabout},
{osrm::guidance::TurnType::EnterRotaryAtExit, fbresult::ManeuverType_Rotary}, {osrm::guidance::TurnType::NoTurn, fbresult::ManeuverType_Notification},
{osrm::guidance::TurnType::ExitRotary, fbresult::ManeuverType_ExitRotary}, {osrm::guidance::TurnType::Suppressed, fbresult::ManeuverType_Notification},
{osrm::guidance::TurnType::EnterRoundaboutIntersectionAtExit, fbresult::ManeuverType_Roundabout}, {osrm::guidance::TurnType::EnterRoundaboutAtExit, fbresult::ManeuverType_Roundabout},
{osrm::guidance::TurnType::ExitRoundaboutIntersection, fbresult::ManeuverType_ExitRoundabout}, {osrm::guidance::TurnType::ExitRoundabout, fbresult::ManeuverType_ExitRoundabout},
{osrm::guidance::TurnType::StayOnRoundabout, fbresult::ManeuverType_RoundaboutTurn}, {osrm::guidance::TurnType::EnterRotaryAtExit, fbresult::ManeuverType_Rotary},
{osrm::guidance::TurnType::Sliproad, fbresult::ManeuverType_Notification}, {osrm::guidance::TurnType::ExitRotary, fbresult::ManeuverType_ExitRotary},
{osrm::guidance::TurnType::MaxTurnType, fbresult::ManeuverType_Notification} {osrm::guidance::TurnType::EnterRoundaboutIntersectionAtExit,
}; fbresult::ManeuverType_Roundabout},
{osrm::guidance::TurnType::ExitRoundaboutIntersection,
fbresult::ManeuverType_ExitRoundabout},
{osrm::guidance::TurnType::StayOnRoundabout, fbresult::ManeuverType_RoundaboutTurn},
{osrm::guidance::TurnType::Sliproad, fbresult::ManeuverType_Notification},
{osrm::guidance::TurnType::MaxTurnType, fbresult::ManeuverType_Notification}};
return mappings[turn]; return mappings[turn];
} }
fbresult::Turn TurnModifierToFB(osrm::guidance::DirectionModifier::Enum modifier) const { fbresult::Turn TurnModifierToFB(osrm::guidance::DirectionModifier::Enum modifier) const
static std::map<osrm::guidance::DirectionModifier::Enum, fbresult::Turn> mappings={ {
{osrm::guidance::DirectionModifier::UTurn, fbresult::Turn_UTurn}, static std::map<osrm::guidance::DirectionModifier::Enum, fbresult::Turn> mappings = {
{osrm::guidance::DirectionModifier::SharpRight, fbresult::Turn_SharpRight}, {osrm::guidance::DirectionModifier::UTurn, fbresult::Turn_UTurn},
{osrm::guidance::DirectionModifier::Right, fbresult::Turn_Right}, {osrm::guidance::DirectionModifier::SharpRight, fbresult::Turn_SharpRight},
{osrm::guidance::DirectionModifier::SlightRight, fbresult::Turn_SlightRight}, {osrm::guidance::DirectionModifier::Right, fbresult::Turn_Right},
{osrm::guidance::DirectionModifier::Straight, fbresult::Turn_Straight}, {osrm::guidance::DirectionModifier::SlightRight, fbresult::Turn_SlightRight},
{osrm::guidance::DirectionModifier::SlightLeft, fbresult::Turn_SlightLeft}, {osrm::guidance::DirectionModifier::Straight, fbresult::Turn_Straight},
{osrm::guidance::DirectionModifier::Left, fbresult::Turn_Left}, {osrm::guidance::DirectionModifier::SlightLeft, fbresult::Turn_SlightLeft},
{osrm::guidance::DirectionModifier::SharpLeft, fbresult::Turn_SharpLeft}, {osrm::guidance::DirectionModifier::Left, fbresult::Turn_Left},
{osrm::guidance::DirectionModifier::SharpLeft, fbresult::Turn_SharpLeft},
}; };
return mappings[modifier]; return mappings[modifier];
} }
std::vector<int8_t> TurnLaneTypeToFB(const extractor::TurnLaneType::Mask lane_type) const { std::vector<int8_t> TurnLaneTypeToFB(const extractor::TurnLaneType::Mask lane_type) const
{
const static fbresult::Turn mapping[] = {fbresult::Turn_None, const static fbresult::Turn mapping[] = {fbresult::Turn_None,
fbresult::Turn_Straight, fbresult::Turn_Straight,
fbresult::Turn_SharpLeft, fbresult::Turn_SharpLeft,
fbresult::Turn_Left, fbresult::Turn_Left,
fbresult::Turn_SlightLeft, fbresult::Turn_SlightLeft,
fbresult::Turn_SlightRight, fbresult::Turn_SlightRight,
fbresult::Turn_Right, fbresult::Turn_Right,
fbresult::Turn_SharpRight, fbresult::Turn_SharpRight,
fbresult::Turn_UTurn, fbresult::Turn_UTurn,
fbresult::Turn_SlightLeft, fbresult::Turn_SlightLeft,
fbresult::Turn_SlightRight}; fbresult::Turn_SlightRight};
std::vector<int8_t> result; std::vector<int8_t> result;
std::bitset<8 * sizeof(extractor::TurnLaneType::Mask)> mask(lane_type); std::bitset<8 * sizeof(extractor::TurnLaneType::Mask)> mask(lane_type);
for (auto index : util::irange<std::size_t>(0, extractor::TurnLaneType::NUM_TYPES)) for (auto index : util::irange<std::size_t>(0, extractor::TurnLaneType::NUM_TYPES))
@ -286,22 +312,24 @@ public:
} }
} }
return result; return result;
} }
flatbuffers::Offset<fbresult::RouteObject> flatbuffers::Offset<fbresult::RouteObject>
MakeRoute(flatbuffers::FlatBufferBuilder &fb_result, MakeRoute(flatbuffers::FlatBufferBuilder &fb_result,
const std::vector<PhantomNodes> &segment_end_coordinates, const std::vector<PhantomNodes> &segment_end_coordinates,
const std::vector<std::vector<PathData>> &unpacked_path_segments, const std::vector<std::vector<PathData>> &unpacked_path_segments,
const std::vector<bool> &source_traversed_in_reverse, const std::vector<bool> &source_traversed_in_reverse,
const std::vector<bool> &target_traversed_in_reverse) const const std::vector<bool> &target_traversed_in_reverse) const
{ {
fbresult::RouteObjectBuilder routeObject(fb_result); fbresult::RouteObjectBuilder routeObject(fb_result);
auto legs_info = MakeLegs(segment_end_coordinates, unpacked_path_segments, source_traversed_in_reverse, target_traversed_in_reverse); auto legs_info = MakeLegs(segment_end_coordinates,
unpacked_path_segments,
source_traversed_in_reverse,
target_traversed_in_reverse);
std::vector<guidance::RouteLeg> legs = legs_info.first; std::vector<guidance::RouteLeg> legs = legs_info.first;
std::vector<guidance::LegGeometry> leg_geometries = legs_info.second; std::vector<guidance::LegGeometry> leg_geometries = legs_info.second;
//Fill basix route info // Fill basix route info
auto route = guidance::assembleRoute(legs); auto route = guidance::assembleRoute(legs);
routeObject.add_distance(route.distance); routeObject.add_distance(route.distance);
routeObject.add_duration(route.duration); routeObject.add_duration(route.duration);
@ -309,137 +337,175 @@ public:
auto weight_name_string = fb_result.CreateString(facade.GetWeightName()); auto weight_name_string = fb_result.CreateString(facade.GetWeightName());
routeObject.add_weight_name(weight_name_string); routeObject.add_weight_name(weight_name_string);
//Fill legs // Fill legs
std::vector<flatbuffers::Offset<fbresult::Leg>> routeLegs; std::vector<flatbuffers::Offset<fbresult::Leg>> routeLegs;
routeLegs.reserve(legs.size()); routeLegs.reserve(legs.size());
for (const auto idx : util::irange<std::size_t>(0UL, legs.size())) { for (const auto idx : util::irange<std::size_t>(0UL, legs.size()))
{
auto leg = legs[idx]; auto leg = legs[idx];
auto &leg_geometry = leg_geometries[idx]; auto &leg_geometry = leg_geometries[idx];
fbresult::LegBuilder legBuilder(fb_result); fbresult::LegBuilder legBuilder(fb_result);
legBuilder.add_distance(leg.distance); legBuilder.add_distance(leg.distance);
legBuilder.add_duration(leg.duration); legBuilder.add_duration(leg.duration);
legBuilder.add_weight(leg.weight); legBuilder.add_weight(leg.weight);
if (!leg.summary.empty()) { if (!leg.summary.empty())
{
auto summary_string = fb_result.CreateString(leg.summary); auto summary_string = fb_result.CreateString(leg.summary);
legBuilder.add_summary(summary_string); legBuilder.add_summary(summary_string);
} }
//Fill steps // Fill steps
if (!leg.steps.empty()) { if (!leg.steps.empty())
{
std::vector<flatbuffers::Offset<fbresult::Step>> legSteps; std::vector<flatbuffers::Offset<fbresult::Step>> legSteps;
legSteps.resize(leg.steps.size()); legSteps.resize(leg.steps.size());
std::transform(leg.steps.begin(), leg.steps.end(), legSteps.begin(), [this, &leg_geometry, &fb_result](const guidance::RouteStep& step) { std::transform(
fbresult::StepBuilder stepBuilder(fb_result); leg.steps.begin(),
stepBuilder.add_duration(step.duration); leg.steps.end(),
stepBuilder.add_distance(step.distance); legSteps.begin(),
stepBuilder.add_weight(step.weight); [this, &leg_geometry, &fb_result](const guidance::RouteStep &step) {
auto name_string = fb_result.CreateString(step.name); fbresult::StepBuilder stepBuilder(fb_result);
stepBuilder.add_name(name_string); stepBuilder.add_duration(step.duration);
if (!step.ref.empty()) { stepBuilder.add_distance(step.distance);
auto ref_string = fb_result.CreateString(step.ref); stepBuilder.add_weight(step.weight);
stepBuilder.add_ref(ref_string); auto name_string = fb_result.CreateString(step.name);
} stepBuilder.add_name(name_string);
if (!step.pronunciation.empty()) { if (!step.ref.empty())
auto pronunciation_string = fb_result.CreateString(step.pronunciation); {
stepBuilder.add_pronunciation(pronunciation_string); auto ref_string = fb_result.CreateString(step.ref);
} stepBuilder.add_ref(ref_string);
if (!step.destinations.empty()) {
auto destinations_string = fb_result.CreateString(step.destinations);
stepBuilder.add_destinations(destinations_string);
}
if (!step.exits.empty()) {
auto exists_string = fb_result.CreateString(step.exits);
stepBuilder.add_exits(exists_string);
}
if(!step.rotary_name.empty()) {
auto rotary_name_string = fb_result.CreateString(step.rotary_name);
stepBuilder.add_rotary_name(rotary_name_string);
if (!step.rotary_pronunciation.empty()) {
auto rotary_pronunciation_string = fb_result.CreateString(step.rotary_pronunciation);
stepBuilder.add_rotary_pronunciation(rotary_pronunciation_string);
} }
} if (!step.pronunciation.empty())
auto mode_string = fb_result.CreateString(extractor::travelModeToString(step.mode)); {
stepBuilder.add_mode(mode_string); auto pronunciation_string = fb_result.CreateString(step.pronunciation);
stepBuilder.add_driving_side(step.is_left_hand_driving); stepBuilder.add_pronunciation(pronunciation_string);
}
//Geometry if (!step.destinations.empty())
MakeGeometry(stepBuilder, leg_geometry.locations.begin() + step.geometry_begin, leg_geometry.locations.begin() + step.geometry_end); {
//Maneuver auto destinations_string = fb_result.CreateString(step.destinations);
fbresult::StepManeuverBuilder maneuver(fb_result); stepBuilder.add_destinations(destinations_string);
fbresult::Position maneuverPosition{static_cast<float>(util::toFloating(step.maneuver.location.lon).__value), }
static_cast<float>(util::toFloating(step.maneuver.location.lat).__value)}; if (!step.exits.empty())
maneuver.add_location(&maneuverPosition); {
maneuver.add_bearing_before(step.maneuver.bearing_before); auto exists_string = fb_result.CreateString(step.exits);
maneuver.add_bearing_after(step.maneuver.bearing_after); stepBuilder.add_exits(exists_string);
if (step.maneuver.waypoint_type == guidance::WaypointType::None) }
maneuver.add_type(TurnTypeToFB(step.maneuver.instruction.type)); if (!step.rotary_name.empty())
else {
maneuver.add_type(WaypointTypeToFB(step.maneuver.waypoint_type)); auto rotary_name_string = fb_result.CreateString(step.rotary_name);
if (osrm::engine::api::json::detail::isValidModifier(step.maneuver)) { stepBuilder.add_rotary_name(rotary_name_string);
maneuver.add_modifier(TurnModifierToFB(step.maneuver.instruction.direction_modifier)); if (!step.rotary_pronunciation.empty())
}
if (step.maneuver.exit != 0) {
maneuver.add_exit(step.maneuver.exit);
}
//intersections
std::vector<flatbuffers::Offset<fbresult::Intersection>> intersections;
intersections.resize(step.intersections.size());
std::transform(step.intersections.begin(), step.intersections.end(), intersections.begin(), [&fb_result, this](const guidance::IntermediateIntersection& intersection) {
fbresult::IntersectionBuilder intersectionBuilder(fb_result);
fbresult::Position maneuverPosition{static_cast<float>(util::toFloating(intersection.location.lon).__value),
static_cast<float>(util::toFloating(intersection.location.lat).__value)};
intersectionBuilder.add_location(&maneuverPosition);
auto bearings_vector = fb_result.CreateVector(intersection.bearings);
intersectionBuilder.add_bearings(bearings_vector);
std::vector<flatbuffers::Offset<flatbuffers::String>> classes;
classes.resize(intersection.classes.size());
std::transform(intersection.classes.begin(), intersection.classes.end(), classes.begin(), [&fb_result](const std::string cls) {
return fb_result.CreateString(cls);
});
auto classes_vector = fb_result.CreateVector(classes);
intersectionBuilder.add_classes(classes_vector);
auto entry_vector = fb_result.CreateVector(intersection.entry);
intersectionBuilder.add_entry(entry_vector);
intersectionBuilder.add_in(intersection.in);
intersectionBuilder.add_out(intersection.out);
if (api::json::detail::hasValidLanes(intersection)) {
BOOST_ASSERT(intersection.lanes.lanes_in_turn >= 1);
std::vector<flatbuffers::Offset<fbresult::Lane>> lanes;
lanes.resize(intersection.lane_description.size());
LaneID lane_id = intersection.lane_description.size();
for (const auto &lane_desc : intersection.lane_description)
{ {
--lane_id; auto rotary_pronunciation_string =
fbresult::LaneBuilder laneBuilder(fb_result); fb_result.CreateString(step.rotary_pronunciation);
auto indications_vector = fb_result.CreateVector(TurnLaneTypeToFB(lane_desc)); stepBuilder.add_rotary_pronunciation(rotary_pronunciation_string);
laneBuilder.add_indications(indications_vector);
if (lane_id >= intersection.lanes.first_lane_from_the_right &&
lane_id <
intersection.lanes.first_lane_from_the_right + intersection.lanes.lanes_in_turn)
laneBuilder.add_valid(true);
else
laneBuilder.add_valid(false);
lanes.emplace_back(laneBuilder.Finish());
} }
auto lanes_vector = fb_result.CreateVector(lanes); }
intersectionBuilder.add_lanes(lanes_vector); auto mode_string =
fb_result.CreateString(extractor::travelModeToString(step.mode));
stepBuilder.add_mode(mode_string);
stepBuilder.add_driving_side(step.is_left_hand_driving);
// Geometry
MakeGeometry(stepBuilder,
leg_geometry.locations.begin() + step.geometry_begin,
leg_geometry.locations.begin() + step.geometry_end);
// Maneuver
fbresult::StepManeuverBuilder maneuver(fb_result);
fbresult::Position maneuverPosition{
static_cast<float>(
util::toFloating(step.maneuver.location.lon).__value),
static_cast<float>(
util::toFloating(step.maneuver.location.lat).__value)};
maneuver.add_location(&maneuverPosition);
maneuver.add_bearing_before(step.maneuver.bearing_before);
maneuver.add_bearing_after(step.maneuver.bearing_after);
if (step.maneuver.waypoint_type == guidance::WaypointType::None)
maneuver.add_type(TurnTypeToFB(step.maneuver.instruction.type));
else
maneuver.add_type(WaypointTypeToFB(step.maneuver.waypoint_type));
if (osrm::engine::api::json::detail::isValidModifier(step.maneuver))
{
maneuver.add_modifier(
TurnModifierToFB(step.maneuver.instruction.direction_modifier));
}
if (step.maneuver.exit != 0)
{
maneuver.add_exit(step.maneuver.exit);
} }
return intersectionBuilder.Finish(); // intersections
std::vector<flatbuffers::Offset<fbresult::Intersection>> intersections;
intersections.resize(step.intersections.size());
std::transform(
step.intersections.begin(),
step.intersections.end(),
intersections.begin(),
[&fb_result,
this](const guidance::IntermediateIntersection &intersection) {
fbresult::IntersectionBuilder intersectionBuilder(fb_result);
fbresult::Position maneuverPosition{
static_cast<float>(
util::toFloating(intersection.location.lon).__value),
static_cast<float>(
util::toFloating(intersection.location.lat).__value)};
intersectionBuilder.add_location(&maneuverPosition);
auto bearings_vector =
fb_result.CreateVector(intersection.bearings);
intersectionBuilder.add_bearings(bearings_vector);
std::vector<flatbuffers::Offset<flatbuffers::String>> classes;
classes.resize(intersection.classes.size());
std::transform(intersection.classes.begin(),
intersection.classes.end(),
classes.begin(),
[&fb_result](const std::string cls) {
return fb_result.CreateString(cls);
});
auto classes_vector = fb_result.CreateVector(classes);
intersectionBuilder.add_classes(classes_vector);
auto entry_vector = fb_result.CreateVector(intersection.entry);
intersectionBuilder.add_entry(entry_vector);
intersectionBuilder.add_in(intersection.in);
intersectionBuilder.add_out(intersection.out);
if (api::json::detail::hasValidLanes(intersection))
{
BOOST_ASSERT(intersection.lanes.lanes_in_turn >= 1);
std::vector<flatbuffers::Offset<fbresult::Lane>> lanes;
lanes.resize(intersection.lane_description.size());
LaneID lane_id = intersection.lane_description.size();
for (const auto &lane_desc : intersection.lane_description)
{
--lane_id;
fbresult::LaneBuilder laneBuilder(fb_result);
auto indications_vector =
fb_result.CreateVector(TurnLaneTypeToFB(lane_desc));
laneBuilder.add_indications(indications_vector);
if (lane_id >=
intersection.lanes.first_lane_from_the_right &&
lane_id < intersection.lanes.first_lane_from_the_right +
intersection.lanes.lanes_in_turn)
laneBuilder.add_valid(true);
else
laneBuilder.add_valid(false);
lanes.emplace_back(laneBuilder.Finish());
}
auto lanes_vector = fb_result.CreateVector(lanes);
intersectionBuilder.add_lanes(lanes_vector);
}
return intersectionBuilder.Finish();
});
auto intersections_vector = fb_result.CreateVector(intersections);
stepBuilder.add_intersections(intersections_vector);
return stepBuilder.Finish();
}); });
auto intersections_vector = fb_result.CreateVector(intersections);
stepBuilder.add_intersections(intersections_vector);
return stepBuilder.Finish();
});
auto steps_vector = fb_result.CreateVector(legSteps); auto steps_vector = fb_result.CreateVector(legSteps);
legBuilder.add_steps(steps_vector); legBuilder.add_steps(steps_vector);
} }
//Fill annotations // Fill annotations
// To maintain support for uses of the old default constructors, we check // To maintain support for uses of the old default constructors, we check
// if annotations property was set manually after default construction // if annotations property was set manually after default construction
auto requested_annotations = parameters.annotations_type; auto requested_annotations = parameters.annotations_type;
@ -458,50 +524,53 @@ public:
{ {
double prev_speed = 0; double prev_speed = 0;
auto speed = GetAnnotations<float>( auto speed = GetAnnotations<float>(
fb_result, leg_geometry, [&prev_speed](const guidance::LegGeometry::Annotation &anno) { fb_result,
if (anno.duration < std::numeric_limits<float>::min()) leg_geometry,
{ [&prev_speed](const guidance::LegGeometry::Annotation &anno) {
return prev_speed; if (anno.duration < std::numeric_limits<float>::min())
} {
else return prev_speed;
{ }
auto speed = std::round(anno.distance / anno.duration * 10.) / 10.; else
prev_speed = speed; {
return util::json::clamp_float(speed); auto speed = std::round(anno.distance / anno.duration * 10.) / 10.;
} prev_speed = speed;
}); return util::json::clamp_float(speed);
}
});
annotation.add_speed(speed); annotation.add_speed(speed);
} }
if (requested_annotations & RouteParameters::AnnotationsType::Duration) if (requested_annotations & RouteParameters::AnnotationsType::Duration)
{ {
auto duration = GetAnnotations<uint32_t>( auto duration = GetAnnotations<uint32_t>(
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
return anno.duration; return anno.duration;
}); });
annotation.add_duration(duration); annotation.add_duration(duration);
} }
if (requested_annotations & RouteParameters::AnnotationsType::Distance) if (requested_annotations & RouteParameters::AnnotationsType::Distance)
{ {
auto distance = GetAnnotations<uint32_t>( auto distance = GetAnnotations<uint32_t>(
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
return anno.distance; return anno.distance;
}); });
annotation.add_distance(distance); annotation.add_distance(distance);
} }
if (requested_annotations & RouteParameters::AnnotationsType::Weight) if (requested_annotations & RouteParameters::AnnotationsType::Weight)
{ {
auto weight = GetAnnotations<uint32_t>( auto weight = GetAnnotations<uint32_t>(
fb_result, leg_geometry, fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
[](const guidance::LegGeometry::Annotation &anno) { return anno.weight; }); return anno.weight;
});
annotation.add_weight(weight); annotation.add_weight(weight);
} }
if (requested_annotations & RouteParameters::AnnotationsType::Datasources) if (requested_annotations & RouteParameters::AnnotationsType::Datasources)
{ {
auto datasources = GetAnnotations<uint32_t>( auto datasources = GetAnnotations<uint32_t>(
fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { fb_result, leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
return anno.datasource; return anno.datasource;
}); });
annotation.add_datasources(datasources); annotation.add_datasources(datasources);
} }
if (requested_annotations & RouteParameters::AnnotationsType::Nodes) if (requested_annotations & RouteParameters::AnnotationsType::Nodes)
@ -527,7 +596,8 @@ public:
// Length of 0 indicates the first empty name, so we can stop here // Length of 0 indicates the first empty name, so we can stop here
if (name.size() == 0) if (name.size() == 0)
break; break;
names.emplace_back(fb_result.CreateString(std::string(facade.GetDatasourceName(i)))); names.emplace_back(
fb_result.CreateString(std::string(facade.GetDatasourceName(i))));
} }
auto datasource_names_vector = fb_result.CreateVector(names); auto datasource_names_vector = fb_result.CreateVector(names);
metadata.add_datasource_names(datasource_names_vector); metadata.add_datasource_names(datasource_names_vector);
@ -542,9 +612,10 @@ public:
auto legs_vector = fb_result.CreateVector(routeLegs); auto legs_vector = fb_result.CreateVector(routeLegs);
routeObject.add_legs(legs_vector); routeObject.add_legs(legs_vector);
//Fill geometry // Fill geometry
auto overview = MakeOverview(leg_geometries); auto overview = MakeOverview(leg_geometries);
if(overview) { if (overview)
{
MakeGeometry(routeObject, overview->begin(), overview->end()); MakeGeometry(routeObject, overview->begin(), overview->end());
} }
@ -556,12 +627,16 @@ public:
const std::vector<bool> &source_traversed_in_reverse, const std::vector<bool> &source_traversed_in_reverse,
const std::vector<bool> &target_traversed_in_reverse) const const std::vector<bool> &target_traversed_in_reverse) const
{ {
auto legs_info = MakeLegs(segment_end_coordinates, unpacked_path_segments, source_traversed_in_reverse, target_traversed_in_reverse); auto legs_info = MakeLegs(segment_end_coordinates,
unpacked_path_segments,
source_traversed_in_reverse,
target_traversed_in_reverse);
std::vector<guidance::RouteLeg> legs = legs_info.first; std::vector<guidance::RouteLeg> legs = legs_info.first;
std::vector<guidance::LegGeometry> leg_geometries = legs_info.second; std::vector<guidance::LegGeometry> leg_geometries = legs_info.second;
auto route = guidance::assembleRoute(legs); auto route = guidance::assembleRoute(legs);
boost::optional<util::json::Value> json_overview = MakeGeometry(MakeOverview(leg_geometries)); boost::optional<util::json::Value> json_overview =
MakeGeometry(MakeOverview(leg_geometries));
std::vector<util::json::Value> step_geometries; std::vector<util::json::Value> step_geometries;
const auto total_step_count = const auto total_step_count =
@ -712,10 +787,12 @@ public:
MakeLegs(const std::vector<PhantomNodes> &segment_end_coordinates, MakeLegs(const std::vector<PhantomNodes> &segment_end_coordinates,
const std::vector<std::vector<PathData>> &unpacked_path_segments, const std::vector<std::vector<PathData>> &unpacked_path_segments,
const std::vector<bool> &source_traversed_in_reverse, const std::vector<bool> &source_traversed_in_reverse,
const std::vector<bool> &target_traversed_in_reverse) const { const std::vector<bool> &target_traversed_in_reverse) const
auto result = std::make_pair(std::vector<guidance::RouteLeg>(), std::vector<guidance::LegGeometry>()); {
auto& legs = result.first; auto result =
auto& leg_geometries = result.second; std::make_pair(std::vector<guidance::RouteLeg>(), std::vector<guidance::LegGeometry>());
auto &legs = result.first;
auto &leg_geometries = result.second;
auto number_of_legs = segment_end_coordinates.size(); auto number_of_legs = segment_end_coordinates.size();
legs.reserve(number_of_legs); legs.reserve(number_of_legs);
leg_geometries.reserve(number_of_legs); leg_geometries.reserve(number_of_legs);
@ -811,12 +888,14 @@ public:
return result; return result;
} }
boost::optional<std::vector<Coordinate>> MakeOverview(const std::vector<guidance::LegGeometry>& leg_geometries) const { boost::optional<std::vector<Coordinate>>
MakeOverview(const std::vector<guidance::LegGeometry> &leg_geometries) const
{
boost::optional<std::vector<Coordinate>> overview; boost::optional<std::vector<Coordinate>> overview;
if (parameters.overview != RouteParameters::OverviewType::False) if (parameters.overview != RouteParameters::OverviewType::False)
{ {
const auto use_simplification = const auto use_simplification =
parameters.overview == RouteParameters::OverviewType::Simplified; parameters.overview == RouteParameters::OverviewType::Simplified;
BOOST_ASSERT(use_simplification || BOOST_ASSERT(use_simplification ||
parameters.overview == RouteParameters::OverviewType::Full); parameters.overview == RouteParameters::OverviewType::Full);

View File

@ -51,13 +51,14 @@ class TableAPI final : public BaseAPI
const std::vector<TableCellRef> &fallback_speed_cells, const std::vector<TableCellRef> &fallback_speed_cells,
osrm::engine::api::ResultT &response) const osrm::engine::api::ResultT &response) const
{ {
if(response.is<flatbuffers::FlatBufferBuilder>()) { if (response.is<flatbuffers::FlatBufferBuilder>())
auto& fb_result = response.get<flatbuffers::FlatBufferBuilder>(); {
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
MakeResponse(tables, phantoms, fallback_speed_cells, fb_result); MakeResponse(tables, phantoms, fallback_speed_cells, fb_result);
} }
else else
{ {
auto& json_result = response.get<util::json::Object>(); auto &json_result = response.get<util::json::Object>();
MakeResponse(tables, phantoms, fallback_speed_cells, json_result); MakeResponse(tables, phantoms, fallback_speed_cells, json_result);
} }
} }
@ -66,7 +67,8 @@ class TableAPI final : public BaseAPI
MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables, MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables,
const std::vector<PhantomNode> &phantoms, const std::vector<PhantomNode> &phantoms,
const std::vector<TableCellRef> &fallback_speed_cells, const std::vector<TableCellRef> &fallback_speed_cells,
flatbuffers::FlatBufferBuilder &fb_result) const { flatbuffers::FlatBufferBuilder &fb_result) const
{
auto number_of_sources = parameters.sources.size(); auto number_of_sources = parameters.sources.size();
auto number_of_destinations = parameters.destinations.size(); auto number_of_destinations = parameters.destinations.size();
@ -169,21 +171,22 @@ class TableAPI final : public BaseAPI
protected: protected:
virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
MakeWaypoints(flatbuffers::FlatBufferBuilder& builder, const std::vector<PhantomNode> &phantoms) const MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
const std::vector<PhantomNode> &phantoms) const
{ {
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints; std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.reserve(phantoms.size()); waypoints.reserve(phantoms.size());
BOOST_ASSERT(phantoms.size() == parameters.coordinates.size()); BOOST_ASSERT(phantoms.size() == parameters.coordinates.size());
boost::range::transform( boost::range::transform(
phantoms, phantoms, std::back_inserter(waypoints), [this, &builder](const PhantomNode &phantom) {
std::back_inserter(waypoints), return BaseAPI::MakeWaypoint(builder, phantom).Finish();
[this, &builder](const PhantomNode &phantom) { return BaseAPI::MakeWaypoint(builder, phantom).Finish(); }); });
return builder.CreateVector(waypoints); return builder.CreateVector(waypoints);
} }
virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
MakeWaypoints(flatbuffers::FlatBufferBuilder& builder, MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
const std::vector<PhantomNode> &phantoms, const std::vector<PhantomNode> &phantoms,
const std::vector<std::size_t> &indices) const const std::vector<std::size_t> &indices) const
{ {
@ -199,49 +202,53 @@ class TableAPI final : public BaseAPI
} }
virtual flatbuffers::Offset<flatbuffers::Vector<float>> virtual flatbuffers::Offset<flatbuffers::Vector<float>>
MakeDurationTable(flatbuffers::FlatBufferBuilder& builder, MakeDurationTable(flatbuffers::FlatBufferBuilder &builder,
const std::vector<EdgeWeight> &values) const const std::vector<EdgeWeight> &values) const
{ {
std::vector<float> distance_table; std::vector<float> distance_table;
distance_table.resize(values.size()); distance_table.resize(values.size());
std::transform(values.begin(), values.end(), distance_table.begin(), [](const EdgeWeight duration) { std::transform(
if (duration == MAXIMAL_EDGE_DURATION) { values.begin(), values.end(), distance_table.begin(), [](const EdgeWeight duration) {
return 0.; if (duration == MAXIMAL_EDGE_DURATION)
} {
return duration / 10.; return 0.;
}); }
return duration / 10.;
});
return builder.CreateVector(distance_table); return builder.CreateVector(distance_table);
} }
virtual flatbuffers::Offset<flatbuffers::Vector<float>> virtual flatbuffers::Offset<flatbuffers::Vector<float>>
MakeDistanceTable(flatbuffers::FlatBufferBuilder& builder, MakeDistanceTable(flatbuffers::FlatBufferBuilder &builder,
const std::vector<EdgeDistance> &values) const const std::vector<EdgeDistance> &values) const
{ {
std::vector<float> duration_table; std::vector<float> duration_table;
duration_table.resize(values.size()); duration_table.resize(values.size());
std::transform(values.begin(), values.end(), duration_table.begin(), [](const EdgeDistance distance) { std::transform(
if (distance == INVALID_EDGE_DISTANCE) { values.begin(), values.end(), duration_table.begin(), [](const EdgeDistance distance) {
return 0.; if (distance == INVALID_EDGE_DISTANCE)
} {
return std::round(distance * 10) / 10.; return 0.;
}); }
return std::round(distance * 10) / 10.;
});
return builder.CreateVector(duration_table); return builder.CreateVector(duration_table);
} }
virtual flatbuffers::Offset<flatbuffers::Vector<uint32_t>> virtual flatbuffers::Offset<flatbuffers::Vector<uint32_t>>
MakeEstimatesTable(flatbuffers::FlatBufferBuilder& builder, const std::vector<TableCellRef> &fallback_speed_cells) const MakeEstimatesTable(flatbuffers::FlatBufferBuilder &builder,
const std::vector<TableCellRef> &fallback_speed_cells) const
{ {
std::vector<uint32_t> fb_table; std::vector<uint32_t> fb_table;
fb_table.reserve(fallback_speed_cells.size()); fb_table.reserve(fallback_speed_cells.size());
std::for_each( std::for_each(
fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) { fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) {
fb_table.push_back(cell.row); fb_table.push_back(cell.row);
fb_table.push_back(cell.column); fb_table.push_back(cell.column);
}); });
return builder.CreateVector(fb_table); return builder.CreateVector(fb_table);
} }
virtual util::json::Array MakeWaypoints(const std::vector<PhantomNode> &phantoms) const virtual util::json::Array MakeWaypoints(const std::vector<PhantomNode> &phantoms) const
{ {
util::json::Array json_waypoints; util::json::Array json_waypoints;

View File

@ -31,21 +31,26 @@ class TripAPI final : public RouteAPI
{ {
BOOST_ASSERT(sub_trips.size() == sub_routes.size()); BOOST_ASSERT(sub_trips.size() == sub_routes.size());
if (response.is<flatbuffers::FlatBufferBuilder>()) { if (response.is<flatbuffers::FlatBufferBuilder>())
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>(); auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
MakeResponse(sub_trips, sub_routes, phantoms, fb_result); MakeResponse(sub_trips, sub_routes, phantoms, fb_result);
} else { }
else
{
auto &json_result = response.get<util::json::Object>(); auto &json_result = response.get<util::json::Object>();
MakeResponse(sub_trips, sub_routes, phantoms, json_result); MakeResponse(sub_trips, sub_routes, phantoms, json_result);
} }
} }
void MakeResponse(const std::vector<std::vector<NodeID>> &sub_trips, void MakeResponse(const std::vector<std::vector<NodeID>> &sub_trips,
const std::vector<InternalRouteResult> &sub_routes, const std::vector<InternalRouteResult> &sub_routes,
const std::vector<PhantomNode> &phantoms, const std::vector<PhantomNode> &phantoms,
flatbuffers::FlatBufferBuilder &fb_result) const flatbuffers::FlatBufferBuilder &fb_result) const
{ {
auto response = MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_trips, &phantoms]() { return MakeWaypoints(fb_result, sub_trips, phantoms); }); auto response =
MakeFBResponse(sub_routes, fb_result, [this, &fb_result, &sub_trips, &phantoms]() {
return MakeWaypoints(fb_result, sub_trips, phantoms);
});
fb_result.Finish(response.Finish()); fb_result.Finish(response.Finish());
} }
@ -74,25 +79,29 @@ class TripAPI final : public RouteAPI
// FIXME this logic is a little backwards. We should change the output format of the // FIXME this logic is a little backwards. We should change the output format of the
// trip plugin routing algorithm to be easier to consume here. // trip plugin routing algorithm to be easier to consume here.
struct TripIndex { struct TripIndex
{
TripIndex() = default; TripIndex() = default;
TripIndex(unsigned sub_trip_index_, unsigned point_index_) TripIndex(unsigned sub_trip_index_, unsigned point_index_)
: sub_trip_index(sub_trip_index_), point_index(point_index_) { : sub_trip_index(sub_trip_index_), point_index(point_index_)
{
} }
unsigned sub_trip_index = std::numeric_limits<unsigned>::max(); unsigned sub_trip_index = std::numeric_limits<unsigned>::max();
unsigned point_index = std::numeric_limits<unsigned>::max(); unsigned point_index = std::numeric_limits<unsigned>::max();
bool NotUsed() { bool NotUsed()
{
return sub_trip_index == std::numeric_limits<unsigned>::max() && return sub_trip_index == std::numeric_limits<unsigned>::max() &&
point_index == std::numeric_limits<unsigned>::max(); point_index == std::numeric_limits<unsigned>::max();
} }
}; };
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> MakeWaypoints(flatbuffers::FlatBufferBuilder &fb_result, flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
const std::vector<std::vector<NodeID>> &sub_trips, MakeWaypoints(flatbuffers::FlatBufferBuilder &fb_result,
const std::vector<PhantomNode> &phantoms) const const std::vector<std::vector<NodeID>> &sub_trips,
const std::vector<PhantomNode> &phantoms) const
{ {
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints; std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.reserve(parameters.coordinates.size()); waypoints.reserve(parameters.coordinates.size());
@ -135,13 +144,15 @@ class TripAPI final : public RouteAPI
return waypoints; return waypoints;
} }
std::vector<TripIndex> std::vector<TripIndex> MakeTripIndices(const std::vector<std::vector<NodeID>> &sub_trips) const
MakeTripIndices(const std::vector<std::vector<NodeID>> &sub_trips) const { {
std::vector<TripIndex> input_idx_to_trip_idx(parameters.coordinates.size()); std::vector<TripIndex> input_idx_to_trip_idx(parameters.coordinates.size());
for (auto sub_trip_index : util::irange<unsigned>(0u, sub_trips.size())) { for (auto sub_trip_index : util::irange<unsigned>(0u, sub_trips.size()))
for (auto point_index : util::irange<unsigned>(0u, sub_trips[sub_trip_index].size())) { {
for (auto point_index : util::irange<unsigned>(0u, sub_trips[sub_trip_index].size()))
{
input_idx_to_trip_idx[sub_trips[sub_trip_index][point_index]] = input_idx_to_trip_idx[sub_trips[sub_trip_index][point_index]] =
TripIndex{sub_trip_index, point_index}; TripIndex{sub_trip_index, point_index};
} }
} }
return input_idx_to_trip_idx; return input_idx_to_trip_idx;

View File

@ -32,18 +32,13 @@ class EngineInterface
{ {
public: public:
virtual ~EngineInterface() = default; virtual ~EngineInterface() = default;
virtual Status Route(const api::RouteParameters &parameters, virtual Status Route(const api::RouteParameters &parameters, api::ResultT &result) const = 0;
api::ResultT &result) const = 0; virtual Status Table(const api::TableParameters &parameters, api::ResultT &result) const = 0;
virtual Status Table(const api::TableParameters &parameters,
api::ResultT &result) const = 0;
virtual Status Nearest(const api::NearestParameters &parameters, virtual Status Nearest(const api::NearestParameters &parameters,
api::ResultT &result) const = 0; api::ResultT &result) const = 0;
virtual Status Trip(const api::TripParameters &parameters, virtual Status Trip(const api::TripParameters &parameters, api::ResultT &result) const = 0;
api::ResultT &result) const = 0; virtual Status Match(const api::MatchParameters &parameters, api::ResultT &result) const = 0;
virtual Status Match(const api::MatchParameters &parameters, virtual Status Tile(const api::TileParameters &parameters, api::ResultT &result) const = 0;
api::ResultT &result) const = 0;
virtual Status Tile(const api::TileParameters &parameters,
api::ResultT &result) const = 0;
}; };
template <typename Algorithm> class Engine final : public EngineInterface template <typename Algorithm> class Engine final : public EngineInterface
@ -90,38 +85,32 @@ template <typename Algorithm> class Engine final : public EngineInterface
Engine &operator=(const Engine &) = delete; Engine &operator=(const Engine &) = delete;
virtual ~Engine() = default; virtual ~Engine() = default;
Status Route(const api::RouteParameters &params, Status Route(const api::RouteParameters &params, api::ResultT &result) const override final
api::ResultT &result) const override final
{ {
return route_plugin.HandleRequest(GetAlgorithms(params), params, result); return route_plugin.HandleRequest(GetAlgorithms(params), params, result);
} }
Status Table(const api::TableParameters &params, Status Table(const api::TableParameters &params, api::ResultT &result) const override final
api::ResultT &result) const override final
{ {
return table_plugin.HandleRequest(GetAlgorithms(params), params, result); return table_plugin.HandleRequest(GetAlgorithms(params), params, result);
} }
Status Nearest(const api::NearestParameters &params, Status Nearest(const api::NearestParameters &params, api::ResultT &result) const override final
api::ResultT &result) const override final
{ {
return nearest_plugin.HandleRequest(GetAlgorithms(params), params, result); return nearest_plugin.HandleRequest(GetAlgorithms(params), params, result);
} }
Status Trip(const api::TripParameters &params, Status Trip(const api::TripParameters &params, api::ResultT &result) const override final
api::ResultT &result) const override final
{ {
return trip_plugin.HandleRequest(GetAlgorithms(params), params, result); return trip_plugin.HandleRequest(GetAlgorithms(params), params, result);
} }
Status Match(const api::MatchParameters &params, Status Match(const api::MatchParameters &params, api::ResultT &result) const override final
api::ResultT &result) const override final
{ {
return match_plugin.HandleRequest(GetAlgorithms(params), params, result); return match_plugin.HandleRequest(GetAlgorithms(params), params, result);
} }
Status Tile(const api::TileParameters &params, Status Tile(const api::TileParameters &params, api::ResultT &result) const override final
api::ResultT &result) const override final
{ {
return tile_plugin.HandleRequest(GetAlgorithms(params), params, result); return tile_plugin.HandleRequest(GetAlgorithms(params), params, result);
} }

View File

@ -64,17 +64,21 @@ class BasePlugin
return false; return false;
} }
struct ErrorRenderer { struct ErrorRenderer
{
std::string code; std::string code;
std::string message; std::string message;
ErrorRenderer(std::string code, std::string message) : code(std::move(code)), message(std::move(message)) {}; ErrorRenderer(std::string code, std::string message)
: code(std::move(code)), message(std::move(message)){};
void operator()(util::json::Object& json_result) { void operator()(util::json::Object &json_result)
{
json_result.values["code"] = code; json_result.values["code"] = code;
json_result.values["message"] = message; json_result.values["message"] = message;
}; };
void operator()(flatbuffers::FlatBufferBuilder& fb_result) { void operator()(flatbuffers::FlatBufferBuilder &fb_result)
{
api::fbresult::FBResultBuilder error(fb_result); api::fbresult::FBResultBuilder error(fb_result);
error.add_error(true); error.add_error(true);
@ -84,7 +88,8 @@ class BasePlugin
error.add_code(codeBuilder.Finish()); error.add_code(codeBuilder.Finish());
fb_result.Finish(error.Finish()); fb_result.Finish(error.Finish());
}; };
void operator()(std::string& str_result) { void operator()(std::string &str_result)
{
str_result = str(boost::format("code=%1% message=%2%") % code % message); str_result = str(boost::format("code=%1% message=%2%") % code % message);
}; };
}; };

View File

@ -28,9 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef OSRM_HPP #ifndef OSRM_HPP
#define OSRM_HPP #define OSRM_HPP
#include "engine/api/base_result.hpp"
#include "osrm/osrm_fwd.hpp" #include "osrm/osrm_fwd.hpp"
#include "osrm/status.hpp" #include "osrm/status.hpp"
#include "engine/api/base_result.hpp"
#include <memory> #include <memory>
#include <string> #include <string>

View File

@ -169,10 +169,11 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar<Iterator, Signature>
qi::lit("snapping=") > qi::lit("snapping=") >
snapping_type[ph::bind(&engine::api::BaseParameters::snapping, qi::_r1) = qi::_1]; snapping_type[ph::bind(&engine::api::BaseParameters::snapping, qi::_r1) = qi::_1];
format_type.add(".json", engine::api::BaseParameters::OutputFormatType::JSON) format_type.add(".json", engine::api::BaseParameters::OutputFormatType::JSON)(
(".flatbuffers", engine::api::BaseParameters::OutputFormatType::FLATBUFFERS); ".flatbuffers", engine::api::BaseParameters::OutputFormatType::FLATBUFFERS);
format_rule = -format_type[ph::bind(&engine::api::BaseParameters::format, qi::_r1) = qi::_1]; format_rule =
-format_type[ph::bind(&engine::api::BaseParameters::format, qi::_r1) = qi::_1];
exclude_rule = qi::lit("exclude=") > exclude_rule = qi::lit("exclude=") >
(qi::as_string[+qi::char_("a-zA-Z0-9")] % (qi::as_string[+qi::char_("a-zA-Z0-9")] %

View File

@ -22,8 +22,9 @@ class MatchService final : public BaseService
public: public:
MatchService(OSRM &routing_machine) : BaseService(routing_machine) {} MatchService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status engine::Status RunQuery(std::size_t prefix_length,
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; std::string &query,
osrm::engine::api::ResultT &result) final override;
unsigned GetVersion() final override { return 1; } unsigned GetVersion() final override { return 1; }
}; };

View File

@ -22,8 +22,9 @@ class NearestService final : public BaseService
public: public:
NearestService(OSRM &routing_machine) : BaseService(routing_machine) {} NearestService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status engine::Status RunQuery(std::size_t prefix_length,
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; std::string &query,
osrm::engine::api::ResultT &result) final override;
unsigned GetVersion() final override { return 1; } unsigned GetVersion() final override { return 1; }
}; };

View File

@ -22,8 +22,9 @@ class RouteService final : public BaseService
public: public:
RouteService(OSRM &routing_machine) : BaseService(routing_machine) {} RouteService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status engine::Status RunQuery(std::size_t prefix_length,
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; std::string &query,
osrm::engine::api::ResultT &result) final override;
unsigned GetVersion() final override { return 1; } unsigned GetVersion() final override { return 1; }
}; };

View File

@ -22,8 +22,9 @@ class TableService final : public BaseService
public: public:
TableService(OSRM &routing_machine) : BaseService(routing_machine) {} TableService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status engine::Status RunQuery(std::size_t prefix_length,
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; std::string &query,
osrm::engine::api::ResultT &result) final override;
unsigned GetVersion() final override { return 1; } unsigned GetVersion() final override { return 1; }
}; };

View File

@ -22,8 +22,9 @@ class TileService final : public BaseService
public: public:
TileService(OSRM &routing_machine) : BaseService(routing_machine) {} TileService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status engine::Status RunQuery(std::size_t prefix_length,
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; std::string &query,
osrm::engine::api::ResultT &result) final override;
unsigned GetVersion() final override { return 1; } unsigned GetVersion() final override { return 1; }
}; };

View File

@ -22,8 +22,9 @@ class TripService final : public BaseService
public: public:
TripService(OSRM &routing_machine) : BaseService(routing_machine) {} TripService(OSRM &routing_machine) : BaseService(routing_machine) {}
engine::Status engine::Status RunQuery(std::size_t prefix_length,
RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) final override; std::string &query,
osrm::engine::api::ResultT &result) final override;
unsigned GetVersion() final override { return 1; } unsigned GetVersion() final override { return 1; }
}; };

View File

@ -3,8 +3,8 @@
#include "server/service/base_service.hpp" #include "server/service/base_service.hpp"
#include "osrm/osrm.hpp"
#include "engine/api/base_api.hpp" #include "engine/api/base_api.hpp"
#include "osrm/osrm.hpp"
#include <unordered_map> #include <unordered_map>

View File

@ -216,8 +216,9 @@ int main(int argc, const char *argv[]) try
{ {
engine::api::ResultT result = json::Object(); engine::api::ResultT result = json::Object();
const auto rc = osrm.Match(params, result); const auto rc = osrm.Match(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
if (rc != Status::Ok || json_result.values.at("matchings").get<json::Array>().values.size() != 1) if (rc != Status::Ok ||
json_result.values.at("matchings").get<json::Array>().values.size() != 1)
{ {
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -158,8 +158,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
if (!time_increases_monotonically) if (!time_increases_monotonically)
{ {
return Error( return Error("InvalidValue", "Timestamps need to be monotonically increasing.", result);
"InvalidValue", "Timestamps need to be monotonically increasing.", result);
} }
SubMatchingList sub_matchings; SubMatchingList sub_matchings;
@ -180,9 +179,8 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
(tidied.parameters.waypoints[0] != 0 || (tidied.parameters.waypoints[0] != 0 ||
tidied.parameters.waypoints.back() != (tidied.parameters.coordinates.size() - 1))) tidied.parameters.waypoints.back() != (tidied.parameters.coordinates.size() - 1)))
{ {
return Error("InvalidValue", return Error(
"First and last coordinates must be specified as waypoints.", "InvalidValue", "First and last coordinates must be specified as waypoints.", result);
result);
} }
// assuming radius is the standard deviation of a normal distribution // assuming radius is the standard deviation of a normal distribution
@ -260,8 +258,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
} }
if (!tidied_waypoints.empty()) if (!tidied_waypoints.empty())
{ {
return Error( return Error("NoMatch", "Requested waypoint parameter could not be matched.", result);
"NoMatch", "Requested waypoint parameter could not be matched.", result);
} }
} }
// we haven't errored yet, only allow leg collapsing if it was originally requested // we haven't errored yet, only allow leg collapsing if it was originally requested

View File

@ -669,7 +669,7 @@ Status TilePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
{ {
BOOST_ASSERT(parameters.IsValid()); BOOST_ASSERT(parameters.IsValid());
auto& pbf_buffer = result.get<std::string>(); auto &pbf_buffer = result.get<std::string>();
const auto &facade = algorithms.GetFacade(); const auto &facade = algorithms.GetFacade();
auto edges = getEdges(facade, parameters.x, parameters.y, parameters.z); auto edges = getEdges(facade, parameters.x, parameters.y, parameters.z);
auto segregated_nodes = getSegregatedNodes(facade, edges); auto segregated_nodes = getSegregatedNodes(facade, edges);

View File

@ -78,9 +78,8 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
(route_parameters.waypoints[0] != 0 || (route_parameters.waypoints[0] != 0 ||
route_parameters.waypoints.back() != (route_parameters.coordinates.size() - 1))) route_parameters.waypoints.back() != (route_parameters.coordinates.size() - 1)))
{ {
return Error("InvalidValue", return Error(
"First and last coordinates must be specified as waypoints.", "InvalidValue", "First and last coordinates must be specified as waypoints.", result);
result);
} }
if (!CheckAlgorithms(route_parameters, algorithms, result)) if (!CheckAlgorithms(route_parameters, algorithms, result))

View File

@ -152,7 +152,7 @@ inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
void Execute() override try void Execute() override try
{ {
osrm::engine::api::ResultT r; osrm::engine::api::ResultT r;
r=osrm::util::json::Object(); r = osrm::util::json::Object();
const auto status = ((*osrm).*(service))(*params, r); const auto status = ((*osrm).*(service))(*params, r);
auto json_result = r.get<osrm::json::Object>(); auto json_result = r.get<osrm::json::Object>();
ParseResult(status, json_result); ParseResult(status, json_result);

View File

@ -110,15 +110,16 @@ void RequestHandler::HandleRequest(const http::request &current_request, http::r
util::json::render(current_reply.content, result.get<util::json::Object>()); util::json::render(current_reply.content, result.get<util::json::Object>());
} }
else if(result.is<flatbuffers::FlatBufferBuilder>()) else if (result.is<flatbuffers::FlatBufferBuilder>())
{ {
auto& buffer = result.get<flatbuffers::FlatBufferBuilder>(); auto &buffer = result.get<flatbuffers::FlatBufferBuilder>();
current_reply.content.resize(buffer.GetSize()); current_reply.content.resize(buffer.GetSize());
std::copy(buffer.GetBufferPointer(), std::copy(buffer.GetBufferPointer(),
buffer.GetBufferPointer() + buffer.GetSize(), buffer.GetBufferPointer() + buffer.GetSize(),
current_reply.content.begin()); current_reply.content.begin());
current_reply.headers.emplace_back("Content-Type", "application/x-flatbuffers;schema=osrm.engine.api.fbresult"); current_reply.headers.emplace_back(
"Content-Type", "application/x-flatbuffers;schema=osrm.engine.api.fbresult");
} }
else else
{ {

View File

@ -41,8 +41,9 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status engine::Status MatchService::RunQuery(std::size_t prefix_length,
MatchService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) std::string &query,
osrm::engine::api::ResultT &result)
{ {
result = util::json::Object(); result = util::json::Object();
auto &json_result = result.get<util::json::Object>(); auto &json_result = result.get<util::json::Object>();
@ -70,7 +71,8 @@ MatchService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engi
if (parameters->format) if (parameters->format)
{ {
if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS) { if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS)
{
result = flatbuffers::FlatBufferBuilder(); result = flatbuffers::FlatBufferBuilder();
} }
} }

View File

@ -35,8 +35,9 @@ std::string getWrongOptionHelp(const engine::api::NearestParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status engine::Status NearestService::RunQuery(std::size_t prefix_length,
NearestService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) std::string &query,
osrm::engine::api::ResultT &result)
{ {
result = util::json::Object(); result = util::json::Object();
auto &json_result = result.get<util::json::Object>(); auto &json_result = result.get<util::json::Object>();
@ -64,7 +65,8 @@ NearestService::RunQuery(std::size_t prefix_length, std::string &query, osrm::en
if (parameters->format) if (parameters->format)
{ {
if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS) { if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS)
{
result = flatbuffers::FlatBufferBuilder(); result = flatbuffers::FlatBufferBuilder();
} }
} }

View File

@ -39,8 +39,9 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status engine::Status RouteService::RunQuery(std::size_t prefix_length,
RouteService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) std::string &query,
osrm::engine::api::ResultT &result)
{ {
result = util::json::Object(); result = util::json::Object();
auto &json_result = result.get<util::json::Object>(); auto &json_result = result.get<util::json::Object>();
@ -68,7 +69,8 @@ RouteService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engi
if (parameters->format) if (parameters->format)
{ {
if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS) { if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS)
{
result = flatbuffers::FlatBufferBuilder(); result = flatbuffers::FlatBufferBuilder();
} }
} }

View File

@ -70,8 +70,9 @@ std::string getWrongOptionHelp(const engine::api::TableParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status engine::Status TableService::RunQuery(std::size_t prefix_length,
TableService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) std::string &query,
osrm::engine::api::ResultT &result)
{ {
result = util::json::Object(); result = util::json::Object();
auto &json_result = result.get<util::json::Object>(); auto &json_result = result.get<util::json::Object>();
@ -99,7 +100,8 @@ TableService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engi
if (parameters->format) if (parameters->format)
{ {
if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS) { if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS)
{
result = flatbuffers::FlatBufferBuilder(); result = flatbuffers::FlatBufferBuilder();
} }
} }

View File

@ -15,7 +15,9 @@ namespace server
namespace service namespace service
{ {
engine::Status TileService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) engine::Status TileService::RunQuery(std::size_t prefix_length,
std::string &query,
osrm::engine::api::ResultT &result)
{ {
auto query_iterator = query.begin(); auto query_iterator = query.begin();
auto parameters = auto parameters =

View File

@ -41,7 +41,9 @@ std::string getWrongOptionHelp(const engine::api::TripParameters &parameters)
} }
} // anon. ns } // anon. ns
engine::Status TripService::RunQuery(std::size_t prefix_length, std::string &query, osrm::engine::api::ResultT &result) engine::Status TripService::RunQuery(std::size_t prefix_length,
std::string &query,
osrm::engine::api::ResultT &result)
{ {
result = util::json::Object(); result = util::json::Object();
auto &json_result = result.get<util::json::Object>(); auto &json_result = result.get<util::json::Object>();
@ -71,7 +73,8 @@ engine::Status TripService::RunQuery(std::size_t prefix_length, std::string &que
if (parameters->format) if (parameters->format)
{ {
if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS) { if (parameters->format == engine::api::BaseParameters::OutputFormatType::FLATBUFFERS)
{
result = flatbuffers::FlatBufferBuilder(); result = flatbuffers::FlatBufferBuilder();
} }
} }

View File

@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(test_trip_limits)
BOOST_CHECK(rc == Status::Error); BOOST_CHECK(rc == Status::Error);
// Make sure we're not accidentally hitting a guard code path before // Make sure we're not accidentally hitting a guard code path before
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values["code"].get<json::String>().value; const auto code = json_result.values["code"].get<json::String>().value;
BOOST_CHECK(code == "TooBig"); // per the New-Server API spec BOOST_CHECK(code == "TooBig"); // per the New-Server API spec
} }
@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(test_route_limits)
BOOST_CHECK(rc == Status::Error); BOOST_CHECK(rc == Status::Error);
// Make sure we're not accidentally hitting a guard code path before // Make sure we're not accidentally hitting a guard code path before
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values["code"].get<json::String>().value; const auto code = json_result.values["code"].get<json::String>().value;
BOOST_CHECK(code == "TooBig"); // per the New-Server API spec BOOST_CHECK(code == "TooBig"); // per the New-Server API spec
} }
@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(test_table_limits)
BOOST_CHECK(rc == Status::Error); BOOST_CHECK(rc == Status::Error);
// Make sure we're not accidentally hitting a guard code path before // Make sure we're not accidentally hitting a guard code path before
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values["code"].get<json::String>().value; const auto code = json_result.values["code"].get<json::String>().value;
BOOST_CHECK(code == "TooBig"); // per the New-Server API spec BOOST_CHECK(code == "TooBig"); // per the New-Server API spec
} }
@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(test_match_coordinate_limits)
BOOST_CHECK(rc == Status::Error); BOOST_CHECK(rc == Status::Error);
// Make sure we're not accidentally hitting a guard code path before // Make sure we're not accidentally hitting a guard code path before
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values["code"].get<json::String>().value; const auto code = json_result.values["code"].get<json::String>().value;
BOOST_CHECK(code == "TooBig"); // per the New-Server API spec BOOST_CHECK(code == "TooBig"); // per the New-Server API spec
} }
@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(test_match_radiuses_limits)
BOOST_CHECK(rc == Status::Error); BOOST_CHECK(rc == Status::Error);
// Make sure we're not accidentally hitting a guard code path before // Make sure we're not accidentally hitting a guard code path before
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values["code"].get<json::String>().value; const auto code = json_result.values["code"].get<json::String>().value;
BOOST_CHECK(code == "TooBig"); // per the New-Server API spec BOOST_CHECK(code == "TooBig"); // per the New-Server API spec
} }
@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(test_nearest_limits)
BOOST_CHECK(rc == Status::Error); BOOST_CHECK(rc == Status::Error);
// Make sure we're not accidentally hitting a guard code path before // Make sure we're not accidentally hitting a guard code path before
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values["code"].get<json::String>().value; const auto code = json_result.values["code"].get<json::String>().value;
BOOST_CHECK(code == "TooBig"); // per the New-Server API spec BOOST_CHECK(code == "TooBig"); // per the New-Server API spec
} }

View File

@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(test_match)
const auto rc = osrm.Match(params, result); const auto rc = osrm.Match(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error); BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(test_match_split)
const auto rc = osrm.Match(params, result); const auto rc = osrm.Match(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error); BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");

View File

@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(test_nearest_response)
const auto rc = osrm.Nearest(params, result); const auto rc = osrm.Nearest(params, result);
BOOST_REQUIRE(rc == Status::Ok); BOOST_REQUIRE(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates)
const auto rc = osrm.Nearest(params, result); const auto rc = osrm.Nearest(params, result);
BOOST_REQUIRE(rc == Status::Error); BOOST_REQUIRE(rc == Status::Error);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "InvalidOptions"); BOOST_CHECK_EQUAL(code, "InvalidOptions");
} }
@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates)
const auto rc = osrm.Nearest(params, result); const auto rc = osrm.Nearest(params, result);
BOOST_REQUIRE(rc == Status::Error); BOOST_REQUIRE(rc == Status::Error);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "InvalidOptions"); BOOST_CHECK_EQUAL(code, "InvalidOptions");
} }
@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component)
const auto rc = osrm.Nearest(params, result); const auto rc = osrm.Nearest(params, result);
BOOST_REQUIRE(rc == Status::Ok); BOOST_REQUIRE(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");

View File

@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
// unset snapping dependent hint // unset snapping dependent hint
for (auto &itr : json_result.values["waypoints"].get<json::Array>().values) for (auto &itr : json_result.values["waypoints"].get<json::Array>().values)
{ {
@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -322,7 +322,7 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -395,7 +395,7 @@ BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
for (auto waypoint : json_result.values["waypoints"].get<json::Array>().values) for (auto waypoint : json_result.values["waypoints"].get<json::Array>().values)
BOOST_CHECK_EQUAL(waypoint.get<json::Object>().values.count("hint"), 0); BOOST_CHECK_EQUAL(waypoint.get<json::Object>().values.count("hint"), 0);
} }
@ -417,7 +417,7 @@ BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto &routes = json_result.values["routes"].get<json::Array>().values; const auto &routes = json_result.values["routes"].get<json::Array>().values;
const auto &legs = routes[0].get<json::Object>().values.at("legs").get<json::Array>().values; const auto &legs = routes[0].get<json::Object>().values.at("legs").get<json::Array>().values;
const auto &annotation = const auto &annotation =
@ -458,7 +458,7 @@ BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property)
const auto rc = osrm.Route(params, result); const auto rc = osrm.Route(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");

View File

@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
const auto rc = osrm.Table(params, result); const auto rc = osrm.Table(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error); BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -61,7 +61,8 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
} }
// check destinations array of waypoint objects // check destinations array of waypoint objects
const auto &destinations_array = json_result.values.at("destinations").get<json::Array>().values; const auto &destinations_array =
json_result.values.at("destinations").get<json::Array>().values;
BOOST_CHECK_EQUAL(destinations_array.size(), params.destinations.size()); BOOST_CHECK_EQUAL(destinations_array.size(), params.destinations.size());
for (const auto &destination : destinations_array) for (const auto &destination : destinations_array)
{ {
@ -91,7 +92,7 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
const auto rc = osrm.Table(params, result); const auto rc = osrm.Table(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error); BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -108,7 +109,8 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
params.sources.size() * params.coordinates.size()); params.sources.size() * params.coordinates.size());
} }
// check destinations array of waypoint objects // check destinations array of waypoint objects
const auto &destinations_array = json_result.values.at("destinations").get<json::Array>().values; const auto &destinations_array =
json_result.values.at("destinations").get<json::Array>().values;
BOOST_CHECK_EQUAL(destinations_array.size(), params.coordinates.size()); BOOST_CHECK_EQUAL(destinations_array.size(), params.coordinates.size());
for (const auto &destination : destinations_array) for (const auto &destination : destinations_array)
{ {
@ -139,7 +141,7 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
const auto rc = osrm.Table(params, result); const auto rc = osrm.Table(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error); BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -154,7 +156,8 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
BOOST_CHECK_EQUAL(durations_matrix[i].get<json::Number>().value, 0); BOOST_CHECK_EQUAL(durations_matrix[i].get<json::Number>().value, 0);
BOOST_CHECK_EQUAL(durations_matrix.size(), params.coordinates.size()); BOOST_CHECK_EQUAL(durations_matrix.size(), params.coordinates.size());
} }
const auto &destinations_array = json_result.values.at("destinations").get<json::Array>().values; const auto &destinations_array =
json_result.values.at("destinations").get<json::Array>().values;
for (const auto &destination : destinations_array) for (const auto &destination : destinations_array)
{ {
BOOST_CHECK(waypoint_check(destination)); BOOST_CHECK(waypoint_check(destination));
@ -185,7 +188,7 @@ BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates)
const auto rc = osrm.Table(params, result); const auto rc = osrm.Table(params, result);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Error); BOOST_CHECK(rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "NoSegment"); BOOST_CHECK_EQUAL(code, "NoSegment");

View File

@ -166,7 +166,7 @@ void validate_tile(const osrm::OSRM &osrm)
const auto rc = osrm.Tile(params, result); const auto rc = osrm.Tile(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& str_result = result.get<std::string>(); auto &str_result = result.get<std::string>();
BOOST_CHECK(str_result.size() > 114000); BOOST_CHECK(str_result.size() > 114000);
vtzero::vector_tile tile{str_result}; vtzero::vector_tile tile{str_result};
@ -212,7 +212,7 @@ void test_tile_turns(const osrm::OSRM &osrm)
const auto rc = osrm.Tile(params, result); const auto rc = osrm.Tile(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& str_result = result.get<std::string>(); auto &str_result = result.get<std::string>();
BOOST_CHECK_GT(str_result.size(), 128); BOOST_CHECK_GT(str_result.size(), 128);
vtzero::vector_tile tile{str_result}; vtzero::vector_tile tile{str_result};
@ -354,7 +354,7 @@ void test_tile_speeds(const osrm::OSRM &osrm)
const auto rc = osrm.Tile(params, result); const auto rc = osrm.Tile(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& str_result = result.get<std::string>(); auto &str_result = result.get<std::string>();
BOOST_CHECK_GT(str_result.size(), 128); BOOST_CHECK_GT(str_result.size(), 128);
vtzero::vector_tile tile{str_result}; vtzero::vector_tile tile{str_result};
@ -435,7 +435,7 @@ void test_tile_nodes(const osrm::OSRM &osrm)
const auto rc = osrm.Tile(params, result); const auto rc = osrm.Tile(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& str_result = result.get<std::string>(); auto &str_result = result.get<std::string>();
BOOST_CHECK_GT(str_result.size(), 128); BOOST_CHECK_GT(str_result.size(), 128);
vtzero::vector_tile tile{str_result}; vtzero::vector_tile tile{str_result};

View File

@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component)
const auto rc = osrm.Trip(params, result); const auto rc = osrm.Trip(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component)
const auto rc = osrm.Trip(params, result); const auto rc = osrm.Trip(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components)
const auto rc = osrm.Trip(params, result); const auto rc = osrm.Trip(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(test_tfse_1)
const auto rc = osrm.Trip(params, result); const auto rc = osrm.Trip(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(test_tfse_2)
const auto rc = osrm.Trip(params, result); const auto rc = osrm.Trip(params, result);
BOOST_CHECK(rc == Status::Ok); BOOST_CHECK(rc == Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value; const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
@ -254,7 +254,7 @@ void CheckNotImplemented(const osrm::OSRM &osrm, osrm::TripParameters &params)
engine::api::ResultT result = json::Object(); engine::api::ResultT result = json::Object();
auto rc = osrm.Trip(params, result); auto rc = osrm.Trip(params, result);
BOOST_REQUIRE(rc == osrm::Status::Error); BOOST_REQUIRE(rc == osrm::Status::Error);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
auto code = json_result.values.at("code").get<osrm::json::String>().value; auto code = json_result.values.at("code").get<osrm::json::String>().value;
BOOST_CHECK_EQUAL(code, "NotImplemented"); BOOST_CHECK_EQUAL(code, "NotImplemented");
} }
@ -265,7 +265,7 @@ void CheckOk(const osrm::OSRM &osrm, osrm::TripParameters &params)
engine::api::ResultT result = json::Object(); engine::api::ResultT result = json::Object();
auto rc = osrm.Trip(params, result); auto rc = osrm.Trip(params, result);
BOOST_REQUIRE(rc == osrm::Status::Ok); BOOST_REQUIRE(rc == osrm::Status::Ok);
auto& json_result=result.get<json::Object>(); auto &json_result = result.get<json::Object>();
auto code = json_result.values.at("code").get<osrm::json::String>().value; auto code = json_result.values.at("code").get<osrm::json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok"); BOOST_CHECK_EQUAL(code, "Ok");
} }