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 b7a990d commit 4f46705
Show file tree
Hide file tree
Showing 38 changed files with 278 additions and 216 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ if(ENABLE_CONAN)
KEEP_RPATHS
NO_OUTPUT_DIRS
OPTIONS boost:filesystem_version=3 # https://stackoverflow.com/questions/73392648/error-with-boost-filesystem-version-in-cmake
onetbb:shared=${TBB_SHARED}
# onetbb:shared=${TBB_SHARED}
boost:without_stacktrace=True # Apple Silicon cross-compilation fails without it
BUILD missing
)
Expand Down
4 changes: 2 additions & 2 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main(int argc, const char *argv[])
// Execute routing request, this does the heavy lifting
const auto status = osrm.Route(params, result);

auto &json_result = result.get<json::Object>();
auto &json_result = std::get<json::Object>(result);
if (status == Status::Ok)
{
auto &routes = json_result.values["routes"].get<json::Array>();
Expand All @@ -80,7 +80,7 @@ int main(int argc, const char *argv[])
}
else if (status == Status::Error)
{
const auto code = json_result.values["code"].get<json::String>().value;
const auto code = std::get<json::String>(json_result.values["code"]).value;
const auto message = json_result.values["message"].get<json::String>().value;

std::cout << "Code: " << code << "\n";
Expand Down
4 changes: 2 additions & 2 deletions include/engine/api/base_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ENGINE_API_BASE_RESULT_HPP

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

#include <string>

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

#endif
6 changes: 3 additions & 3 deletions include/engine/api/match_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class MatchAPI final : public RouteAPI
osrm::engine::api::ResultT &response) const
{
BOOST_ASSERT(sub_matchings.size() == sub_routes.size());
if (response.is<flatbuffers::FlatBufferBuilder>())
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
MakeResponse(sub_matchings, sub_routes, fb_result);
}
else
{
auto &json_result = response.get<util::json::Object>();
auto &json_result = std::get<util::json::Object>(response);
MakeResponse(sub_matchings, sub_routes, json_result);
}
}
Expand Down
6 changes: 3 additions & 3 deletions include/engine/api/nearest_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class NearestAPI final : public BaseAPI
BOOST_ASSERT(phantom_nodes.size() == 1);
BOOST_ASSERT(parameters.coordinates.size() == 1);

if (response.is<flatbuffers::FlatBufferBuilder>())
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
MakeResponse(phantom_nodes, fb_result);
}
else
{
auto &json_result = response.get<util::json::Object>();
auto &json_result = std::get<util::json::Object>(response);
MakeResponse(phantom_nodes, json_result);
}
}
Expand Down
14 changes: 7 additions & 7 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ class RouteAPI : public BaseAPI
{
BOOST_ASSERT(!raw_routes.routes.empty());

if (response.is<flatbuffers::FlatBufferBuilder>())
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
MakeResponse(raw_routes, waypoint_candidates, fb_result);
}
else
{
auto &json_result = response.get<util::json::Object>();
auto &json_result = std::get<util::json::Object>(response);
MakeResponse(raw_routes, waypoint_candidates, json_result);
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ class RouteAPI : public BaseAPI
}

template <typename ForwardIter>
mapbox::util::variant<flatbuffers::Offset<flatbuffers::String>,
std::variant<flatbuffers::Offset<flatbuffers::String>,
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
MakeGeometry(flatbuffers::FlatBufferBuilder &builder, ForwardIter begin, ForwardIter end) const
{
Expand Down Expand Up @@ -408,7 +408,7 @@ class RouteAPI : public BaseAPI

// Fill geometry
auto overview = MakeOverview(leg_geometries);
mapbox::util::variant<flatbuffers::Offset<flatbuffers::String>,
std::variant<flatbuffers::Offset<flatbuffers::String>,
flatbuffers::Offset<flatbuffers::Vector<const fbresult::Position *>>>
geometry;
if (overview)
Expand All @@ -426,7 +426,7 @@ class RouteAPI : public BaseAPI
routeObject.add_legs(legs_vector);
if (overview)
{
mapbox::util::apply_visitor(GeometryVisitor<fbresult::RouteObjectBuilder>(routeObject),
std::visit(GeometryVisitor<fbresult::RouteObjectBuilder>(routeObject),
geometry);
}

Expand Down Expand Up @@ -645,7 +645,7 @@ class RouteAPI : public BaseAPI
stepBuilder.add_rotary_pronunciation(rotary_pronunciation_string);
stepBuilder.add_intersections(intersections_vector);
stepBuilder.add_maneuver(maneuver_buffer);
mapbox::util::apply_visitor(GeometryVisitor<fbresult::StepBuilder>(stepBuilder), geometry);
std::visit(GeometryVisitor<fbresult::StepBuilder>(stepBuilder), geometry);
return stepBuilder.Finish();
};

Expand Down
6 changes: 3 additions & 3 deletions include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ class TableAPI final : public BaseAPI
const std::vector<TableCellRef> &fallback_speed_cells,
osrm::engine::api::ResultT &response) const
{
if (response.is<flatbuffers::FlatBufferBuilder>())
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
MakeResponse(tables, candidates, fallback_speed_cells, fb_result);
}
else
{
auto &json_result = response.get<util::json::Object>();
auto &json_result = std::get<util::json::Object>(response);
MakeResponse(tables, candidates, fallback_speed_cells, json_result);
}
}
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 @@ -27,14 +27,14 @@ class TripAPI final : public RouteAPI
{
BOOST_ASSERT(sub_trips.size() == sub_routes.size());

if (response.is<flatbuffers::FlatBufferBuilder>())
if (std::holds_alternative<flatbuffers::FlatBufferBuilder>(response))
{
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
auto &fb_result = std::get<flatbuffers::FlatBufferBuilder>(response);
MakeResponse(sub_trips, sub_routes, candidates, fb_result);
}
else
{
auto &json_result = response.get<util::json::Object>();
auto &json_result = std::get<util::json::Object>(response);
MakeResponse(sub_trips, sub_routes, candidates, json_result);
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/engine/plugins/plugin_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class BasePlugin
const std::string &message,
osrm::engine::api::ResultT &result) const
{
mapbox::util::apply_visitor(ErrorRenderer(code, message), result);
std::visit(ErrorRenderer(code, message), result);
return Status::Error;
}

Expand Down
4 changes: 2 additions & 2 deletions include/nodejs/json_v8_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct V8Renderer
for (const auto &keyValue : object.values)
{
Napi::Value child;
mapbox::util::apply_visitor(V8Renderer(env, child), keyValue.second);
std::visit(V8Renderer(env, child), keyValue.second);
obj.Set(keyValue.first, child);
}
out = obj;
Expand All @@ -41,7 +41,7 @@ struct V8Renderer
for (auto i = 0u; i < array.values.size(); ++i)
{
Napi::Value child;
mapbox::util::apply_visitor(V8Renderer(env, child), array.values[i]);
std::visit(V8Renderer(env, child), array.values[i]);
a.Set(i, child);
}
out = a;
Expand Down
2 changes: 1 addition & 1 deletion include/nodejs/node_osrm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ template <> Napi::Value inline render(const Napi::Env &env, const ObjectOrString
{
// Return the string object as a node Buffer
return Napi::Buffer<char>::Copy(
env, result.get<std::string>().data(), result.get<std::string>().size());
env, std::get<std::string>(result).data(), std::get<std::string>(result).size());
}
}

Expand Down
3 changes: 2 additions & 1 deletion include/util/geojson_debug_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class GeojsonLogger
if (!first)
ofs << ",\n\t\t";

util::json::render(ofs, object.get<util::json::Object>());
(void)object;
// util::json::render(ofs, std::get<util::json::Object>(object));

first = false;
}
Expand Down
12 changes: 6 additions & 6 deletions include/util/json_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef JSON_CONTAINER_HPP
#define JSON_CONTAINER_HPP

#include <mapbox/variant.hpp>

#include <variant>
#include <boost/variant/recursive_wrapper.hpp>
#include <string>
#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -96,10 +96,10 @@ struct Null
*
* Dispatch on its type by either by using apply_visitor or its get function.
*/
using Value = mapbox::util::variant<String,
Number,
mapbox::util::recursive_wrapper<Object>,
mapbox::util::recursive_wrapper<Array>,
using Value = std::variant<String,
Number,
boost::recursive_wrapper<Object>,
boost::recursive_wrapper<Array>,
True,
False,
Null>;
Expand Down
6 changes: 3 additions & 3 deletions include/util/json_deep_compare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct Comparator

const auto &rhs_child = rhs.values.find(key)->second;
const auto &lhs_child = lhs.values.find(key)->second;
auto is_same = mapbox::util::apply_visitor(
auto is_same = std::visit(
Comparator(reason, lhs_path + "." + key, rhs_path + "." + key),
lhs_child,
rhs_child);
Expand All @@ -105,7 +105,7 @@ struct Comparator
for (auto i = 0UL; i < lhs.values.size(); ++i)
{
auto is_same =
mapbox::util::apply_visitor(Comparator(reason,
std::visit(Comparator(reason,
lhs_path + "[" + std::to_string(i) + "]",
rhs_path + "[" + std::to_string(i) + "]"),
lhs.values[i],
Expand Down Expand Up @@ -151,7 +151,7 @@ struct Comparator

inline bool compare(const Value &reference, const Value &result, std::string &reason)
{
return mapbox::util::apply_visitor(
return std::visit(
Comparator(reason, "reference", "result"), reference, result);
}
} // namespace osrm::util::json
Expand Down
50 changes: 25 additions & 25 deletions include/util/json_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,35 @@ template <typename Out> struct Renderer
write(buffer.data(), buffer.size());
}

void operator()(const Object &object)
void operator()(const boost::recursive_wrapper<Object> &)
{
write('{');
for (auto it = object.values.begin(), end = object.values.end(); it != end;)
{
write('\"');
write(it->first);
write<>("\":");
mapbox::util::apply_visitor(Renderer(out), it->second);
if (++it != end)
{
write(',');
}
}
write('}');
// write('{');
// for (auto it = object.values.begin(), end = object.values.end(); it != end;)
// {
// write('\"');
// write(it->first);
// write<>("\":");
// std::visit(Renderer(out), it->second);
// if (++it != end)
// {
// write(',');
// }
// }
// write('}');
}

void operator()(const Array &array)
void operator()(const boost::recursive_wrapper<Array> &)
{
write('[');
for (auto it = array.values.cbegin(), end = array.values.cend(); it != end;)
{
mapbox::util::apply_visitor(Renderer(out), *it);
if (++it != end)
{
write(',');
}
}
write(']');
// write('[');
// for (auto it = array.values.cbegin(), end = array.values.cend(); it != end;)
// {
// std::visit(Renderer(out), *it);
// if (++it != end)
// {
// write(',');
// }
// }
// write(']');
}

void operator()(const True &) { write<>("true"); }
Expand Down
2 changes: 1 addition & 1 deletion src/benchmarks/json_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ json::Object load(const char *filename)

json::Value result;
convert(document, result);
return result.get<json::Object>();
return std::get<json::Object>(result);
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/benchmarks/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ try
{
engine::api::ResultT result = json::Object();
const auto rc = osrm.Match(params, result);
auto &json_result = result.get<json::Object>();
auto &json_result = std::get<json::Object>(result);
if (rc != Status::Ok ||
json_result.values.at("matchings").get<json::Array>().values.size() != 1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/benchmarks/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ try
{
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
auto &json_result = result.get<json::Object>();
auto &json_result = std::get<json::Object>(result);
if (rc != Status::Ok || json_result.values.find("routes") == json_result.values.end())
{
throw std::runtime_error{"Couldn't route"};
Expand Down
2 changes: 1 addition & 1 deletion src/engine/plugins/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ Status TilePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
{
BOOST_ASSERT(parameters.IsValid());

auto &pbf_buffer = result.get<std::string>();
auto &pbf_buffer = std::get<std::string>(result);
const auto &facade = algorithms.GetFacade();
auto edges = getEdges(facade, parameters.x, parameters.y, parameters.z);
auto segregated_nodes = getSegregatedNodes(facade, edges);
Expand Down
Loading

0 comments on commit 4f46705

Please sign in to comment.