This commit is contained in:
Siarhei Fedartsou 2024-05-25 19:07:58 +02:00
parent ad990aafe7
commit 1f6e4ff9db
16 changed files with 665 additions and 667 deletions

View File

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

View File

@ -159,7 +159,7 @@ class RouteAPI : public BaseAPI
template <typename ForwardIter>
std::variant<flatbuffers::Offset<flatbuffers::String>,
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
MakeGeometry(flatbuffers::FlatBufferBuilder &builder, ForwardIter begin, ForwardIter end) const
{
if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
@ -409,7 +409,7 @@ class RouteAPI : public BaseAPI
// Fill geometry
auto overview = MakeOverview(leg_geometries);
std::variant<flatbuffers::Offset<flatbuffers::String>,
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
geometry;
if (overview)
{
@ -426,8 +426,7 @@ class RouteAPI : public BaseAPI
routeObject.add_legs(legs_vector);
if (overview)
{
std::visit(GeometryVisitor<fbresult::RouteObjectBuilder>(routeObject),
geometry);
std::visit(GeometryVisitor<fbresult::RouteObjectBuilder>(routeObject), geometry);
}
return routeObject.Finish();

View File

@ -7,7 +7,7 @@
#include "util/typedefs.hpp"
#include <boost/assert.hpp>
#include <mapbox/variant.hpp>
#include <variant>
#include <utility>
namespace osrm::extractor

View File

@ -11,7 +11,7 @@
#include "util/std_hash.hpp"
#include "util/vector_view.hpp"
#include <mapbox/variant.hpp>
#include <variant>
#include <algorithm>

View File

@ -4,7 +4,7 @@
#include "util/typedefs.hpp"
#include <algorithm>
#include <mapbox/variant.hpp>
#include <variant>
#include <vector>
namespace osrm::extractor
@ -61,50 +61,50 @@ struct InputViaWayPath
struct InputTurnPath
{
mapbox::util::variant<InputViaNodePath, InputViaWayPath> node_or_way;
std::variant<InputViaNodePath, InputViaWayPath> node_or_way;
TurnPathType Type() const
{
BOOST_ASSERT(node_or_way.which() < TurnPathType::NUM_TURN_PATH_TYPES);
return static_cast<TurnPathType>(node_or_way.which());
BOOST_ASSERT(node_or_way.index() < TurnPathType::NUM_TURN_PATH_TYPES);
return static_cast<TurnPathType>(node_or_way.index());
}
OSMWayID From() const
{
return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH
? mapbox::util::get<InputViaNodePath>(node_or_way).from
: mapbox::util::get<InputViaWayPath>(node_or_way).from;
return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH
? std::get<InputViaNodePath>(node_or_way).from
: std::get<InputViaWayPath>(node_or_way).from;
}
OSMWayID To() const
{
return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH
? mapbox::util::get<InputViaNodePath>(node_or_way).to
: mapbox::util::get<InputViaWayPath>(node_or_way).to;
return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH
? std::get<InputViaNodePath>(node_or_way).to
: std::get<InputViaWayPath>(node_or_way).to;
}
InputViaWayPath &AsViaWayPath()
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH);
return mapbox::util::get<InputViaWayPath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH);
return std::get<InputViaWayPath>(node_or_way);
}
const InputViaWayPath &AsViaWayPath() const
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH);
return mapbox::util::get<InputViaWayPath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH);
return std::get<InputViaWayPath>(node_or_way);
}
InputViaNodePath &AsViaNodePath()
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH);
return mapbox::util::get<InputViaNodePath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH);
return std::get<InputViaNodePath>(node_or_way);
}
const InputViaNodePath &AsViaNodePath() const
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH);
return mapbox::util::get<InputViaNodePath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH);
return std::get<InputViaNodePath>(node_or_way);
}
};
@ -175,63 +175,63 @@ struct ViaWayPath
// between node/way paths
struct TurnPath
{
mapbox::util::variant<ViaNodePath, ViaWayPath> node_or_way;
std::variant<ViaNodePath, ViaWayPath> node_or_way;
NodeID To() const
{
return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH
? mapbox::util::get<ViaNodePath>(node_or_way).to
: mapbox::util::get<ViaWayPath>(node_or_way).to;
return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH
? std::get<ViaNodePath>(node_or_way).to
: std::get<ViaWayPath>(node_or_way).to;
}
NodeID From() const
{
return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH
? mapbox::util::get<ViaNodePath>(node_or_way).from
: mapbox::util::get<ViaWayPath>(node_or_way).from;
return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH
? std::get<ViaNodePath>(node_or_way).from
: std::get<ViaWayPath>(node_or_way).from;
}
NodeID FirstVia() const
{
if (node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH)
if (node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH)
{
return mapbox::util::get<ViaNodePath>(node_or_way).via;
return std::get<ViaNodePath>(node_or_way).via;
}
else
{
BOOST_ASSERT(!mapbox::util::get<ViaWayPath>(node_or_way).via.empty());
return mapbox::util::get<ViaWayPath>(node_or_way).via[0];
BOOST_ASSERT(!std::get<ViaWayPath>(node_or_way).via.empty());
return std::get<ViaWayPath>(node_or_way).via[0];
}
}
ViaWayPath &AsViaWayPath()
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH);
return mapbox::util::get<ViaWayPath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH);
return std::get<ViaWayPath>(node_or_way);
}
const ViaWayPath &AsViaWayPath() const
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH);
return mapbox::util::get<ViaWayPath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH);
return std::get<ViaWayPath>(node_or_way);
}
ViaNodePath &AsViaNodePath()
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH);
return mapbox::util::get<ViaNodePath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH);
return std::get<ViaNodePath>(node_or_way);
}
const ViaNodePath &AsViaNodePath() const
{
BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH);
return mapbox::util::get<ViaNodePath>(node_or_way);
BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH);
return std::get<ViaNodePath>(node_or_way);
}
TurnPathType Type() const
{
BOOST_ASSERT(node_or_way.which() < TurnPathType::NUM_TURN_PATH_TYPES);
return static_cast<TurnPathType>(node_or_way.which());
BOOST_ASSERT(node_or_way.index() < TurnPathType::NUM_TURN_PATH_TYPES);
return static_cast<TurnPathType>(node_or_way.index());
}
bool operator==(const TurnPath &other) const

View File

@ -28,6 +28,7 @@
#include <sstream>
#include <stdexcept>
#include <string>
#include <variant>
#include <vector>
#include <exception>
@ -50,7 +51,7 @@ struct PluginParameters
bool renderToBuffer = false;
};
using ObjectOrString = typename mapbox::util::variant<osrm::json::Object, std::string>;
using ObjectOrString = typename std::variant<osrm::json::Object, std::string>;
template <typename ResultT> inline Napi::Value render(const Napi::Env &env, const ResultT &result);
@ -61,7 +62,7 @@ template <> Napi::Value inline render(const Napi::Env &env, const std::string &r
template <> Napi::Value inline render(const Napi::Env &env, const ObjectOrString &result)
{
if (result.is<osrm::json::Object>())
if (std::holds_alternative<osrm::json::Object>(result))
{
// Convert osrm::json object tree into matching v8 object tree
Napi::Value value;
@ -95,7 +96,7 @@ inline void ParseResult(const osrm::Status &result_status, osrm::json::Object &r
if (result_status == osrm::Status::Error)
{
throw std::logic_error(code_iter->second.get<osrm::json::String>().value.c_str());
throw std::logic_error(std::get<osrm::json::String>(code_iter->second).value.c_str());
}
result.values.erase(code_iter);

View File

@ -5,7 +5,7 @@
#include "osrm/osrm.hpp"
#include "util/coordinate.hpp"
#include <mapbox/variant.hpp>
#include <variant>
#include <string>
#include <vector>

View File

@ -31,11 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef JSON_CONTAINER_HPP
#define JSON_CONTAINER_HPP
#include <variant>
#include <boost/variant/recursive_wrapper.hpp>
#include <string>
#include <unordered_map>
#include <utility>
#include <variant>
#include <vector>
namespace osrm::util::json
@ -96,13 +96,7 @@ struct Null
*
* Dispatch on its type by either by using apply_visitor or its get function.
*/
using Value = std::variant<String,
Number,
Object,
Array,
True,
False,
Null>;
using Value = std::variant<String, Number, Object, Array, True, False, Null>;
/**
* Typed Object.

View File

@ -81,10 +81,10 @@ struct Comparator
const auto &rhs_child = rhs.values.find(key)->second;
const auto &lhs_child = lhs.values.find(key)->second;
auto is_same = std::visit(
Comparator(reason, lhs_path + "." + key, rhs_path + "." + key),
lhs_child,
rhs_child);
auto is_same =
std::visit(Comparator(reason, lhs_path + "." + key, rhs_path + "." + key),
lhs_child,
rhs_child);
if (!is_same)
{
return false;
@ -104,12 +104,11 @@ struct Comparator
for (auto i = 0UL; i < lhs.values.size(); ++i)
{
auto is_same =
std::visit(Comparator(reason,
lhs_path + "[" + std::to_string(i) + "]",
rhs_path + "[" + std::to_string(i) + "]"),
lhs.values[i],
rhs.values[i]);
auto is_same = std::visit(Comparator(reason,
lhs_path + "[" + std::to_string(i) + "]",
rhs_path + "[" + std::to_string(i) + "]"),
lhs.values[i],
rhs.values[i]);
if (!is_same)
{
return false;
@ -151,8 +150,7 @@ struct Comparator
inline bool compare(const Value &reference, const Value &result, std::string &reason)
{
return std::visit(
Comparator(reason, "reference", "result"), reference, result);
return std::visit(Comparator(reason, "reference", "result"), reference, result);
}
} // namespace osrm::util::json

View File

@ -234,7 +234,7 @@ try
const auto rc = osrm.Match(params, result);
auto &json_result = std::get<json::Object>(result);
if (rc != Status::Ok ||
json_result.values.at("matchings").get<json::Array>().values.size() != 1)
std::get<json::Array>(json_result.values.at("matchings")).values.size() != 1)
{
throw std::runtime_error{"Couldn't match"};
}

View File

@ -147,7 +147,7 @@ inline void async(const Napi::CallbackInfo &info,
osrm::engine::api::ResultT r;
r = osrm::util::json::Object();
const auto status = ((*osrm).*(service))(*params, r);
auto &json_result = r.get<osrm::json::Object>();
auto &json_result = std::get<osrm::json::Object>(r);
ParseResult(status, json_result);
if (pluginParams.renderToBuffer)
{

View File

@ -64,11 +64,10 @@ void test_match(bool use_json_only_api)
std::get<json::Number>(waypoint_object.values.at("matchings_index")).value;
const auto waypoint_index =
std::get<json::Number>(waypoint_object.values.at("waypoint_index")).value;
const auto &route_legs = std::get<json::Array>(std::get<json::Object>(matchings[matchings_index]
)
.values.at("legs")
)
.values;
const auto &route_legs =
std::get<json::Array>(
std::get<json::Object>(matchings[matchings_index]).values.at("legs"))
.values;
BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1);
BOOST_CHECK_LT(matchings_index, number_of_matchings);
}
@ -122,7 +121,7 @@ void test_match_split(bool use_json_only_api)
const auto code = std::get<json::String>(json_result.values.at("code")).value;
BOOST_CHECK_EQUAL(code, "Ok");
const auto &tracepoints =std::get<json::Array>(json_result.values.at("tracepoints")).values;
const auto &tracepoints = std::get<json::Array>(json_result.values.at("tracepoints")).values;
BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size());
const auto &matchings = std::get<json::Array>(json_result.values.at("matchings")).values;
@ -136,7 +135,7 @@ void test_match_split(bool use_json_only_api)
BOOST_CHECK(waypoint_check(waypoint));
const auto &waypoint_object = std::get<json::Object>(waypoint);
const auto matchings_index =
std::get<json::Number>(waypoint_object.values.at("matchings_index")).value;
std::get<json::Number>(waypoint_object.values.at("matchings_index")).value;
const auto waypoint_index =
std::get<json::Number>(waypoint_object.values.at("waypoint_index")).value;

View File

@ -54,8 +54,8 @@ void test_route_same_coordinates_fixture(bool use_json_only_api)
std::get<json::Object>(itr).values["hint"] = "";
// Round value to 6 decimal places for double comparison later
std::get<json::Object>(itr).values["distance"] =
round(std::get<json::Number>(std::get<json::Object>(itr).values["distance"]).value * 1000000);
std::get<json::Object>(itr).values["distance"] = round(
std::get<json::Number>(std::get<json::Object>(itr).values["distance"]).value * 1000000);
}
const auto location = json::Array{{{7.437070}, {43.749248}}};
@ -221,14 +221,17 @@ void test_route_same_coordinates(bool use_json_only_api)
{
const auto &step_object = std::get<json::Object>(step);
const auto distance = std::get<json::Number>(step_object.values.at("distance")).value;
const auto distance =
std::get<json::Number>(step_object.values.at("distance")).value;
BOOST_CHECK_EQUAL(distance, 0);
const auto duration = std::get<json::Number>(step_object.values.at("duration")).value;
const auto duration =
std::get<json::Number>(step_object.values.at("duration")).value;
BOOST_CHECK_EQUAL(duration, 0);
// geometries=polyline by default
const auto geometry = std::get<json::String>(step_object.values.at("geometry")).value;
const auto geometry =
std::get<json::String>(step_object.values.at("geometry")).value;
BOOST_CHECK(!geometry.empty());
// nothing can be said about name, empty or contains way name
@ -239,7 +242,8 @@ void test_route_same_coordinates(bool use_json_only_api)
const auto mode = std::get<json::String>(step_object.values.at("mode")).value;
BOOST_CHECK(!name.empty());
const auto &maneuver = std::get<json::Object>(step_object.values.at("maneuver")).values;
const auto &maneuver =
std::get<json::Object>(step_object.values.at("maneuver")).values;
const auto type = std::get<json::String>(maneuver.at("type")).value;
BOOST_CHECK(!type.empty());
@ -260,7 +264,8 @@ void test_route_same_coordinates(bool use_json_only_api)
const auto &bearings =
std::get<json::Array>(intersection_object.at("bearings")).values;
BOOST_CHECK(!bearings.empty());
const auto &entries = std::get<json::Array>(intersection_object.at("entry")).values;
const auto &entries =
std::get<json::Array>(intersection_object.at("entry")).values;
BOOST_CHECK(bearings.size() == entries.size());
for (const auto &bearing : bearings)
@ -274,7 +279,8 @@ void test_route_same_coordinates(bool use_json_only_api)
}
if (step_count + 1 < steps.size())
{
const auto out = std::get<json::Number>(intersection_object.at("out")).value;
const auto out =
std::get<json::Number>(intersection_object.at("out")).value;
BOOST_CHECK(out < bearings.size());
}
}
@ -523,7 +529,8 @@ void speed_annotation_matches_duration_and_distance(bool use_json_only_api)
BOOST_CHECK(rc == Status::Ok);
const auto &routes = std::get<json::Array>(json_result.values["routes"]).values;
const auto &legs = std::get<json::Array>(std::get<json::Object>(routes[0]).values.at("legs")).values;
const auto &legs =
std::get<json::Array>(std::get<json::Object>(routes[0]).values.at("legs")).values;
const auto &annotation =
std::get<json::Object>(std::get<json::Object>(legs[0]).values.at("annotation"));
const auto &speeds = std::get<json::Array>(annotation.values.at("speed")).values;
@ -573,16 +580,16 @@ void test_manual_setting_of_annotations_property(bool use_json_only_api)
const auto code = std::get<json::String>(json_result.values.at("code")).value;
BOOST_CHECK_EQUAL(code, "Ok");
auto annotations = std::get<json::Object>(
std::get<json::Object>(
std::get<json::Array>(
auto annotations =
std::get<json::Object>(
std::get<json::Object>(
std::get<json::Array>(json_result.values["routes"])
.values[0])
.values["legs"])
.values[0])
.values["annotation"])
.values;
std::get<json::Array>(
std::get<json::Object>(
std::get<json::Array>(json_result.values["routes"]).values[0])
.values["legs"])
.values[0])
.values["annotation"])
.values;
BOOST_CHECK_EQUAL(annotations.size(), 7);
}
BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property_old_api)

View File

@ -135,7 +135,7 @@ void test_table_three_coords_one_source_one_dest_matrix_no_waypoints(bool use_js
BOOST_CHECK_EQUAL(distances_array.size(), params.sources.size());
for (unsigned int i = 0; i < distances_array.size(); i++)
{
const auto distances_matrix =std::get<json::Array>(distances_array[i]).values;
const auto distances_matrix = std::get<json::Array>(distances_array[i]).values;
BOOST_CHECK_EQUAL(distances_matrix.size(),
params.sources.size() * params.destinations.size());
}

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,8 @@ inline bool waypoint_check(osrm::json::Value waypoint)
throw util::exception("Must pass in a waypoint object");
}
const auto waypoint_object = std::get<json::Object>(waypoint);
const auto waypoint_location = std::get<json::Array>(waypoint_object.values.at("location")).values;
const auto waypoint_location =
std::get<json::Array>(waypoint_object.values.at("location")).values;
util::FloatLongitude lon{std::get<json::Number>(waypoint_location[0]).value};
util::FloatLatitude lat{std::get<json::Number>(waypoint_location[1]).value};
util::Coordinate location_coordinate(lon, lat);