From dc1b5d3424a96a67bb27c947b52b533558fc691b Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Thu, 3 Mar 2016 02:55:30 +0100 Subject: [PATCH] Provides ctor from base path for EngineConfig, fixes #2030 --- example/example.cpp | 47 ++++++++++++-------------------- include/engine/engine_config.hpp | 16 ++++++++++- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 7815aaaa5..2bb1392ba 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -26,49 +26,36 @@ int main(int argc, const char *argv[]) try return EXIT_FAILURE; } - // Path to .osrm base file - std::string base{argv[1]}; + using namespace osrm; - // Configure routing machine - osrm::EngineConfig config; - - // TODO(daniel-j-h): this is ugly, provide easier way for users - config.server_paths["ramindex"] = base + ".ramIndex"; - config.server_paths["fileindex"] = base + ".fileIndex"; - config.server_paths["hsgrdata"] = base + ".hsgr"; - config.server_paths["nodesdata"] = base + ".nodes"; - config.server_paths["edgesdata"] = base + ".edges"; - config.server_paths["coredata"] = base + ".core"; - config.server_paths["geometries"] = base + ".geometry"; - config.server_paths["timestamp"] = base + ".timestamp"; - config.server_paths["namesdata"] = base + ".names"; + // Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore + EngineConfig config{argv[1]}; config.use_shared_memory = false; // Routing machine with several services (such as Route, Table, Nearest, Trip, Match) - osrm::OSRM osrm{config}; + OSRM osrm{config}; // The following shows how to use the Route service; configure this service - osrm::RouteParameters params; + RouteParameters params; - // Route is in Berlin. Latitude, Longitude - // TODO(daniel-j-h): use either coordinate_precision or better provide double,double-taking ctor - params.coordinates.push_back({osrm::util::FloatLongitude(7.419758), osrm::util::FloatLatitude(43.731142)}); - params.coordinates.push_back({osrm::util::FloatLongitude(7.419505), osrm::util::FloatLatitude(43.736825)}); + // Rout in monaco + params.coordinates.push_back({util::FloatLongitude(7.419758), util::FloatLatitude(43.731142)}); + params.coordinates.push_back({util::FloatLongitude(7.419505), util::FloatLatitude(43.736825)}); // Response is in JSON format - osrm::json::Object result; + json::Object result; // Execute routing request, this does the heavy lifting const auto status = osrm.Route(params, result); - if (status == osrm::Status::Ok) + if (status == Status::Ok) { - auto &routes = result.values["routes"].get(); + auto &routes = result.values["routes"].get(); // Let's just use the first route - auto &route = routes.values.at(0).get(); - const auto distance = route.values["distance"].get().value; - const auto duration = route.values["duration"].get().value; + auto &route = routes.values.at(0).get(); + const auto distance = route.values["distance"].get().value; + const auto duration = route.values["duration"].get().value; // Warn users if extract does not contain the default Berlin coordinates from above if (distance == 0 or duration == 0) @@ -80,10 +67,10 @@ int main(int argc, const char *argv[]) try std::cout << "Distance: " << distance << " meter\n"; std::cout << "Duration: " << duration << " seconds\n"; } - else if (status == osrm::Status::Error) + else if (status == Status::Error) { - const auto code = result.values["code"].get().value; - const auto message = result.values["message"].get().value; + const auto code = result.values["code"].get().value; + const auto message = result.values["message"].get().value; std::cout << "Code: " << code << "\n"; std::cout << "Message: " << code << "\n"; diff --git a/include/engine/engine_config.hpp b/include/engine/engine_config.hpp index d16f3f4ce..c54cd52cb 100644 --- a/include/engine/engine_config.hpp +++ b/include/engine/engine_config.hpp @@ -41,6 +41,21 @@ namespace engine struct EngineConfig { + EngineConfig() = default; + + EngineConfig(const boost::filesystem::path &base) + : server_paths{{"ramindex", base.string() + ".ramIndex"}, + {"fileindex", base.string() + ".fileIndex"}, + {"hsgrdata", base.string() + ".hsgr"}, + {"nodesdata", base.string() + ".nodes"}, + {"edgesdata", base.string() + ".edges"}, + {"coredata", base.string() + ".core"}, + {"geometries", base.string() + ".geometry"}, + {"timestamp", base.string() + ".timestamp"}, + {"namesdata", base.string() + ".names"}} + { + } + std::unordered_map server_paths; int max_locations_trip = -1; int max_locations_viaroute = -1; @@ -48,7 +63,6 @@ struct EngineConfig int max_locations_map_matching = -1; bool use_shared_memory = true; }; - } }