Merge remote-tracking branch 'origin/master' into dl_using_keyword

This commit is contained in:
Dennis Luxen
2022-12-10 16:02:53 +01:00
45 changed files with 951 additions and 1059 deletions
-2
View File
@@ -645,7 +645,6 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
const util::XORFastHash<> hash;
unsigned current_level = 0;
std::size_t next_renumbering = number_of_nodes * 0.35;
while (remaining_nodes.size() > number_of_core_nodes)
{
@@ -761,7 +760,6 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
remaining_nodes.resize(begin_independent_nodes_idx);
p.PrintStatus(number_of_contracted_nodes);
++current_level;
}
node_data.Renumber(new_to_old_node_id);
+4 -4
View File
@@ -4,7 +4,6 @@
#include "engine/plugins/tile.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/string_view.hpp"
#include "util/vector_tile.hpp"
#include "util/web_mercator.hpp"
@@ -20,6 +19,7 @@
#include <algorithm>
#include <numeric>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
@@ -340,7 +340,7 @@ class SpeedLayerFeatureBuilder : public vtzero::linestring_feature_builder
add_property(m_layer.key_duration, m_layer.double_index(value));
}
void set_name(const boost::string_ref &value)
void set_name(const std::string_view value)
{
add_property(
m_layer.key_name,
@@ -518,7 +518,7 @@ void encodeVectorTile(const DataFacadeBase &facade,
fbuilder.set_speed(speed_kmh_idx);
fbuilder.set_is_small(component_id.is_tiny);
fbuilder.set_datasource(
facade.GetDatasourceName(forward_datasource_idx).to_string());
std::string(facade.GetDatasourceName(forward_datasource_idx)));
fbuilder.set_weight(from_alias<double>(forward_weight) / 10.0);
fbuilder.set_duration(from_alias<double>(forward_duration) / 10.0);
fbuilder.set_name(name);
@@ -552,7 +552,7 @@ void encodeVectorTile(const DataFacadeBase &facade,
fbuilder.set_speed(speed_kmh_idx);
fbuilder.set_is_small(component_id.is_tiny);
fbuilder.set_datasource(
facade.GetDatasourceName(reverse_datasource_idx).to_string());
std::string(facade.GetDatasourceName(reverse_datasource_idx)));
fbuilder.set_weight(from_alias<double>(reverse_weight) / 10.0);
fbuilder.set_duration(from_alias<double>(reverse_duration) / 10.0);
fbuilder.set_name(name);
@@ -13,7 +13,7 @@
#include <utility>
#include <vector>
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
namespace osrm
{
+1 -1
View File
@@ -8,8 +8,8 @@
#include <rapidjson/istreamwrapper.h>
#include <boost/filesystem.hpp>
#include <boost/function_output_iterator.hpp>
#include <boost/geometry/algorithms/equals.hpp>
#include <boost/iterator/function_output_iterator.hpp>
#include <fstream>
#include <string>
+3 -3
View File
@@ -19,16 +19,16 @@ SuffixTable::SuffixTable(ScriptingEnvironment &scripting_environment)
boost::algorithm::to_lower(suffix);
auto into = std::inserter(suffix_set, end(suffix_set));
auto to_view = [](const auto &s) { return util::StringView{s}; };
auto to_view = [](const auto &s) { return std::string_view{s}; };
std::transform(begin(suffixes), end(suffixes), into, to_view);
}
bool SuffixTable::isSuffix(const std::string &possible_suffix) const
{
return isSuffix(util::StringView{possible_suffix});
return isSuffix(std::string_view{possible_suffix});
}
bool SuffixTable::isSuffix(util::StringView possible_suffix) const
bool SuffixTable::isSuffix(std::string_view possible_suffix) const
{
return suffix_set.count(possible_suffix) > 0;
}
@@ -24,7 +24,7 @@ struct EdgeInfo
NodeID node;
util::StringView name;
std::string_view name;
bool reversed;
+12
View File
@@ -4,6 +4,9 @@ cmake_minimum_required(VERSION 3.1)
message(STATUS "Building node_osrm")
set(NAPI_VERSION 8)
add_definitions(-DNAPI_VERSION=${NAPI_VERSION})
set(BINDING_DIR "${PROJECT_SOURCE_DIR}/lib/binding")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/node_modules/node-cmake")
@@ -13,6 +16,7 @@ nodejs_init()
message(STATUS "Configuring node_osrm bindings for NodeJs ${NODEJS_VERSION}")
add_nodejs_module(node_osrm node_osrm.cpp)
set_target_properties(node_osrm PROPERTIES CXX_STANDARD 17)
# TODO: we disable clang-tidy for this target, because it causes errors in third-party NodeJs related headers
@@ -21,6 +25,14 @@ set_target_properties(node_osrm PROPERTIES CXX_CLANG_TIDY "")
target_no_warning(node_osrm suggest-destructor-override)
target_no_warning(node_osrm suggest-override)
# https://github.com/cjntaylor/node-cmake/issues/53#issuecomment-842357457
execute_process(COMMAND node -p "require('node-addon-api').include" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE NODE_ADDON_API_DIR)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(node_osrm SYSTEM PRIVATE ${NODE_ADDON_API_DIR})
target_link_libraries(node_osrm osrm)
# node_osrm artifacts in ${BINDING_DIR} to depend targets on
+79 -91
View File
@@ -1,3 +1,5 @@
#include "osrm/engine_config.hpp"
#include "osrm/osrm.hpp"
@@ -9,6 +11,7 @@
#include "osrm/trip_parameters.hpp"
#include <exception>
#include <napi.h>
#include <sstream>
#include <stdexcept>
#include <type_traits>
@@ -21,35 +24,25 @@
namespace node_osrm
{
Engine::Engine(osrm::EngineConfig &config) : Base(), this_(std::make_shared<osrm::OSRM>(config)) {}
Nan::Persistent<v8::Function> &Engine::constructor()
Napi::Object Engine::Init(Napi::Env env, Napi::Object exports)
{
static Nan::Persistent<v8::Function> init;
return init;
}
Napi::Function func = DefineClass(env,
"OSRM",
{
InstanceMethod("route", &Engine::route),
InstanceMethod("nearest", &Engine::nearest),
InstanceMethod("table", &Engine::table),
InstanceMethod("tile", &Engine::tile),
InstanceMethod("match", &Engine::match),
InstanceMethod("trip", &Engine::trip),
});
NAN_MODULE_INIT(Engine::Init)
{
const auto whoami = Nan::New("OSRM").ToLocalChecked();
Napi::FunctionReference *constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
env.SetInstanceData(constructor);
auto fnTp = Nan::New<v8::FunctionTemplate>(New);
fnTp->InstanceTemplate()->SetInternalFieldCount(1);
fnTp->SetClassName(whoami);
SetPrototypeMethod(fnTp, "route", route);
SetPrototypeMethod(fnTp, "nearest", nearest);
SetPrototypeMethod(fnTp, "table", table);
SetPrototypeMethod(fnTp, "tile", tile);
SetPrototypeMethod(fnTp, "match", match);
SetPrototypeMethod(fnTp, "trip", trip);
const auto fn = Nan::GetFunction(fnTp).ToLocalChecked();
constructor().Reset(fn);
Nan::Set(target, whoami, fn);
exports.Set("OSRM", func);
return exports;
}
// clang-format off
@@ -93,35 +86,25 @@ NAN_MODULE_INIT(Engine::Init)
*
*/
// clang-format on
NAN_METHOD(Engine::New)
Engine::Engine(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Engine>(info)
{
if (info.IsConstructCall())
try
{
try
{
auto config = argumentsToEngineConfig(info);
if (!config)
return;
auto config = argumentsToEngineConfig(info);
if (!config)
return;
auto *const self = new Engine(*config);
self->Wrap(info.This());
}
catch (const std::exception &ex)
{
return Nan::ThrowTypeError(ex.what());
}
info.GetReturnValue().Set(info.This());
this_ = std::make_shared<osrm::OSRM>(*config);
}
else
catch (const std::exception &ex)
{
return Nan::ThrowTypeError(
"Cannot call constructor as function, you need to use 'new' keyword");
ThrowTypeError(info.Env(), ex.what());
}
}
template <typename ParameterParser, typename ServiceMemFn>
inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
inline void async(const Napi::CallbackInfo &info,
ParameterParser argsToParams,
ServiceMemFn service,
bool requires_multiple_coordinates)
@@ -133,22 +116,21 @@ inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
BOOST_ASSERT(params->IsValid());
if (!info[info.Length() - 1]->IsFunction())
return Nan::ThrowTypeError("last argument must be a callback function");
if (!info[info.Length() - 1].IsFunction())
return ThrowTypeError(info.Env(), "last argument must be a callback function");
auto *const self = Nan::ObjectWrap::Unwrap<Engine>(info.Holder());
auto *const self = Napi::ObjectWrap<Engine>::Unwrap(info.This().As<Napi::Object>());
using ParamPtr = decltype(params);
struct Worker final : Nan::AsyncWorker
struct Worker final : Napi::AsyncWorker
{
Worker(std::shared_ptr<osrm::OSRM> osrm_,
ParamPtr params_,
ServiceMemFn service,
Nan::Callback *callback,
Napi::Function callback,
PluginParameters pluginParams_)
: Nan::AsyncWorker(callback, "osrm:async"), osrm{std::move(osrm_)},
service{std::move(service)}, params{std::move(params_)}, pluginParams{
std::move(pluginParams_)}
: Napi::AsyncWorker(callback), osrm{std::move(osrm_)}, service{std::move(service)},
params{std::move(params_)}, pluginParams{std::move(pluginParams_)}
{
}
@@ -194,17 +176,14 @@ inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
}
catch (const std::exception &e)
{
SetErrorMessage(e.what());
SetError(e.what());
}
void HandleOKCallback() override
void OnOK() override
{
Nan::HandleScope scope;
Napi::HandleScope scope{Env()};
const constexpr auto argc = 2u;
v8::Local<v8::Value> argv[argc] = {Nan::Null(), render(result)};
callback->Call(argc, argv, async_resource);
Callback().Call({Env().Null(), render(Env(), result)});
}
// Keeps the OSRM object alive even after shutdown until we're done with callback
@@ -216,13 +195,14 @@ inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
ObjectOrString result;
};
auto *callback = new Nan::Callback{info[info.Length() - 1].As<v8::Function>()};
Nan::AsyncQueueWorker(
new Worker{self->this_, std::move(params), service, callback, std::move(pluginParams)});
Napi::Function callback = info[info.Length() - 1].As<Napi::Function>();
auto worker =
new Worker(self->this_, std::move(params), service, callback, std::move(pluginParams));
worker->Queue();
}
template <typename ParameterParser, typename ServiceMemFn>
inline void asyncForTiles(const Nan::FunctionCallbackInfo<v8::Value> &info,
inline void asyncForTiles(const Napi::CallbackInfo &info,
ParameterParser argsToParams,
ServiceMemFn service,
bool requires_multiple_coordinates)
@@ -235,22 +215,21 @@ inline void asyncForTiles(const Nan::FunctionCallbackInfo<v8::Value> &info,
BOOST_ASSERT(params->IsValid());
if (!info[info.Length() - 1]->IsFunction())
return Nan::ThrowTypeError("last argument must be a callback function");
if (!info[info.Length() - 1].IsFunction())
return ThrowTypeError(info.Env(), "last argument must be a callback function");
auto *const self = Nan::ObjectWrap::Unwrap<Engine>(info.Holder());
auto *const self = Napi::ObjectWrap<Engine>::Unwrap(info.This().As<Napi::Object>());
using ParamPtr = decltype(params);
struct Worker final : Nan::AsyncWorker
struct Worker final : Napi::AsyncWorker
{
Worker(std::shared_ptr<osrm::OSRM> osrm_,
ParamPtr params_,
ServiceMemFn service,
Nan::Callback *callback,
Napi::Function callback,
PluginParameters pluginParams_)
: Nan::AsyncWorker(callback, "osrm:asyncForTiles"), osrm{std::move(osrm_)},
service{std::move(service)}, params{std::move(params_)}, pluginParams{
std::move(pluginParams_)}
: Napi::AsyncWorker(callback), osrm{std::move(osrm_)}, service{std::move(service)},
params{std::move(params_)}, pluginParams{std::move(pluginParams_)}
{
}
@@ -264,18 +243,14 @@ inline void asyncForTiles(const Nan::FunctionCallbackInfo<v8::Value> &info,
}
catch (const std::exception &e)
{
SetErrorMessage(e.what());
SetError(e.what());
}
void HandleOKCallback() override
void OnOK() override
{
Nan::HandleScope scope;
Napi::HandleScope scope{Env()};
const constexpr auto argc = 2u;
auto str_result = result.get<std::string>();
v8::Local<v8::Value> argv[argc] = {Nan::Null(), render(str_result)};
callback->Call(argc, argv, async_resource);
Callback().Call({Env().Null(), render(Env(), result.get<std::string>())});
}
// Keeps the OSRM object alive even after shutdown until we're done with callback
@@ -287,9 +262,10 @@ inline void asyncForTiles(const Nan::FunctionCallbackInfo<v8::Value> &info,
osrm::engine::api::ResultT result;
};
auto *callback = new Nan::Callback{info[info.Length() - 1].As<v8::Function>()};
Nan::AsyncQueueWorker(
new Worker{self->this_, std::move(params), service, callback, std::move(pluginParams)});
Napi::Function callback = info[info.Length() - 1].As<Napi::Function>();
auto worker =
new Worker(self->this_, std::move(params), service, callback, std::move(pluginParams));
worker->Queue();
}
// clang-format off
@@ -333,12 +309,13 @@ inline void asyncForTiles(const Nan::FunctionCallbackInfo<v8::Value> &info,
* });
*/
// clang-format on
NAN_METHOD(Engine::route) //
Napi::Value Engine::route(const Napi::CallbackInfo &info)
{
osrm::Status (osrm::OSRM::*route_fn)(const osrm::RouteParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Route;
async(info, &argumentsToRouteParameter, route_fn, true);
return info.Env().Undefined();
}
// clang-format off
@@ -379,12 +356,13 @@ NAN_METHOD(Engine::route) //
* });
*/
// clang-format on
NAN_METHOD(Engine::nearest) //
Napi::Value Engine::nearest(const Napi::CallbackInfo &info)
{
osrm::Status (osrm::OSRM::*nearest_fn)(const osrm::NearestParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Nearest;
async(info, &argumentsToNearestParameter, nearest_fn, false);
return info.Env().Undefined();
}
// clang-format off
@@ -410,7 +388,6 @@ NAN_METHOD(Engine::nearest) //
* @param {Number} [options.scale_factor] Multiply the table duration values in the table by this number for more controlled input into a route optimization solver.
* @param {String} [options.snapping] Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph.
* @param {Array} [options.annotations] Return the requested table or tables in response. Can be `['duration']` (return the duration matrix, default), `[distance']` (return the distance matrix), or `['duration', distance']` (return both the duration matrix and the distance matrix).
* @param {Function} callback
*
* @returns {Object} containing `durations`, `distances`, `sources`, and `destinations`.
@@ -439,12 +416,13 @@ NAN_METHOD(Engine::nearest) //
* });
*/
// clang-format on
NAN_METHOD(Engine::table) //
Napi::Value Engine::table(const Napi::CallbackInfo &info)
{
osrm::Status (osrm::OSRM::*table_fn)(const osrm::TableParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Table;
async(info, &argumentsToTableParameter, table_fn, true);
return info.Env().Undefined();
}
// clang-format off
@@ -473,12 +451,13 @@ NAN_METHOD(Engine::table) //
* });
*/
// clang-format on
NAN_METHOD(Engine::tile)
Napi::Value Engine::tile(const Napi::CallbackInfo &info)
{
osrm::Status (osrm::OSRM::*tile_fn)(const osrm::TileParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Tile;
asyncForTiles(info, &argumentsToTileParameters, tile_fn, {/*unused*/});
return info.Env().Undefined();
}
// clang-format off
@@ -536,12 +515,13 @@ NAN_METHOD(Engine::tile)
*
*/
// clang-format on
NAN_METHOD(Engine::match) //
Napi::Value Engine::match(const Napi::CallbackInfo &info)
{
osrm::Status (osrm::OSRM::*match_fn)(const osrm::MatchParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Match;
async(info, &argumentsToMatchParameter, match_fn, true);
return info.Env().Undefined();
}
// clang-format off
@@ -611,12 +591,13 @@ NAN_METHOD(Engine::match) //
* });
*/
// clang-format on
NAN_METHOD(Engine::trip) //
Napi::Value Engine::trip(const Napi::CallbackInfo &info)
{
osrm::Status (osrm::OSRM::*trip_fn)(const osrm::TripParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Trip;
async(info, &argumentsToTripParameter, trip_fn, true);
return info.Env().Undefined();
}
/**
@@ -710,3 +691,10 @@ NAN_METHOD(Engine::trip) //
*/
} // namespace node_osrm
Napi::Object InitAll(Napi::Env env, Napi::Object exports)
{
return node_osrm::Engine::Init(env, exports);
}
NODE_API_MODULE(addon, InitAll)
+1 -1
View File
@@ -11,7 +11,7 @@
#include "util/typedefs.hpp"
#include <boost/filesystem.hpp>
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
#include <tbb/parallel_sort.h>