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
commit f983d626ac
45 changed files with 951 additions and 1059 deletions

View File

@ -42,6 +42,7 @@ Checks: >
-llvm-twine-local,
misc-*,
-misc-argument-comment,
-misc-const-correctness,
-misc-non-private-member-variables-in-classes,
-misc-unconventional-assign-operator,
-misc-no-recursion,

View File

@ -20,7 +20,7 @@ env:
ENABLE_NODE_BINDINGS: "ON"
jobs:
windows:
windows-release-node:
needs: format-taginfo-docs
runs-on: windows-2022
continue-on-error: false
@ -180,14 +180,14 @@ jobs:
CXXCOMPILER: clang++-6.0
CUCUMBER_TIMEOUT: 60000
- name: clang-11.0-debug-clang-tidy
- name: clang-15.0-debug-clang-tidy
continue-on-error: false
node: 16
runs-on: ubuntu-22.04
BUILD_TOOLS: ON
BUILD_TYPE: Debug
CCOMPILER: clang-14
CXXCOMPILER: clang++-14
CCOMPILER: clang-15
CXXCOMPILER: clang++-15
CUCUMBER_TIMEOUT: 60000
ENABLE_CLANG_TIDY: ON
@ -212,6 +212,17 @@ jobs:
CXXCOMPILER: clang++-6.0
ENABLE_CONAN: ON
- name: gcc-12-release
continue-on-error: false
node: 16
runs-on: ubuntu-22.04
BUILD_TOOLS: ON
BUILD_TYPE: Release
CCOMPILER: gcc-12
CXXCOMPILER: g++-12
ENABLE_BENCHMARKS: ON
CXXFLAGS: '-Wno-array-bounds -Wno-uninitialized'
- name: gcc-11-release
continue-on-error: false
node: 16
@ -264,102 +275,7 @@ jobs:
CXXCOMPILER: g++-8
CXXFLAGS: -Wno-cast-function-type
- name: gcc-7-release
continue-on-error: false
node: 16
runs-on: ubuntu-20.04
BUILD_TOOLS: ON
BUILD_TYPE: Release
CCOMPILER: gcc-7
CXXCOMPILER: g++-7
- name: conan-macos-x64-release-node-16
build_node_package: true
continue-on-error: false
node: 16
runs-on: macos-11
BUILD_TOOLS: ON
BUILD_TYPE: Release
CCOMPILER: clang
CXXCOMPILER: clang++
CUCUMBER_TIMEOUT: 60000
ENABLE_ASSERTIONS: ON
ENABLE_CONAN: ON
- name: conan-macos-arm64-release-node-16
build_node_package: true
continue-on-error: false
node: 16
runs-on: macos-11
BUILD_TOOLS: ON
BUILD_TYPE: Release
CCOMPILER: clang
CXXCOMPILER: clang++
CUCUMBER_TIMEOUT: 60000
ENABLE_ASSERTIONS: ON
ENABLE_CONAN: ON
ENABLE_APPLE_SILICON: ON
- name: conan-macos-x64-release-node-18
build_node_package: true
continue-on-error: false
node: 18
runs-on: macos-11
BUILD_TOOLS: ON
BUILD_TYPE: Release
CCOMPILER: clang
CXXCOMPILER: clang++
CUCUMBER_TIMEOUT: 60000
ENABLE_ASSERTIONS: ON
ENABLE_CONAN: ON
- name: conan-macos-arm64-release-node-18
build_node_package: true
continue-on-error: false
node: 18
runs-on: macos-11
BUILD_TOOLS: ON
BUILD_TYPE: Release
CCOMPILER: clang
CXXCOMPILER: clang++
CUCUMBER_TIMEOUT: 60000
ENABLE_ASSERTIONS: ON
ENABLE_CONAN: ON
ENABLE_APPLE_SILICON: ON
- name: gcc-7-release-shared
continue-on-error: false
node: 16
runs-on: ubuntu-20.04
BUILD_TOOLS: ON
BUILD_TYPE: Release
BUILD_SHARED_LIBS: ON
CCOMPILER: gcc-7
CXXCOMPILER: g++-7
- name: node-16-conan-linux-release
build_node_package: true
continue-on-error: false
node: 16
runs-on: ubuntu-20.04
BUILD_TYPE: Release
CCOMPILER: clang-6.0
CXXCOMPILER: clang++-6.0
ENABLE_CONAN: ON
NODE_PACKAGE_TESTS_ONLY: ON
- name: node-16-conan-linux-debug
build_node_package: true
continue-on-error: false
node: 16
runs-on: ubuntu-20.04
BUILD_TYPE: Debug
CCOMPILER: clang-6.0
CXXCOMPILER: clang++-6.0
ENABLE_CONAN: ON
NODE_PACKAGE_TESTS_ONLY: ON
- name: node-18-conan-linux-release
- name: conan-linux-release-node
build_node_package: true
continue-on-error: false
node: 18
@ -370,7 +286,7 @@ jobs:
ENABLE_CONAN: ON
NODE_PACKAGE_TESTS_ONLY: ON
- name: node-18-conan-linux-debug
- name: conan-linux-debug-node
build_node_package: true
continue-on-error: false
node: 18
@ -381,10 +297,10 @@ jobs:
ENABLE_CONAN: ON
NODE_PACKAGE_TESTS_ONLY: ON
- name: conan-macos-x64-release-node-latest
- name: conan-macos-x64-release-node
build_node_package: true
continue-on-error: true
node: latest
node: 18
runs-on: macos-11
BUILD_TYPE: Release
CCOMPILER: clang
@ -393,10 +309,10 @@ jobs:
ENABLE_ASSERTIONS: ON
ENABLE_CONAN: ON
- name: conan-macos-arm64-release-node-latest
- name: conan-macos-arm64-release-node
build_node_package: true
continue-on-error: true
node: latest
node: 18
runs-on: macos-11
BUILD_TYPE: Release
CCOMPILER: clang
@ -406,28 +322,6 @@ jobs:
ENABLE_CONAN: ON
ENABLE_APPLE_SILICON: ON
- name: node-latest-conan-linux-release
build_node_package: true
continue-on-error: true
node: latest
runs-on: ubuntu-20.04
BUILD_TYPE: Release
CCOMPILER: clang-6.0
CXXCOMPILER: clang++-6.0
ENABLE_CONAN: ON
NODE_PACKAGE_TESTS_ONLY: ON
- name: node-latest-conan-linux-debug
build_node_package: true
continue-on-error: true
node: latest
runs-on: ubuntu-20.04
BUILD_TYPE: Debug
CCOMPILER: clang-6.0
CXXCOMPILER: clang++-6.0
ENABLE_CONAN: ON
NODE_PACKAGE_TESTS_ONLY: ON
name: ${{ matrix.name}}
continue-on-error: ${{ matrix.continue-on-error }}
runs-on: ${{ matrix.runs-on }}
@ -507,10 +401,11 @@ jobs:
- name: Install dev dependencies
run: |
python3 -m pip install conan==1.53.0
# workaround for issue that GitHub Actions seems to not adding it to PATH after https://github.com/actions/runner-images/pull/6499
# and that's why CI cannot find conan executable installed above
if [[ "${RUNNER_OS}" == "macOS" ]]; then
echo "/Library/Frameworks/Python.framework/Versions/3.11/bin" >> $GITHUB_PATH
echo "/Library/Frameworks/Python.framework/Versions/Current/bin" >> $GITHUB_PATH
fi
# ccache
@ -523,6 +418,12 @@ jobs:
# clang
if [[ "${CCOMPILER}" == "clang-6.0" ]]; then
sudo apt-get update -y && sudo apt-get install clang++-6
elif [[ "${CCOMPILER}" == "clang-15" ]]; then
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update -y && sudo apt-get install software-properties-common
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main'
sudo apt-get update -y && sudo apt-get install clang++-15 clang-tidy-15
sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-15 100000
fi
# Linux dev packages
@ -551,7 +452,6 @@ jobs:
tar zxvf onetbb.tgz
sudo cp -a oneapi-tbb-${TBB_VERSION}/lib/. /usr/local/lib/
sudo cp -a oneapi-tbb-${TBB_VERSION}/include/. /usr/local/include/
- name: Prepare build
run: |
mkdir ${OSRM_BUILD_DIR}
@ -640,10 +540,38 @@ jobs:
./src/benchmarks/packedvector-bench
./src/benchmarks/rtree-bench ../test/data/monaco.osrm.ramIndex ../test/data/monaco.osrm.fileIndex ../test/data/monaco.osrm.nbg_nodes
popd
- name: Run Node package tests only
- name: Use Node 16
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }}
uses: actions/setup-node@v3
with:
node-version: 16
- name: Run Node package tests on Node 16
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }}
run: |
node --version
npm run nodejs-tests
- name: Use Node 18
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }}
uses: actions/setup-node@v3
with:
node-version: 18
- name: Run Node package tests on Node 18
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }}
run: |
node --version
npm run nodejs-tests
- name: Use Node latest
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }}
uses: actions/setup-node@v3
with:
node-version: latest
- name: Run Node package tests on Node-latest
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' && matrix.ENABLE_APPLE_SILICON != 'ON' }}
run: |
node --version
npm run nodejs-tests
- name: Upload test logs
uses: actions/upload-artifact@v3
if: failure()
@ -694,6 +622,6 @@ jobs:
ci-complete:
runs-on: ubuntu-22.04
needs: [build-test-publish, docker-image, windows]
needs: [build-test-publish, docker-image, windows-release-node]
steps:
- run: echo "CI complete"

1
.gitignore vendored
View File

@ -105,3 +105,4 @@ debug.lua
# node-osrm artifacts
lib/binding

View File

@ -1,9 +1,15 @@
# Unreleased
- Changes from 5.27.1
- Build:
- ADDED: Add CI job which builds OSRM with gcc 12. [#6455](https://github.com/Project-OSRM/osrm-backend/pull/6455)
- CHANGED: Upgrade to clang-tidy 15. [#6439](https://github.com/Project-OSRM/osrm-backend/pull/6439)
- CHANGED: Update actions/cache to v3. [#6420](https://github.com/Project-OSRM/osrm-backend/pull/6420)
- REMOVED: Drop support of Node 12 & 14. [#6431](https://github.com/Project-OSRM/osrm-backend/pull/6431)
- NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc:
- CHANGED: Move vector in CSVFilesParser instead copying it. [#6470](https://github.com/Project-OSRM/osrm-backend/pull/6470)
- REMOVED: Get rid of unused functions in util/json_util.hpp. [#6446](https://github.com/Project-OSRM/osrm-backend/pull/6446)
- FIXED: Apply workaround for Conan installation issue on CI. [#6442](https://github.com/Project-OSRM/osrm-backend/pull/6442)
- FIXED: Fix `npm audit` warnings in NPM package. [#6437](https://github.com/Project-OSRM/osrm-backend/pull/6437)
- FIXED: Handle snapping parameter for all plugins in NodeJs bindings, but not for Route only. [#6417](https://github.com/Project-OSRM/osrm-backend/pull/6417)
@ -11,6 +17,7 @@
- FIXED: Fix bindings compilation issue on the latest Node. Update NAN to 2.17.0. [#6416](https://github.com/Project-OSRM/osrm-backend/pull/6416)
- CHANGED: Make edge metrics strongly typed [#6420](https://github.com/Project-OSRM/osrm-backend/pull/6420)
- FIXED: Typo in file name src/util/timed_historgram.cpp -> src/util/timed_histogram.cpp [#6428](https://github.com/Project-OSRM/osrm-backend/issues/6428)
- CHANGED: Replace boost::string_ref with std::string_view [#6433](https://github.com/Project-OSRM/osrm-backend/pull/6433)
- Routing:
- FIXED: Fix adding traffic signal penalties during compression [#6419](https://github.com/Project-OSRM/osrm-backend/pull/6419)
# 5.27.1

View File

@ -3,7 +3,7 @@
[![osrm-backend CI](https://github.com/Project-OSRM/osrm-backend/actions/workflows/osrm-backend.yml/badge.svg)](https://github.com/Project-OSRM/osrm-backend/actions/workflows/osrm-backend.yml) [![Codecov](https://codecov.io/gh/Project-OSRM/osrm-backend/branch/master/graph/badge.svg)](https://codecov.io/gh/Project-OSRM/osrm-backend) [![Discord](https://img.shields.io/discord/1034487840219860992)](https://discord.gg/es9CdcCXcb)
High performance routing engine written in C++14 designed to run on OpenStreetMap data.
High performance routing engine written in C++ designed to run on OpenStreetMap data.
The following services are available via HTTP API, C++ library interface and NodeJs wrapper:
- Nearest - Snaps coordinates to the street network and returns the nearest matches

View File

@ -57,8 +57,8 @@ class BaseAPI
{
// TODO: check forward/reverse
const auto toName = [this](const auto &phantom) {
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string();
return std::string(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)));
};
const auto noEmpty = [](const auto &name) { return !name.empty(); };
@ -128,8 +128,8 @@ class BaseAPI
static_cast<float>(static_cast<double>(util::toFloating(snapped_location.lat))));
const auto toName = [this](const auto &phantom) {
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string();
return std::string(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)));
};
const auto noEmpty = [](const auto &name) { return !name.empty(); };

View File

@ -142,7 +142,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
extractor::Datasources *m_datasources;
std::uint32_t m_check_sum;
StringView m_data_timestamp;
std::string_view m_data_timestamp;
util::vector_view<util::Coordinate> m_coordinate_list;
extractor::PackedOSMIDsView m_osmnodeid_list;
util::vector_view<std::uint32_t> m_lane_description_offsets;
@ -408,32 +408,32 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return edge_based_node_data.GetNameID(edge_based_node_id);
}
StringView GetNameForID(const NameID id) const override final
std::string_view GetNameForID(const NameID id) const override final
{
return m_name_table.GetNameForID(id);
}
StringView GetRefForID(const NameID id) const override final
std::string_view GetRefForID(const NameID id) const override final
{
return m_name_table.GetRefForID(id);
}
StringView GetPronunciationForID(const NameID id) const override final
std::string_view GetPronunciationForID(const NameID id) const override final
{
return m_name_table.GetPronunciationForID(id);
}
StringView GetDestinationsForID(const NameID id) const override final
std::string_view GetDestinationsForID(const NameID id) const override final
{
return m_name_table.GetDestinationsForID(id);
}
StringView GetExitsForID(const NameID id) const override final
std::string_view GetExitsForID(const NameID id) const override final
{
return m_name_table.GetExitsForID(id);
}
StringView GetDatasourceName(const DatasourceID id) const override final
std::string_view GetDatasourceName(const DatasourceID id) const override final
{
return m_datasources->GetSourceName(id);
}

View File

@ -26,7 +26,6 @@
#include "util/integer_range.hpp"
#include "util/packed_vector.hpp"
#include "util/string_util.hpp"
#include "util/string_view.hpp"
#include "util/typedefs.hpp"
#include "osrm/coordinate.hpp"
@ -37,6 +36,7 @@
#include <engine/bearing.hpp>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
@ -47,8 +47,6 @@ namespace engine
namespace datafacade
{
using StringView = util::StringView;
class BaseDataFacade
{
public:
@ -113,7 +111,7 @@ class BaseDataFacade
GetUncompressedReverseDatasources(const PackedGeometryID id) const = 0;
// Gets the name of a datasource
virtual StringView GetDatasourceName(const DatasourceID id) const = 0;
virtual std::string_view GetDatasourceName(const DatasourceID id) const = 0;
virtual osrm::guidance::TurnInstruction
GetTurnInstructionForEdgeID(const EdgeID edge_based_edge_id) const = 0;
@ -157,15 +155,15 @@ class BaseDataFacade
virtual NameID GetNameIndex(const NodeID edge_based_node_id) const = 0;
virtual StringView GetNameForID(const NameID id) const = 0;
virtual std::string_view GetNameForID(const NameID id) const = 0;
virtual StringView GetRefForID(const NameID id) const = 0;
virtual std::string_view GetRefForID(const NameID id) const = 0;
virtual StringView GetPronunciationForID(const NameID id) const = 0;
virtual std::string_view GetPronunciationForID(const NameID id) const = 0;
virtual StringView GetDestinationsForID(const NameID id) const = 0;
virtual std::string_view GetDestinationsForID(const NameID id) const = 0;
virtual StringView GetExitsForID(const NameID id) const = 0;
virtual std::string_view GetExitsForID(const NameID id) const = 0;
virtual bool GetContinueStraightDefault() const = 0;

View File

@ -145,11 +145,11 @@ inline std::string assembleSummary(const datafacade::BaseDataFacade &facade,
const auto name_id_to_string = [&](const NameID name_id) {
const auto name = facade.GetNameForID(name_id);
if (!name.empty())
return name.to_string();
return std::string(name);
else
{
const auto ref = facade.GetRefForID(name_id);
return ref.to_string();
return std::string(ref);
}
};

View File

@ -140,11 +140,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{path_point.from_edge_based_node,
step_name_id,
is_segregated,
name.to_string(),
ref.to_string(),
pronunciation.to_string(),
destinations.to_string(),
exits.to_string(),
std::string(name),
std::string(ref),
std::string(pronunciation),
std::string(destinations),
std::string(exits),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
from_alias<double>(segment_duration) / 10.,
@ -241,11 +241,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{leg_data[leg_data.size() - 1].from_edge_based_node,
step_name_id,
is_segregated,
facade.GetNameForID(step_name_id).to_string(),
facade.GetRefForID(step_name_id).to_string(),
facade.GetPronunciationForID(step_name_id).to_string(),
facade.GetDestinationsForID(step_name_id).to_string(),
facade.GetExitsForID(step_name_id).to_string(),
std::string(facade.GetNameForID(step_name_id)),
std::string(facade.GetRefForID(step_name_id)),
std::string(facade.GetPronunciationForID(step_name_id)),
std::string(facade.GetDestinationsForID(step_name_id)),
std::string(facade.GetExitsForID(step_name_id)),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
from_alias<double>(duration) / 10.,
@ -287,11 +287,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{source_node_id,
source_name_id,
is_segregated,
facade.GetNameForID(source_name_id).to_string(),
facade.GetRefForID(source_name_id).to_string(),
facade.GetPronunciationForID(source_name_id).to_string(),
facade.GetDestinationsForID(source_name_id).to_string(),
facade.GetExitsForID(source_name_id).to_string(),
std::string(facade.GetNameForID(source_name_id)),
std::string(facade.GetRefForID(source_name_id)),
std::string(facade.GetPronunciationForID(source_name_id)),
std::string(facade.GetDestinationsForID(source_name_id)),
std::string(facade.GetExitsForID(source_name_id)),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
from_alias<double>(duration) / 10.,
@ -330,11 +330,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{target_node_id,
target_name_id,
facade.IsSegregated(target_node_id),
facade.GetNameForID(target_name_id).to_string(),
facade.GetRefForID(target_name_id).to_string(),
facade.GetPronunciationForID(target_name_id).to_string(),
facade.GetDestinationsForID(target_name_id).to_string(),
facade.GetExitsForID(target_name_id).to_string(),
std::string(facade.GetNameForID(target_name_id)),
std::string(facade.GetRefForID(target_name_id)),
std::string(facade.GetPronunciationForID(target_name_id)),
std::string(facade.GetDestinationsForID(target_name_id)),
std::string(facade.GetExitsForID(target_name_id)),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
ZERO_DURATION,

View File

@ -1,9 +1,12 @@
#ifndef OSRM_EXTRACT_DATASOURCES_HPP
#define OSRM_EXTRACT_DATASOURCES_HPP
#include "util/typedefs.hpp"
#include <algorithm>
#include <array>
#include <cstdint>
#include <util/string_view.hpp>
#include <util/typedefs.hpp>
#include <string_view>
namespace osrm
{
@ -22,11 +25,11 @@ class Datasources
std::fill(sources.begin(), sources.end(), '\0');
}
util::StringView GetSourceName(DatasourceID id) const
std::string_view GetSourceName(DatasourceID id) const
{
auto begin = sources.data() + (MAX_LENGTH_NAME * id);
return util::StringView{begin, lengths[id]};
return std::string_view{begin, lengths[id]};
}
void SetSourceName(DatasourceID id, const std::string &name)

View File

@ -2,10 +2,10 @@
#define OSRM_EXTRACTOR_NAME_TABLE_HPP
#include "util/indexed_data.hpp"
#include "util/string_view.hpp"
#include "util/typedefs.hpp"
#include <string>
#include <string_view>
namespace osrm
{
@ -50,7 +50,7 @@ template <storage::Ownership Ownership> class NameTableImpl
{
public:
using IndexedData =
util::detail::IndexedDataImpl<util::VariableGroupBlock<16, util::StringView>, Ownership>;
util::detail::IndexedDataImpl<util::VariableGroupBlock<16, std::string_view>, Ownership>;
using ResultType = typename IndexedData::ResultType;
using ValueType = typename IndexedData::ValueType;
@ -58,7 +58,7 @@ template <storage::Ownership Ownership> class NameTableImpl
NameTableImpl(IndexedData indexed_data_) : indexed_data{std::move(indexed_data_)} {}
util::StringView GetNameForID(const NameID id) const
std::string_view GetNameForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};
@ -66,7 +66,7 @@ template <storage::Ownership Ownership> class NameTableImpl
return indexed_data.at(id + 0);
}
util::StringView GetDestinationsForID(const NameID id) const
std::string_view GetDestinationsForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};
@ -74,7 +74,7 @@ template <storage::Ownership Ownership> class NameTableImpl
return indexed_data.at(id + 1);
}
util::StringView GetExitsForID(const NameID id) const
std::string_view GetExitsForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};
@ -82,7 +82,7 @@ template <storage::Ownership Ownership> class NameTableImpl
return indexed_data.at(id + 4);
}
util::StringView GetRefForID(const NameID id) const
std::string_view GetRefForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};
@ -91,7 +91,7 @@ template <storage::Ownership Ownership> class NameTableImpl
return indexed_data.at(id + OFFSET_REF);
}
util::StringView GetPronunciationForID(const NameID id) const
std::string_view GetPronunciationForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};

View File

@ -2,9 +2,9 @@
#define OSRM_EXTRACTOR_SUFFIX_LIST_HPP_
#include <string>
#include <string_view>
#include <unordered_set>
#include "util/string_view.hpp"
#include <vector>
namespace osrm
{
@ -23,7 +23,7 @@ class SuffixTable final
// check whether a string is part of the know suffix list
bool isSuffix(const std::string &possible_suffix) const;
bool isSuffix(util::StringView possible_suffix) const;
bool isSuffix(std::string_view possible_suffix) const;
private:
// Store lower-cased strings in SuffixTable and a set of StringViews for quick membership
@ -36,7 +36,7 @@ class SuffixTable final
// require us to first convert StringViews into strings (allocation), do the membership,
// and destroy the StringView again.
std::vector<std::string> suffixes;
std::unordered_set<util::StringView> suffix_set;
std::unordered_set<std::string_view> suffix_set;
};
} /* namespace extractor */

View File

@ -2,11 +2,7 @@
#define OSRM_BINDINGS_NODE_JSON_V8_RENDERER_HPP
#include "osrm/json_container.hpp"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <nan.h>
#pragma GCC diagnostic pop
#include <napi.h>
#include <functional>
@ -15,52 +11,56 @@ namespace node_osrm
struct V8Renderer
{
explicit V8Renderer(v8::Local<v8::Value> &_out) : out(_out) {}
explicit V8Renderer(const Napi::Env &env, Napi::Value &out) : env(env), out(out) {}
void operator()(const osrm::json::String &string) const
{
out = Nan::New(std::cref(string.value)).ToLocalChecked();
out = Napi::String::New(env, string.value);
}
void operator()(const osrm::json::Number &number) const { out = Nan::New(number.value); }
void operator()(const osrm::json::Number &number) const
{
out = Napi::Number::New(env, number.value);
}
void operator()(const osrm::json::Object &object) const
{
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
Napi::Object obj = Napi::Object::New(env);
for (const auto &keyValue : object.values)
{
v8::Local<v8::Value> child;
mapbox::util::apply_visitor(V8Renderer(child), keyValue.second);
Nan::Set(obj, Nan::New(keyValue.first).ToLocalChecked(), child);
Napi::Value child;
mapbox::util::apply_visitor(V8Renderer(env, child), keyValue.second);
obj.Set(keyValue.first, child);
}
out = obj;
}
void operator()(const osrm::json::Array &array) const
{
v8::Local<v8::Array> a = Nan::New<v8::Array>(array.values.size());
Napi::Array a = Napi::Array::New(env, array.values.size());
for (auto i = 0u; i < array.values.size(); ++i)
{
v8::Local<v8::Value> child;
mapbox::util::apply_visitor(V8Renderer(child), array.values[i]);
Nan::Set(a, i, child);
Napi::Value child;
mapbox::util::apply_visitor(V8Renderer(env, child), array.values[i]);
a.Set(i, child);
}
out = a;
}
void operator()(const osrm::json::True &) const { out = Nan::New(true); }
void operator()(const osrm::json::True &) const { out = Napi::Boolean::New(env, true); }
void operator()(const osrm::json::False &) const { out = Nan::New(false); }
void operator()(const osrm::json::False &) const { out = Napi::Boolean::New(env, false); }
void operator()(const osrm::json::Null &) const { out = Nan::Null(); }
void operator()(const osrm::json::Null &) const { out = env.Null(); }
private:
v8::Local<v8::Value> &out;
const Napi::Env &env;
Napi::Value &out;
};
inline void renderToV8(v8::Local<v8::Value> &out, const osrm::json::Object &object)
inline void renderToV8(const Napi::Env &env, Napi::Value &out, const osrm::json::Object &object)
{
V8Renderer renderer(out);
V8Renderer renderer(env, out);
renderer(object);
}
} // namespace node_osrm

View File

@ -3,45 +3,30 @@
#include "osrm/osrm_fwd.hpp"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <nan.h>
#pragma GCC diagnostic pop
#include <napi.h>
#include <memory>
namespace node_osrm
{
struct Engine final : public Nan::ObjectWrap
class Engine final : public Napi::ObjectWrap<Engine>
{
using Base = Nan::ObjectWrap;
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);
Engine(const Napi::CallbackInfo &info);
static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);
static NAN_METHOD(route);
static NAN_METHOD(nearest);
static NAN_METHOD(table);
static NAN_METHOD(tile);
static NAN_METHOD(match);
static NAN_METHOD(trip);
Engine(osrm::EngineConfig &config);
// Thread-safe singleton accessor
static Nan::Persistent<v8::Function> &constructor();
// Ref-counted OSRM alive even after shutdown until last callback is done
std::shared_ptr<osrm::OSRM> this_;
private:
Napi::Value route(const Napi::CallbackInfo &info);
Napi::Value nearest(const Napi::CallbackInfo &info);
Napi::Value table(const Napi::CallbackInfo &info);
Napi::Value tile(const Napi::CallbackInfo &info);
Napi::Value match(const Napi::CallbackInfo &info);
Napi::Value trip(const Napi::CallbackInfo &info);
};
} // namespace node_osrm
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
NAN_MODULE_WORKER_ENABLED(osrm, node_osrm::Engine::Init)
#pragma GCC diagnostic pop
#endif

File diff suppressed because it is too large Load Diff

View File

@ -10,8 +10,8 @@
#include "storage/tar.hpp"
#include <boost/assert.hpp>
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_input_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
#include <cmath>
#include <cstdint>

View File

@ -3,7 +3,7 @@
#include "storage/shared_datatype.hpp"
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
#include <type_traits>
#include <unordered_map>

View File

@ -263,7 +263,7 @@ inline auto make_partition_view(const SharedDataIndex &index, const std::string
inline auto make_timestamp_view(const SharedDataIndex &index, const std::string &name)
{
return util::StringView(index.GetBlockPtr<char>(name), index.GetBlockEntries(name));
return std::string_view(index.GetBlockPtr<char>(name), index.GetBlockEntries(name));
}
inline auto make_cell_storage_view(const SharedDataIndex &index, const std::string &name)

View File

@ -78,7 +78,7 @@ template <typename Key, typename Value> struct CSVFilesParser
util::Log() << "In total loaded " << csv_filenames.size() << " file(s) with a total of "
<< lookup.size() << " unique values";
return LookupTable<Key, Value>{lookup};
return LookupTable<Key, Value>{std::move(lookup)};
}
catch (const std::exception &e)
// TBB should capture to std::exception_ptr and automatically rethrow in this thread.

View File

@ -1,22 +0,0 @@
#ifndef CONTAINER_HPP
#define CONTAINER_HPP
#include <utility>
namespace osrm
{
namespace util
{
template <class Container> void append_to_container(Container &&) {}
template <class Container, typename T, typename... Args>
void append_to_container(Container &&container, T value, Args &&... args)
{
container.emplace_back(value);
append_to_container(std::forward<Container>(container), std::forward<Args>(args)...);
}
} // namespace util
} // namespace osrm
#endif

View File

@ -27,8 +27,8 @@ namespace guidance
// Name Change Logic
// Used both during Extraction as well as during Post-Processing
inline util::StringView longest_common_substring(const util::StringView &lhs,
const util::StringView &rhs)
inline std::string_view longest_common_substring(const std::string_view lhs,
const std::string_view rhs)
{
if (lhs.empty() || rhs.empty())
return "";
@ -70,7 +70,11 @@ template <typename StringView> inline auto decompose(const StringView &lhs, cons
const auto trim = [](StringView view) {
// we compare suffixes based on this value, it might break UTF chars, but as long as we are
// consistent in handling, we do not create bad results
std::string str = boost::to_lower_copy(view.to_string());
std::string str;
str.reserve(view.size());
std::transform(view.begin(), view.end(), std::back_inserter(str), [](unsigned char c) {
return std::tolower(c);
});
auto front = str.find_first_not_of(' ');
if (front == std::string::npos)
@ -129,20 +133,20 @@ inline bool requiresNameAnnounced(const StringView &from_name,
const auto name_is_contained =
boost::starts_with(from_name, to_name) || boost::starts_with(to_name, from_name);
const auto checkForPrefixOrSuffixChange =
[](const StringView &first, const StringView &second, const SuffixTable &suffix_table) {
std::string first_prefix, first_suffix, second_prefix, second_suffix;
std::tie(first_prefix, first_suffix, second_prefix, second_suffix) =
decompose(first, second);
const auto checkTable = [&](const std::string &str) {
return str.empty() || suffix_table.isSuffix(str);
};
return checkTable(first_prefix) && checkTable(first_suffix) &&
checkTable(second_prefix) && checkTable(second_suffix);
const auto checkForPrefixOrSuffixChange = [](const std::string_view first,
const std::string_view second,
const SuffixTable &suffix_table) {
std::string first_prefix, first_suffix, second_prefix, second_suffix;
std::tie(first_prefix, first_suffix, second_prefix, second_suffix) =
decompose(first, second);
const auto checkTable = [&](const std::string &str) {
return str.empty() || suffix_table.isSuffix(str);
};
return checkTable(first_prefix) && checkTable(first_suffix) && checkTable(second_prefix) &&
checkTable(second_suffix);
};
const auto is_suffix_change = checkForPrefixOrSuffixChange(from_name, to_name, suffix_table);
const auto names_are_equal = from_name == to_name || name_is_contained || is_suffix_change;
const auto name_is_removed = !from_name.empty() && to_name.empty();
@ -201,17 +205,17 @@ inline bool requiresNameAnnounced(const std::string &from_name,
struct NopSuffixTable final
{
NopSuffixTable() {}
bool isSuffix(const StringView &) const { return false; }
bool isSuffix(const std::string_view) const { return false; }
} static const table;
return requiresNameAnnounced(util::StringView(from_name),
util::StringView(from_ref),
util::StringView(from_pronunciation),
util::StringView(from_exits),
util::StringView(to_name),
util::StringView(to_ref),
util::StringView(to_pronunciation),
util::StringView(to_exits),
return requiresNameAnnounced(std::string_view(from_name),
std::string_view(from_ref),
std::string_view(from_pronunciation),
std::string_view(from_exits),
std::string_view(to_name),
std::string_view(to_ref),
std::string_view(to_pronunciation),
std::string_view(to_exits),
table);
}

View File

@ -4,16 +4,16 @@
#include "storage/tar_fwd.hpp"
#include "util/exception.hpp"
#include "util/string_view.hpp"
#include "util/vector_view.hpp"
#include <boost/assert.hpp>
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
#include <array>
#include <iterator>
#include <limits>
#include <string>
#include <string_view>
#include <type_traits>
namespace osrm
@ -216,7 +216,7 @@ template <int N, typename T = std::string> struct FixedGroupBlock
std::numeric_limits<std::make_unsigned_t<ValueType>>::max();
auto index = 0;
std::array<ValueType, BLOCK_SIZE> prefix;
std::array<ValueType, BLOCK_SIZE> prefix{};
for (OffsetIterator curr = first, next = std::next(first); curr != last; ++curr, ++next)
{
@ -365,14 +365,14 @@ template <typename GroupBlockPolicy, storage::Ownership Ownership> struct Indexe
std::enable_if_t<std::is_same<T, typename std::iterator_traits<Iter>::value_type>::value>;
template <typename T = ResultType, typename Iter, typename = IsValueIterator<Iter, ValueType>>
typename std::enable_if<!std::is_same<T, StringView>::value, T>::type
typename std::enable_if<!std::is_same<T, std::string_view>::value, T>::type
adapt(const Iter first, const Iter last) const
{
return ResultType(first, last);
}
template <typename T = ResultType, typename Iter, typename = IsValueIterator<Iter, ValueType>>
typename std::enable_if<std::is_same<T, StringView>::value, T>::type
typename std::enable_if<std::is_same<T, std::string_view>::value, T>::type
adapt(const Iter first, const Iter last) const
{
auto diff = std::distance(first, last);

View File

@ -2,7 +2,6 @@
#define JSON_UTIL_HPP
#include "osrm/json_container.hpp"
#include "util/container.hpp"
#include <cmath>
#include <limits>
@ -27,30 +26,6 @@ template <typename T> T clamp_float(T d)
return d;
}
template <typename... Args> Array make_array(Args... args)
{
Array a;
// TODO: check why a.values.emplace_back(args...); is not an option here
append_to_container(a.values, args...);
return a;
}
// Easy acces to object hierachies
inline Value &get(Value &value) { return value; }
template <typename... Keys> Value &get(Value &value, const char *key, Keys... keys)
{
using recursive_object_t = mapbox::util::recursive_wrapper<Object>;
return get(value.get<recursive_object_t>().get().values[key], keys...);
}
template <typename... Keys> Value &get(Value &value, unsigned key, Keys... keys)
{
using recursive_array_t = mapbox::util::recursive_wrapper<Array>;
return get(value.get<recursive_array_t>().get().values[key], keys...);
}
} // namespace json
} // namespace util
} // namespace osrm

View File

@ -1,34 +0,0 @@
#ifndef OSRM_STRING_VIEW_HPP
#define OSRM_STRING_VIEW_HPP
#include <boost/functional/hash.hpp>
#include <boost/utility/string_ref.hpp>
namespace osrm
{
namespace util
{
// Convenience typedef: boost::string_ref, boost::string_view or C++17's string_view
using StringView = boost::string_ref;
} // namespace util
} // namespace osrm
// Specializing hash<> for user-defined type in std namespace, this is standard conforming.
namespace std
{
template <> struct hash<::osrm::util::StringView> final
{
std::size_t operator()(::osrm::util::StringView v) const noexcept
{
// Bring into scope and call un-qualified for ADL:
// remember we want to be able to switch impl. above.
using std::begin;
using std::end;
return boost::hash_range(begin(v), end(v));
}
};
} // namespace std
#endif /* OSRM_STRING_VIEW_HPP */

1
lib/binding_napi_v8 Symbolic link
View File

@ -0,0 +1 @@
binding

139
package-lock.json generated
View File

@ -36,7 +36,7 @@
"faucet": "^0.0.1",
"jsonpath": "^1.1.1",
"mkdirp": "^0.5.6",
"nan": "^2.17.0",
"node-addon-api": "^5.0.0",
"node-cmake": "^2.5.1",
"node-timeout": "0.0.4",
"polyline": "^0.2.0",
@ -5436,9 +5436,9 @@
}
},
"node_modules/color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"node_modules/color-string": {
@ -6011,6 +6011,15 @@
"integrity": "sha1-skbCuApXCkfBG+HZvRBw7IeLh84=",
"dev": true
},
"node_modules/deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",
"dev": true,
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/deep-is": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
@ -9114,7 +9123,7 @@
"node_modules/find-up": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
"integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=",
"integrity": "sha512-jvElSjyuo4EMQGoTwo1uJU5pQMwTW5lS1x05zzfJuTIyLR3zwO27LYrxNg+dlvKpGOuGy/MzBdXh80g0ve5+HA==",
"dev": true,
"dependencies": {
"path-exists": "^2.0.0",
@ -10038,13 +10047,10 @@
"dev": true
},
"node_modules/graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=",
"dev": true,
"engines": {
"node": ">=0.4.0"
}
"version": "4.2.10",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==",
"dev": true
},
"node_modules/gulp-sourcemaps": {
"version": "1.6.0",
@ -11854,7 +11860,7 @@
"node_modules/load-json-file": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
"integrity": "sha512-cy7ZdNRXdablkXYNI049pthVeXFurRyb9+hA/dZzerZ0pGTx42z+y+ssxBaVV2l70t1muq5IdKhn4UtcoGUY9A==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.1.2",
@ -12711,6 +12717,12 @@
"lower-case": "^1.1.1"
}
},
"node_modules/node-addon-api": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.0.0.tgz",
"integrity": "sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA==",
"dev": true
},
"node_modules/node-cmake": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/node-cmake/-/node-cmake-2.5.1.tgz",
@ -13481,7 +13493,7 @@
"node_modules/path-type": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
"integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=",
"integrity": "sha512-S4eENJz1pkiQn9Znv33Q+deTOKmbl+jj1Fl+qiP/vYezj+S8x+J3Uo0ISrx/QoEvIlOaDWJhPaRd1flJ9HXZqg==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.1.2",
@ -13536,7 +13548,7 @@
"node_modules/pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==",
"dev": true,
"engines": {
"node": ">=0.10.0"
@ -14276,7 +14288,7 @@
"node_modules/read-pkg": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
"integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=",
"integrity": "sha512-7BGwRHqt4s/uVbuyoeejRn4YmFnYZiFl4AuaeXHlgZf3sONF0SOGlxs2Pw8g6hCKupo08RafIO5YXFNOKTfwsQ==",
"dev": true,
"dependencies": {
"load-json-file": "^1.0.0",
@ -14290,7 +14302,7 @@
"node_modules/read-pkg-up": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz",
"integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=",
"integrity": "sha512-WD9MTlNtI55IwYUS27iHh9tK3YoIVhxis8yKhLpTqWtml739uXc9NWTpxoHkfZf3+DkCCsXox94/VWZniuZm6A==",
"dev": true,
"dependencies": {
"find-up": "^1.0.0",
@ -15126,9 +15138,9 @@
}
},
"node_modules/signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
},
"node_modules/simple-concat": {
"version": "1.0.1",
@ -16644,15 +16656,6 @@
"node": ">=4.0.0"
}
},
"node_modules/table-layout/node_modules/deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",
"dev": true,
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/table/node_modules/ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
@ -18846,9 +18849,9 @@
"dev": true
},
"node_modules/yargs": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.1.tgz",
"integrity": "sha512-huO4Fr1f9PmiJJdll5kwoS2e4GqzGSsMT3PPMpOwoVkOK8ckqAewMTZyA6LXVQWflleb/Z8oPBEvNsMft0XE+g==",
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.2.tgz",
"integrity": "sha512-ZEjj/dQYQy0Zx0lgLMLR8QuaqTihnxirir7EwUHp1Axq4e3+k8jXU5K0VLbNvedv1f4EWtBonDIZm0NUr+jCcA==",
"dev": true,
"dependencies": {
"camelcase": "^3.0.0",
@ -18863,13 +18866,13 @@
"string-width": "^1.0.2",
"which-module": "^1.0.0",
"y18n": "^3.2.1",
"yargs-parser": "5.0.0-security.0"
"yargs-parser": "^5.0.1"
}
},
"node_modules/yargs-parser": {
"version": "5.0.0-security.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.0-security.0.tgz",
"integrity": "sha512-T69y4Ps64LNesYxeYGYPvfoMTt/7y1XtfpIslUeK4um+9Hu7hlGoRtaDLvdXb7+/tfq4opVa2HRY5xGip022rQ==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.1.tgz",
"integrity": "sha512-wpav5XYiddjXxirPoCTUPbqM0PXvJ9hiBMvuJgInvo4/lAOTZzUprArw17q2O1P2+GHhbBr18/iQwjL5Z9BqfA==",
"dev": true,
"dependencies": {
"camelcase": "^3.0.0",
@ -23193,9 +23196,9 @@
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true
},
"color-string": {
@ -23690,6 +23693,12 @@
"integrity": "sha1-skbCuApXCkfBG+HZvRBw7IeLh84=",
"dev": true
},
"deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",
"dev": true
},
"deep-is": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
@ -26233,7 +26242,7 @@
"find-up": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
"integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=",
"integrity": "sha512-jvElSjyuo4EMQGoTwo1uJU5pQMwTW5lS1x05zzfJuTIyLR3zwO27LYrxNg+dlvKpGOuGy/MzBdXh80g0ve5+HA==",
"dev": true,
"requires": {
"path-exists": "^2.0.0",
@ -26966,9 +26975,9 @@
"dev": true
},
"graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=",
"version": "4.2.10",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==",
"dev": true
},
"gulp-sourcemaps": {
@ -28353,7 +28362,7 @@
"load-json-file": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",
"integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=",
"integrity": "sha512-cy7ZdNRXdablkXYNI049pthVeXFurRyb9+hA/dZzerZ0pGTx42z+y+ssxBaVV2l70t1muq5IdKhn4UtcoGUY9A==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
@ -29082,6 +29091,12 @@
"lower-case": "^1.1.1"
}
},
"node-addon-api": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.0.0.tgz",
"integrity": "sha512-CvkDw2OEnme7ybCykJpVcKH+uAOLV2qLqiyla128dN9TkEWfrYmxG6C2boDe5KcNQqZF3orkqzGgOMvZ/JNekA==",
"dev": true
},
"node-cmake": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/node-cmake/-/node-cmake-2.5.1.tgz",
@ -29696,7 +29711,7 @@
"path-type": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
"integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=",
"integrity": "sha512-S4eENJz1pkiQn9Znv33Q+deTOKmbl+jj1Fl+qiP/vYezj+S8x+J3Uo0ISrx/QoEvIlOaDWJhPaRd1flJ9HXZqg==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.2",
@ -29739,7 +29754,7 @@
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
"integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==",
"dev": true
},
"pinkie": {
@ -30383,7 +30398,7 @@
"read-pkg": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
"integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=",
"integrity": "sha512-7BGwRHqt4s/uVbuyoeejRn4YmFnYZiFl4AuaeXHlgZf3sONF0SOGlxs2Pw8g6hCKupo08RafIO5YXFNOKTfwsQ==",
"dev": true,
"requires": {
"load-json-file": "^1.0.0",
@ -30394,7 +30409,7 @@
"read-pkg-up": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz",
"integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=",
"integrity": "sha512-WD9MTlNtI55IwYUS27iHh9tK3YoIVhxis8yKhLpTqWtml739uXc9NWTpxoHkfZf3+DkCCsXox94/VWZniuZm6A==",
"dev": true,
"requires": {
"find-up": "^1.0.0",
@ -31099,9 +31114,9 @@
}
},
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
},
"simple-concat": {
"version": "1.0.1",
@ -32325,14 +32340,6 @@
"lodash.padend": "^4.6.1",
"typical": "^2.6.1",
"wordwrapjs": "^3.0.0"
},
"dependencies": {
"deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",
"dev": true
}
}
},
"tap-parser": {
@ -34121,9 +34128,9 @@
"dev": true
},
"yargs": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.1.tgz",
"integrity": "sha512-huO4Fr1f9PmiJJdll5kwoS2e4GqzGSsMT3PPMpOwoVkOK8ckqAewMTZyA6LXVQWflleb/Z8oPBEvNsMft0XE+g==",
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.2.tgz",
"integrity": "sha512-ZEjj/dQYQy0Zx0lgLMLR8QuaqTihnxirir7EwUHp1Axq4e3+k8jXU5K0VLbNvedv1f4EWtBonDIZm0NUr+jCcA==",
"dev": true,
"requires": {
"camelcase": "^3.0.0",
@ -34138,13 +34145,13 @@
"string-width": "^1.0.2",
"which-module": "^1.0.0",
"y18n": "^3.2.1",
"yargs-parser": "5.0.0-security.0"
"yargs-parser": "^5.0.1"
}
},
"yargs-parser": {
"version": "5.0.0-security.0",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.0-security.0.tgz",
"integrity": "sha512-T69y4Ps64LNesYxeYGYPvfoMTt/7y1XtfpIslUeK4um+9Hu7hlGoRtaDLvdXb7+/tfq4opVa2HRY5xGip022rQ==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.1.tgz",
"integrity": "sha512-wpav5XYiddjXxirPoCTUPbqM0PXvJ9hiBMvuJgInvo4/lAOTZzUprArw17q2O1P2+GHhbBr18/iQwjL5Z9BqfA==",
"dev": true,
"requires": {
"camelcase": "^3.0.0",

View File

@ -2,7 +2,7 @@
"name": "@project-osrm/osrm",
"version": "5.28.0-unreleased",
"private": false,
"description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.",
"description": "The Open Source Routing Machine is a high performance routing engine written in C++ designed to run on OpenStreetMap data.",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.10"
},
@ -45,6 +45,7 @@
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"chalk": "^1.1.3",
"cheap-ruler": "^3.0.2",
"command-line-args": "^5.2.1",
"command-line-usage": "^5.0.4",
"csv-stringify": "^3.0.0",
@ -55,26 +56,26 @@
"eslint": "^5.16.0",
"faucet": "^0.0.1",
"jsonpath": "^1.1.1",
"mkdirp": "^0.5.6",
"node-addon-api": "^5.0.0",
"node-timeout": "0.0.4",
"polyline": "^0.2.0",
"request": "^2.88.2",
"rimraf": "^2.7.1",
"tape": "^4.16.0",
"turf": "^3.0.14",
"uglify-js": "^3.17.0",
"xmlbuilder": "^4.2.1",
"cheap-ruler": "^3.0.2",
"mkdirp": "^0.5.6",
"nan": "^2.17.0",
"node-cmake": "^2.5.1",
"rimraf": "^2.7.1"
"node-cmake": "^2.5.1"
},
"main": "lib/index.js",
"binary": {
"napi_versions": [8],
"module_name": "node_osrm",
"module_path": "./lib/binding/",
"module_path": "./lib/binding_napi_v{napi_build_version}/",
"host": "https://github.com",
"remote_path": "./Project-OSRM/osrm-backend/releases/download/v{version}/",
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}-{configuration}.tar.gz"
"package_name": "{module_name}-v{version}-{napi_build_version}-{platform}-{arch}-{configuration}.tar.gz"
},
"publishConfig": {
"access": "public"

View File

@ -276,6 +276,7 @@ function setup()
["be-vlg:rural"] = 70,
["by:urban"] = 60,
["by:motorway"] = 110,
["ca-on:rural"] = 80,
["ch:rural"] = 80,
["ch:trunk"] = 100,
["ch:motorway"] = 120,
@ -285,6 +286,7 @@ function setup()
["de:rural"] = 100,
["de:motorway"] = 0,
["dk:rural"] = 80,
["es:trunk"] = 90,
["fr:rural"] = 80,
["gb:nsl_single"] = (60*1609)/1000,
["gb:nsl_dual"] = (70*1609)/1000,

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);

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);

View File

@ -13,7 +13,7 @@
#include <utility>
#include <vector>
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
namespace osrm
{

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>

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;
}

View File

@ -24,7 +24,7 @@ struct EdgeInfo
NodeID node;
util::StringView name;
std::string_view name;
bool reversed;

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

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)

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>

View File

@ -152,6 +152,7 @@
{"key": "maxspeed", "value": "BE-VLG:rural"},
{"key": "maxspeed", "value": "BY:urban"},
{"key": "maxspeed", "value": "BY:motorway"},
{"key": "maxspeed", "value": "CA-ON:rural"},
{"key": "maxspeed", "value": "CH:rural"},
{"key": "maxspeed", "value": "CH:trunk"},
{"key": "maxspeed", "value": "CH:motorway"},
@ -161,6 +162,7 @@
{"key": "maxspeed", "value": "DE:rural"},
{"key": "maxspeed", "value": "DE:motorway"},
{"key": "maxspeed", "value": "DK:rural"},
{"key": "maxspeed", "value": "ES:trunk"},
{"key": "maxspeed", "value": "FR:rural"},
{"key": "maxspeed", "value": "GB:nsl_single"},
{"key": "maxspeed", "value": "GB:nsl_dual"},

51
test/nodejs/benchmark.js Normal file
View File

@ -0,0 +1,51 @@
const OSRM = require('../../');
const {performance, createHistogram} = require('node:perf_hooks');
// usage: node test/nodejs/benchmark.js berlin-latest.osrm 13.388860,52.517037;13.385983,52.496891
const args = process.argv.slice(2);
const path = args[0] || require('./constants').mld_data_path;
function parseWaypoints(waypoints) {
if (waypoints == undefined) {
return undefined;
}
return waypoints.split(';').map((waypoint) => {
const [lon, lat] = waypoint.split(',');
return [parseFloat(lon), parseFloat(lat)];
});
}
const waypoints = parseWaypoints(args[1]) || [[7.41337, 43.72956],[7.41546, 43.73077]];
const osrm = new OSRM({path, algorithm: 'MLD'});
async function route(coordinates) {
const promise = new Promise((resolve, reject) => {
osrm.route({coordinates, steps: true, overview: 'full'}, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
return promise;
}
async function benchmark() {
// warmup
await route(waypoints);
const performanceHistorgram = createHistogram();
for (let i = 0; i < 1000; i++) {
const start = performance.now();
await route(waypoints);
const end = performance.now();
// record result in microseconds
performanceHistorgram.record(Math.ceil((end - start) * 1000));
}
console.log(performanceHistorgram);
}
benchmark();

View File

@ -8,7 +8,7 @@ var monaco_corech_path = require('./constants').corech_data_path;
test('constructor: throws if new keyword is not used', function(assert) {
assert.plan(1);
assert.throws(function() { OSRM(); },
/Cannot call constructor as function, you need to use 'new' keyword/);
/Class constructors cannot be invoked without 'new'/);
});
test('constructor: uses defaults with no parameter', function(assert) {

View File

@ -203,7 +203,10 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
return DatasourceReverseRange(DatasourceForwardRange());
}
StringView GetDatasourceName(const DatasourceID /*id*/) const override { return StringView{}; }
std::string_view GetDatasourceName(const DatasourceID /*id*/) const override
{
return std::string_view{};
}
guidance::TurnInstruction GetTurnInstructionForEdgeID(const EdgeID /*id*/) const override
{
@ -270,11 +273,20 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
bool HasLaneData(const EdgeID /*id*/) const override { return false; }
NameID GetNameIndex(const NodeID /*nodeID*/) const override { return EMPTY_NAMEID; }
StringView GetNameForID(const NameID /*id*/) const override { return StringView{}; }
StringView GetRefForID(const NameID /*id*/) const override { return StringView{}; }
StringView GetPronunciationForID(const NameID /*id*/) const override { return StringView{}; }
StringView GetDestinationsForID(const NameID /*id*/) const override { return StringView{}; }
StringView GetExitsForID(const NameID /*id*/) const override { return StringView{}; }
std::string_view GetNameForID(const NameID /*id*/) const override { return std::string_view{}; }
std::string_view GetRefForID(const NameID /*id*/) const override { return std::string_view{}; }
std::string_view GetPronunciationForID(const NameID /*id*/) const override
{
return std::string_view{};
}
std::string_view GetDestinationsForID(const NameID /*id*/) const override
{
return std::string_view{};
}
std::string_view GetExitsForID(const NameID /*id*/) const override
{
return std::string_view{};
}
bool GetContinueStraightDefault() const override { return false; }
std::string GetTimestamp() const override { return ""; }
double GetMapMatchingMaxSpeed() const override { return 0; }

View File

@ -26,8 +26,6 @@ namespace test
class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
{
using StringView = util::StringView;
public:
bool ExcludeNode(const NodeID) const override { return false; };
@ -95,7 +93,7 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
return DatasourceReverseRange(DatasourceForwardRange());
}
StringView GetDatasourceName(const DatasourceID) const override final { return {}; }
std::string_view GetDatasourceName(const DatasourceID) const override final { return {}; }
osrm::guidance::TurnInstruction
GetTurnInstructionForEdgeID(const EdgeID /* id */) const override
@ -154,11 +152,11 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
NameID GetNameIndex(const NodeID /* id */) const override { return 0; }
StringView GetNameForID(const NameID) const override final { return {}; }
StringView GetRefForID(const NameID) const override final { return {}; }
StringView GetPronunciationForID(const NameID) const override final { return {}; }
StringView GetDestinationsForID(const NameID) const override final { return {}; }
StringView GetExitsForID(const NameID) const override final { return {}; }
std::string_view GetNameForID(const NameID) const override final { return {}; }
std::string_view GetRefForID(const NameID) const override final { return {}; }
std::string_view GetPronunciationForID(const NameID) const override final { return {}; }
std::string_view GetDestinationsForID(const NameID) const override final { return {}; }
std::string_view GetExitsForID(const NameID) const override final { return {}; }
bool GetContinueStraightDefault() const override { return true; }
double GetMapMatchingMaxSpeed() const override { return 180 / 3.6; }

View File

@ -3,8 +3,8 @@
#include "../common/range_tools.hpp"
#include "../common/temporary_file.hpp"
#include <boost/function_output_iterator.hpp>
#include <boost/iterator/function_input_iterator.hpp>
#include <boost/iterator/function_output_iterator.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(tar)

View File

@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(check_string_view)
std::string name_data = "hellostringview";
std::vector<std::uint32_t> name_offsets = {0, 5, 11, 15};
IndexedData<VariableGroupBlock<16, StringView>> indexed_data(
IndexedData<VariableGroupBlock<16, std::string_view>> indexed_data(
name_offsets.begin(), name_offsets.end(), name_data.begin());
BOOST_CHECK_EQUAL(indexed_data.at(0), "hello");