Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SiarheiFedartsou committed May 25, 2024
1 parent ad990aa commit 1f6e4ff
Show file tree
Hide file tree
Showing 16 changed files with 665 additions and 667 deletions.
3 changes: 1 addition & 2 deletions include/engine/api/base_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 3 additions & 4 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion include/extractor/internal_extractor_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "util/typedefs.hpp"

#include <boost/assert.hpp>
#include <mapbox/variant.hpp>
#include <variant>
#include <utility>

namespace osrm::extractor
Expand Down
2 changes: 1 addition & 1 deletion include/extractor/maneuver_override.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util/std_hash.hpp"
#include "util/vector_view.hpp"

#include <mapbox/variant.hpp>
#include <variant>

#include <algorithm>

Expand Down
78 changes: 39 additions & 39 deletions include/extractor/turn_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "util/typedefs.hpp"

#include <algorithm>
#include <mapbox/variant.hpp>
#include <variant>
#include <vector>

namespace osrm::extractor
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions include/nodejs/node_osrm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <sstream>
#include <stdexcept>
#include <string>
#include <variant>
#include <vector>

#include <exception>
Expand All @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/server/service/base_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "osrm/osrm.hpp"
#include "util/coordinate.hpp"

#include <mapbox/variant.hpp>
#include <variant>

#include <string>
#include <vector>
Expand Down
10 changes: 2 additions & 8 deletions include/util/json_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 10 additions & 12 deletions include/util/json_deep_compare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/benchmarks/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
}
Expand Down
2 changes: 1 addition & 1 deletion src/nodejs/node_osrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 6 additions & 7 deletions unit_tests/library/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Loading

0 comments on commit 1f6e4ff

Please sign in to comment.