Skip to content

Commit

Permalink
Fixed flatbufferbuiler copy issues.
Browse files Browse the repository at this point in the history
Compiling under gcc9.1 we get copy issues.
It appears we shouldn't pass builder classes by value, only ref.
  • Loading branch information
peoplestom committed Oct 1, 2019
1 parent 018a9bc commit 2889537
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
29 changes: 15 additions & 14 deletions include/engine/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <boost/assert.hpp>
#include <boost/range/algorithm/transform.hpp>

#include <memory>
#include <vector>

namespace osrm
Expand Down Expand Up @@ -73,7 +74,7 @@ class BaseAPI
}

flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
MakeWaypoints(flatbuffers::FlatBufferBuilder *builder,
const std::vector<PhantomNodes> &segment_end_coordinates) const
{
BOOST_ASSERT(parameters.coordinates.size() > 0);
Expand All @@ -82,43 +83,43 @@ class BaseAPI
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(parameters.coordinates.size());
waypoints[0] =
MakeWaypoint(builder, segment_end_coordinates.front().source_phantom).Finish();
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) {
return MakeWaypoint(builder, phantom_pair.target_phantom).Finish();
[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
// protected:
fbresult::WaypointBuilder MakeWaypoint(flatbuffers::FlatBufferBuilder &builder,
const PhantomNode &phantom) const
std::unique_ptr<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 name_string = builder.CreateString(
auto name_string = builder->CreateString(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string());

boost::optional<flatbuffers::Offset<flatbuffers::String>> hint_string = boost::none;
if (parameters.generate_hints)
{
hint_string = builder.CreateString(Hint{phantom, facade.GetCheckSum()}.ToBase64());
hint_string = builder->CreateString(Hint{phantom, facade.GetCheckSum()}.ToBase64());
}

fbresult::WaypointBuilder waypoint(builder);
waypoint.add_location(&location);
waypoint.add_distance(util::coordinate_calculation::fccApproximateDistance(
auto waypoint = std::make_unique<fbresult::WaypointBuilder>(*builder);
waypoint->add_location(&location);
waypoint->add_distance(util::coordinate_calculation::fccApproximateDistance(
phantom.location, phantom.input_location));
waypoint.add_name(name_string);
waypoint->add_name(name_string);
if (hint_string)
{
waypoint.add_hint(*hint_string);
waypoint->add_hint(*hint_string);
}
return waypoint;
}
Expand Down
20 changes: 10 additions & 10 deletions include/engine/api/match_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class MatchAPI final : public RouteAPI

if (data_version_string)
{
response.add_data_version(*data_version_string);
response->add_data_version(*data_version_string);
}

fb_result.Finish(response.Finish());
fb_result.Finish(response->Finish());
}
void MakeResponse(const std::vector<map_matching::SubMatching> &sub_matchings,
const std::vector<InternalRouteResult> &sub_routes,
Expand Down Expand Up @@ -141,29 +141,29 @@ class MatchAPI final : public RouteAPI
}
const auto &phantom =
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
auto waypoint = BaseAPI::MakeWaypoint(fb_result, phantom);
waypoint.add_matchings_index(matching_index.sub_matching_index);
waypoint.add_alternatives_count(sub_matchings[matching_index.sub_matching_index]
.alternatives_count[matching_index.point_index]);
auto waypoint = BaseAPI::MakeWaypoint(&fb_result, phantom);
waypoint->add_matchings_index(matching_index.sub_matching_index);
waypoint->add_alternatives_count(sub_matchings[matching_index.sub_matching_index]
.alternatives_count[matching_index.point_index]);
// waypoint indices need to be adjusted if route legs were collapsed
// waypoint parameter assumes there is only one match object
if (!parameters.waypoints.empty())
{
if (tidy_result.was_waypoint[trace_index])
{
waypoint.add_waypoint_index(was_waypoint_idx);
waypoint->add_waypoint_index(was_waypoint_idx);
was_waypoint_idx++;
}
else
{
waypoint.add_waypoint_index(0);
waypoint->add_waypoint_index(0);
}
}
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());
}

return fb_result.CreateVector(waypoints);
Expand Down
7 changes: 3 additions & 4 deletions include/engine/api/nearest_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ class NearestAPI final : public BaseAPI
auto node_values = MakeNodes(phantom_node);
fbresult::Uint64Pair nodes{node_values.first, node_values.second};

auto waypoint = MakeWaypoint(fb_result, phantom_node);
waypoint.add_nodes(&nodes);

return waypoint.Finish();
auto waypoint = MakeWaypoint(&fb_result, phantom_node);
waypoint->add_nodes(&nodes);
return waypoint->Finish();
});

waypoints_vector = fb_result.CreateVector(waypoints);
Expand Down
20 changes: 10 additions & 10 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ class RouteAPI : public BaseAPI

auto response =
MakeFBResponse(raw_routes, fb_result, [this, &all_start_end_points, &fb_result]() {
return BaseAPI::MakeWaypoints(fb_result, all_start_end_points);
return BaseAPI::MakeWaypoints(&fb_result, all_start_end_points);
});

if (data_version_string)
{
response.add_data_version(*data_version_string);
response->add_data_version(*data_version_string);
}
fb_result.Finish(response.Finish());
fb_result.Finish(response->Finish());
}

void
Expand Down Expand Up @@ -125,9 +125,10 @@ class RouteAPI : public BaseAPI

protected:
template <typename GetWptsFn>
fbresult::FBResultBuilder MakeFBResponse(const InternalManyRoutesResult &raw_routes,
flatbuffers::FlatBufferBuilder &fb_result,
GetWptsFn getWaypoints) const
std::unique_ptr<fbresult::FBResultBuilder>
MakeFBResponse(const InternalManyRoutesResult &raw_routes,
flatbuffers::FlatBufferBuilder &fb_result,
GetWptsFn getWaypoints) const
{

std::vector<flatbuffers::Offset<fbresult::RouteObject>> routes;
Expand All @@ -151,9 +152,9 @@ class RouteAPI : public BaseAPI
waypoints_vector = getWaypoints();
}

fbresult::FBResultBuilder response(fb_result);
response.add_routes(routes_vector);
response.add_waypoints(waypoints_vector);
auto response = std::make_unique<fbresult::FBResultBuilder>(fb_result);
response->add_routes(routes_vector);
response->add_waypoints(waypoints_vector);

return response;
}
Expand Down Expand Up @@ -656,7 +657,6 @@ class RouteAPI : public BaseAPI
step.intersections.end(),
intersections.begin(),
[&fb_result, this](const guidance::IntermediateIntersection &intersection) {

std::vector<flatbuffers::Offset<fbresult::Lane>> lanes;
if (json::detail::hasValidLanes(intersection))
{
Expand Down
4 changes: 2 additions & 2 deletions include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class TableAPI final : public BaseAPI

boost::range::transform(
phantoms, std::back_inserter(waypoints), [this, &builder](const PhantomNode &phantom) {
return BaseAPI::MakeWaypoint(builder, phantom).Finish();
return BaseAPI::MakeWaypoint(&builder, phantom)->Finish();
});
return builder.CreateVector(waypoints);
}
Expand All @@ -252,7 +252,7 @@ class TableAPI final : public BaseAPI
std::back_inserter(waypoints),
[this, &builder, phantoms](const std::size_t idx) {
BOOST_ASSERT(idx < phantoms.size());
return BaseAPI::MakeWaypoint(builder, phantoms[idx]).Finish();
return BaseAPI::MakeWaypoint(&builder, phantoms[idx])->Finish();
});
return builder.CreateVector(waypoints);
}
Expand Down
12 changes: 6 additions & 6 deletions include/engine/api/trip_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class TripAPI final : public RouteAPI

if (data_version_string)
{
response.add_data_version(*data_version_string);
response->add_data_version(*data_version_string);
}
fb_result.Finish(response.Finish());
fb_result.Finish(response->Finish());
}
void MakeResponse(const std::vector<std::vector<NodeID>> &sub_trips,
const std::vector<InternalRouteResult> &sub_routes,
Expand Down Expand Up @@ -127,10 +127,10 @@ class TripAPI final : public RouteAPI
auto trip_index = input_idx_to_trip_idx[input_index];
BOOST_ASSERT(!trip_index.NotUsed());

auto waypoint = BaseAPI::MakeWaypoint(fb_result, phantoms[input_index]);
waypoint.add_waypoint_index(trip_index.point_index);
waypoint.add_trips_index(trip_index.sub_trip_index);
waypoints.push_back(waypoint.Finish());
auto waypoint = BaseAPI::MakeWaypoint(&fb_result, phantoms[input_index]);
waypoint->add_waypoint_index(trip_index.point_index);
waypoint->add_trips_index(trip_index.sub_trip_index);
waypoints.push_back(waypoint->Finish());
}

return fb_result.CreateVector(waypoints);
Expand Down

0 comments on commit 2889537

Please sign in to comment.