Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatbuffers is not a boost::optional friendly #5566

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/engine/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class BaseAPI
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;
flatbuffers::Offset<flatbuffers::String> hint_string;
if (parameters.generate_hints)
{
hint_string = builder->CreateString(Hint{phantom, facade.GetCheckSum()}.ToBase64());
Expand All @@ -117,9 +117,9 @@ class BaseAPI
waypoint->add_distance(util::coordinate_calculation::fccApproximateDistance(
phantom.location, phantom.input_location));
waypoint->add_name(name_string);
if (hint_string)
if (parameters.generate_hints)
{
waypoint->add_hint(*hint_string);
waypoint->add_hint(hint_string);
}
return waypoint;
}
Expand Down
6 changes: 3 additions & 3 deletions include/engine/api/match_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MatchAPI final : public RouteAPI
flatbuffers::FlatBufferBuilder &fb_result) const
{
auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
flatbuffers::Offset<flatbuffers::String> data_version_string;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
Expand All @@ -60,9 +60,9 @@ class MatchAPI final : public RouteAPI
return MakeTracepoints(fb_result, sub_matchings);
});

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

fb_result.Finish(response->Finish());
Expand Down
22 changes: 11 additions & 11 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RouteAPI : public BaseAPI
{

auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
flatbuffers::Offset<flatbuffers::String> data_version_string;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
Expand All @@ -84,9 +84,9 @@ class RouteAPI : public BaseAPI
return BaseAPI::MakeWaypoints(&fb_result, all_start_end_points);
});

if (data_version_string)
if (!data_timestamp.empty())
{
response->add_data_version(*data_version_string);
response->add_data_version(data_version_string);
}
fb_result.Finish(response->Finish());
}
Expand Down Expand Up @@ -373,8 +373,7 @@ class RouteAPI : public BaseAPI
requested_annotations = RouteParameters::AnnotationsType::All;
}

boost::optional<flatbuffers::Offset<fbresult::Annotation>> annotation_buffer =
boost::none;
flatbuffers::Offset<fbresult::Annotation> annotation_buffer;
if (requested_annotations != RouteParameters::AnnotationsType::None)
{
annotation_buffer =
Expand All @@ -397,9 +396,9 @@ class RouteAPI : public BaseAPI
}
legBuilder.add_steps(steps_vector);

if (annotation_buffer)
if (requested_annotations != RouteParameters::AnnotationsType::None)
{
legBuilder.add_annotations(*annotation_buffer);
legBuilder.add_annotations(annotation_buffer);
}
routeLegs.emplace_back(legBuilder.Finish());
}
Expand Down Expand Up @@ -506,8 +505,9 @@ class RouteAPI : public BaseAPI
}
auto nodes_vector = fb_result.CreateVector(nodes);
// Add any supporting metadata, if needed
boost::optional<flatbuffers::Offset<fbresult::Metadata>> metadata_buffer = boost::none;
if (requested_annotations & RouteParameters::AnnotationsType::Datasources)
bool use_metadata = requested_annotations & RouteParameters::AnnotationsType::Datasources;
flatbuffers::Offset<fbresult::Metadata> metadata_buffer;
if (use_metadata)
{
const auto MAX_DATASOURCE_ID = 255u;
std::vector<flatbuffers::Offset<flatbuffers::String>> names;
Expand All @@ -529,9 +529,9 @@ class RouteAPI : public BaseAPI
annotation.add_weight(weight);
annotation.add_datasources(datasources);
annotation.add_nodes(nodes_vector);
if (metadata_buffer)
if (use_metadata)
{
annotation.add_metadata(*metadata_buffer);
annotation.add_metadata(metadata_buffer);
}

return annotation.Finish();
Expand Down
35 changes: 19 additions & 16 deletions include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TableAPI final : public BaseAPI
auto number_of_destinations = parameters.destinations.size();

auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
flatbuffers::Offset<flatbuffers::String> data_version_string;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
Expand Down Expand Up @@ -116,21 +116,24 @@ class TableAPI final : public BaseAPI
}
}

boost::optional<flatbuffers::Offset<flatbuffers::Vector<float>>> durations = boost::none;
if (parameters.annotations & TableParameters::AnnotationsType::Duration)
bool use_durations = parameters.annotations & TableParameters::AnnotationsType::Duration;
flatbuffers::Offset<flatbuffers::Vector<float>> durations;
if (use_durations)
{
durations = MakeDurationTable(fb_result, tables.first);
}

boost::optional<flatbuffers::Offset<flatbuffers::Vector<float>>> distances = boost::none;
if (parameters.annotations & TableParameters::AnnotationsType::Distance)
bool use_distances = parameters.annotations & TableParameters::AnnotationsType::Distance;
flatbuffers::Offset<flatbuffers::Vector<float>> distances;
if (use_distances)
{
distances = MakeDistanceTable(fb_result, tables.second);
}

boost::optional<flatbuffers::Offset<flatbuffers::Vector<uint32_t>>> speed_cells =
boost::none;
if (parameters.fallback_speed != INVALID_FALLBACK_SPEED && parameters.fallback_speed > 0)
bool have_speed_cells =
parameters.fallback_speed != INVALID_FALLBACK_SPEED && parameters.fallback_speed > 0;
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> speed_cells;
if (have_speed_cells)
{
speed_cells = MakeEstimatesTable(fb_result, fallback_speed_cells);
}
Expand All @@ -139,24 +142,24 @@ class TableAPI final : public BaseAPI
table.add_destinations(destinations);
table.add_rows(number_of_sources);
table.add_cols(number_of_destinations);
if (durations)
if (use_durations)
{
table.add_durations(*durations);
table.add_durations(durations);
}
if (distances)
if (use_distances)
{
table.add_distances(*distances);
table.add_distances(distances);
}
if (speed_cells)
if (have_speed_cells)
{
table.add_fallback_speed_cells(*speed_cells);
table.add_fallback_speed_cells(speed_cells);
}
auto table_buffer = table.Finish();

fbresult::FBResultBuilder response(fb_result);
if (data_version_string)
if (!data_timestamp.empty())
{
response.add_data_version(*data_version_string);
response.add_data_version(data_version_string);
}
response.add_table(table_buffer);
response.add_waypoints(sources);
Expand Down
6 changes: 3 additions & 3 deletions include/engine/api/trip_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TripAPI final : public RouteAPI
flatbuffers::FlatBufferBuilder &fb_result) const
{
auto data_timestamp = facade.GetTimestamp();
boost::optional<flatbuffers::Offset<flatbuffers::String>> data_version_string = boost::none;
flatbuffers::Offset<flatbuffers::String> data_version_string;
if (!data_timestamp.empty())
{
data_version_string = fb_result.CreateString(data_timestamp);
Expand All @@ -59,9 +59,9 @@ class TripAPI final : public RouteAPI
return MakeWaypoints(fb_result, sub_trips, phantoms);
});

if (data_version_string)
if (!data_timestamp.empty())
{
response->add_data_version(*data_version_string);
response->add_data_version(data_version_string);
}
fb_result.Finish(response->Finish());
}
Expand Down