Merge pull request #6433 from Project-OSRM/replace_boost_stringref
Replace boost::string_ref with std::string_view
This commit is contained in:
commit
aeaf5e0735
@ -11,6 +11,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)
|
- 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)
|
- 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)
|
- 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:
|
- Routing:
|
||||||
- FIXED: Fix adding traffic signal penalties during compression [#6419](https://github.com/Project-OSRM/osrm-backend/pull/6419)
|
- FIXED: Fix adding traffic signal penalties during compression [#6419](https://github.com/Project-OSRM/osrm-backend/pull/6419)
|
||||||
# 5.27.1
|
# 5.27.1
|
||||||
|
@ -57,8 +57,8 @@ class BaseAPI
|
|||||||
{
|
{
|
||||||
// TODO: check forward/reverse
|
// TODO: check forward/reverse
|
||||||
const auto toName = [this](const auto &phantom) {
|
const auto toName = [this](const auto &phantom) {
|
||||||
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
|
return std::string(
|
||||||
.to_string();
|
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)));
|
||||||
};
|
};
|
||||||
const auto noEmpty = [](const auto &name) { return !name.empty(); };
|
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))));
|
static_cast<float>(static_cast<double>(util::toFloating(snapped_location.lat))));
|
||||||
|
|
||||||
const auto toName = [this](const auto &phantom) {
|
const auto toName = [this](const auto &phantom) {
|
||||||
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
|
return std::string(
|
||||||
.to_string();
|
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)));
|
||||||
};
|
};
|
||||||
const auto noEmpty = [](const auto &name) { return !name.empty(); };
|
const auto noEmpty = [](const auto &name) { return !name.empty(); };
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
|||||||
extractor::Datasources *m_datasources;
|
extractor::Datasources *m_datasources;
|
||||||
|
|
||||||
std::uint32_t m_check_sum;
|
std::uint32_t m_check_sum;
|
||||||
StringView m_data_timestamp;
|
std::string_view m_data_timestamp;
|
||||||
util::vector_view<util::Coordinate> m_coordinate_list;
|
util::vector_view<util::Coordinate> m_coordinate_list;
|
||||||
extractor::PackedOSMIDsView m_osmnodeid_list;
|
extractor::PackedOSMIDsView m_osmnodeid_list;
|
||||||
util::vector_view<std::uint32_t> m_lane_description_offsets;
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
return m_datasources->GetSourceName(id);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include "util/integer_range.hpp"
|
#include "util/integer_range.hpp"
|
||||||
#include "util/packed_vector.hpp"
|
#include "util/packed_vector.hpp"
|
||||||
#include "util/string_util.hpp"
|
#include "util/string_util.hpp"
|
||||||
#include "util/string_view.hpp"
|
|
||||||
#include "util/typedefs.hpp"
|
#include "util/typedefs.hpp"
|
||||||
|
|
||||||
#include "osrm/coordinate.hpp"
|
#include "osrm/coordinate.hpp"
|
||||||
@ -37,6 +36,7 @@
|
|||||||
|
|
||||||
#include <engine/bearing.hpp>
|
#include <engine/bearing.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -47,8 +47,6 @@ namespace engine
|
|||||||
namespace datafacade
|
namespace datafacade
|
||||||
{
|
{
|
||||||
|
|
||||||
using StringView = util::StringView;
|
|
||||||
|
|
||||||
class BaseDataFacade
|
class BaseDataFacade
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -113,7 +111,7 @@ class BaseDataFacade
|
|||||||
GetUncompressedReverseDatasources(const PackedGeometryID id) const = 0;
|
GetUncompressedReverseDatasources(const PackedGeometryID id) const = 0;
|
||||||
|
|
||||||
// Gets the name of a datasource
|
// 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
|
virtual osrm::guidance::TurnInstruction
|
||||||
GetTurnInstructionForEdgeID(const EdgeID edge_based_edge_id) const = 0;
|
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 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;
|
virtual bool GetContinueStraightDefault() const = 0;
|
||||||
|
|
||||||
|
@ -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_id_to_string = [&](const NameID name_id) {
|
||||||
const auto name = facade.GetNameForID(name_id);
|
const auto name = facade.GetNameForID(name_id);
|
||||||
if (!name.empty())
|
if (!name.empty())
|
||||||
return name.to_string();
|
return std::string(name);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto ref = facade.GetRefForID(name_id);
|
const auto ref = facade.GetRefForID(name_id);
|
||||||
return ref.to_string();
|
return std::string(ref);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -140,11 +140,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
|
|||||||
steps.push_back(RouteStep{path_point.from_edge_based_node,
|
steps.push_back(RouteStep{path_point.from_edge_based_node,
|
||||||
step_name_id,
|
step_name_id,
|
||||||
is_segregated,
|
is_segregated,
|
||||||
name.to_string(),
|
std::string(name),
|
||||||
ref.to_string(),
|
std::string(ref),
|
||||||
pronunciation.to_string(),
|
std::string(pronunciation),
|
||||||
destinations.to_string(),
|
std::string(destinations),
|
||||||
exits.to_string(),
|
std::string(exits),
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
from_alias<double>(segment_duration) / 10.,
|
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,
|
steps.push_back(RouteStep{leg_data[leg_data.size() - 1].from_edge_based_node,
|
||||||
step_name_id,
|
step_name_id,
|
||||||
is_segregated,
|
is_segregated,
|
||||||
facade.GetNameForID(step_name_id).to_string(),
|
std::string(facade.GetNameForID(step_name_id)),
|
||||||
facade.GetRefForID(step_name_id).to_string(),
|
std::string(facade.GetRefForID(step_name_id)),
|
||||||
facade.GetPronunciationForID(step_name_id).to_string(),
|
std::string(facade.GetPronunciationForID(step_name_id)),
|
||||||
facade.GetDestinationsForID(step_name_id).to_string(),
|
std::string(facade.GetDestinationsForID(step_name_id)),
|
||||||
facade.GetExitsForID(step_name_id).to_string(),
|
std::string(facade.GetExitsForID(step_name_id)),
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
from_alias<double>(duration) / 10.,
|
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,
|
steps.push_back(RouteStep{source_node_id,
|
||||||
source_name_id,
|
source_name_id,
|
||||||
is_segregated,
|
is_segregated,
|
||||||
facade.GetNameForID(source_name_id).to_string(),
|
std::string(facade.GetNameForID(source_name_id)),
|
||||||
facade.GetRefForID(source_name_id).to_string(),
|
std::string(facade.GetRefForID(source_name_id)),
|
||||||
facade.GetPronunciationForID(source_name_id).to_string(),
|
std::string(facade.GetPronunciationForID(source_name_id)),
|
||||||
facade.GetDestinationsForID(source_name_id).to_string(),
|
std::string(facade.GetDestinationsForID(source_name_id)),
|
||||||
facade.GetExitsForID(source_name_id).to_string(),
|
std::string(facade.GetExitsForID(source_name_id)),
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
from_alias<double>(duration) / 10.,
|
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,
|
steps.push_back(RouteStep{target_node_id,
|
||||||
target_name_id,
|
target_name_id,
|
||||||
facade.IsSegregated(target_node_id),
|
facade.IsSegregated(target_node_id),
|
||||||
facade.GetNameForID(target_name_id).to_string(),
|
std::string(facade.GetNameForID(target_name_id)),
|
||||||
facade.GetRefForID(target_name_id).to_string(),
|
std::string(facade.GetRefForID(target_name_id)),
|
||||||
facade.GetPronunciationForID(target_name_id).to_string(),
|
std::string(facade.GetPronunciationForID(target_name_id)),
|
||||||
facade.GetDestinationsForID(target_name_id).to_string(),
|
std::string(facade.GetDestinationsForID(target_name_id)),
|
||||||
facade.GetExitsForID(target_name_id).to_string(),
|
std::string(facade.GetExitsForID(target_name_id)),
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
NO_ROTARY_NAME,
|
NO_ROTARY_NAME,
|
||||||
ZERO_DURATION,
|
ZERO_DURATION,
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#ifndef OSRM_EXTRACT_DATASOURCES_HPP
|
#ifndef OSRM_EXTRACT_DATASOURCES_HPP
|
||||||
#define OSRM_EXTRACT_DATASOURCES_HPP
|
#define OSRM_EXTRACT_DATASOURCES_HPP
|
||||||
|
|
||||||
|
#include "util/typedefs.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <util/string_view.hpp>
|
#include <string_view>
|
||||||
#include <util/typedefs.hpp>
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -22,11 +25,11 @@ class Datasources
|
|||||||
std::fill(sources.begin(), sources.end(), '\0');
|
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);
|
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)
|
void SetSourceName(DatasourceID id, const std::string &name)
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#define OSRM_EXTRACTOR_NAME_TABLE_HPP
|
#define OSRM_EXTRACTOR_NAME_TABLE_HPP
|
||||||
|
|
||||||
#include "util/indexed_data.hpp"
|
#include "util/indexed_data.hpp"
|
||||||
#include "util/string_view.hpp"
|
|
||||||
#include "util/typedefs.hpp"
|
#include "util/typedefs.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ template <storage::Ownership Ownership> class NameTableImpl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using IndexedData =
|
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 ResultType = typename IndexedData::ResultType;
|
||||||
using ValueType = typename IndexedData::ValueType;
|
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_)} {}
|
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)
|
if (id == INVALID_NAMEID)
|
||||||
return {};
|
return {};
|
||||||
@ -66,7 +66,7 @@ template <storage::Ownership Ownership> class NameTableImpl
|
|||||||
return indexed_data.at(id + 0);
|
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)
|
if (id == INVALID_NAMEID)
|
||||||
return {};
|
return {};
|
||||||
@ -74,7 +74,7 @@ template <storage::Ownership Ownership> class NameTableImpl
|
|||||||
return indexed_data.at(id + 1);
|
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)
|
if (id == INVALID_NAMEID)
|
||||||
return {};
|
return {};
|
||||||
@ -82,7 +82,7 @@ template <storage::Ownership Ownership> class NameTableImpl
|
|||||||
return indexed_data.at(id + 4);
|
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)
|
if (id == INVALID_NAMEID)
|
||||||
return {};
|
return {};
|
||||||
@ -91,7 +91,7 @@ template <storage::Ownership Ownership> class NameTableImpl
|
|||||||
return indexed_data.at(id + OFFSET_REF);
|
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)
|
if (id == INVALID_NAMEID)
|
||||||
return {};
|
return {};
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
#define OSRM_EXTRACTOR_SUFFIX_LIST_HPP_
|
#define OSRM_EXTRACTOR_SUFFIX_LIST_HPP_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
#include "util/string_view.hpp"
|
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
{
|
{
|
||||||
@ -23,7 +23,7 @@ class SuffixTable final
|
|||||||
|
|
||||||
// check whether a string is part of the know suffix list
|
// check whether a string is part of the know suffix list
|
||||||
bool isSuffix(const std::string &possible_suffix) const;
|
bool isSuffix(const std::string &possible_suffix) const;
|
||||||
bool isSuffix(util::StringView possible_suffix) const;
|
bool isSuffix(std::string_view possible_suffix) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Store lower-cased strings in SuffixTable and a set of StringViews for quick membership
|
// 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,
|
// require us to first convert StringViews into strings (allocation), do the membership,
|
||||||
// and destroy the StringView again.
|
// and destroy the StringView again.
|
||||||
std::vector<std::string> suffixes;
|
std::vector<std::string> suffixes;
|
||||||
std::unordered_set<util::StringView> suffix_set;
|
std::unordered_set<std::string_view> suffix_set;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace extractor */
|
} /* namespace extractor */
|
||||||
|
@ -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)
|
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)
|
inline auto make_cell_storage_view(const SharedDataIndex &index, const std::string &name)
|
||||||
|
@ -27,8 +27,8 @@ namespace guidance
|
|||||||
// Name Change Logic
|
// Name Change Logic
|
||||||
// Used both during Extraction as well as during Post-Processing
|
// Used both during Extraction as well as during Post-Processing
|
||||||
|
|
||||||
inline util::StringView longest_common_substring(const util::StringView &lhs,
|
inline std::string_view longest_common_substring(const std::string_view lhs,
|
||||||
const util::StringView &rhs)
|
const std::string_view rhs)
|
||||||
{
|
{
|
||||||
if (lhs.empty() || rhs.empty())
|
if (lhs.empty() || rhs.empty())
|
||||||
return "";
|
return "";
|
||||||
@ -70,7 +70,11 @@ template <typename StringView> inline auto decompose(const StringView &lhs, cons
|
|||||||
const auto trim = [](StringView view) {
|
const auto trim = [](StringView view) {
|
||||||
// we compare suffixes based on this value, it might break UTF chars, but as long as we are
|
// 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
|
// 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(' ');
|
auto front = str.find_first_not_of(' ');
|
||||||
|
|
||||||
if (front == std::string::npos)
|
if (front == std::string::npos)
|
||||||
@ -129,18 +133,18 @@ inline bool requiresNameAnnounced(const StringView &from_name,
|
|||||||
const auto name_is_contained =
|
const auto name_is_contained =
|
||||||
boost::starts_with(from_name, to_name) || boost::starts_with(to_name, from_name);
|
boost::starts_with(from_name, to_name) || boost::starts_with(to_name, from_name);
|
||||||
|
|
||||||
const auto checkForPrefixOrSuffixChange =
|
const auto checkForPrefixOrSuffixChange = [](const std::string_view first,
|
||||||
[](const StringView &first, const StringView &second, const SuffixTable &suffix_table) {
|
const std::string_view second,
|
||||||
|
const SuffixTable &suffix_table) {
|
||||||
std::string first_prefix, first_suffix, second_prefix, second_suffix;
|
std::string first_prefix, first_suffix, second_prefix, second_suffix;
|
||||||
std::tie(first_prefix, first_suffix, second_prefix, second_suffix) =
|
std::tie(first_prefix, first_suffix, second_prefix, second_suffix) =
|
||||||
decompose(first, second);
|
decompose(first, second);
|
||||||
|
|
||||||
const auto checkTable = [&](const std::string &str) {
|
const auto checkTable = [&](const std::string &str) {
|
||||||
return str.empty() || suffix_table.isSuffix(str);
|
return str.empty() || suffix_table.isSuffix(str);
|
||||||
};
|
};
|
||||||
|
|
||||||
return checkTable(first_prefix) && checkTable(first_suffix) &&
|
return checkTable(first_prefix) && checkTable(first_suffix) && checkTable(second_prefix) &&
|
||||||
checkTable(second_prefix) && checkTable(second_suffix);
|
checkTable(second_suffix);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto is_suffix_change = checkForPrefixOrSuffixChange(from_name, to_name, suffix_table);
|
const auto is_suffix_change = checkForPrefixOrSuffixChange(from_name, to_name, suffix_table);
|
||||||
@ -201,17 +205,17 @@ inline bool requiresNameAnnounced(const std::string &from_name,
|
|||||||
struct NopSuffixTable final
|
struct NopSuffixTable final
|
||||||
{
|
{
|
||||||
NopSuffixTable() {}
|
NopSuffixTable() {}
|
||||||
bool isSuffix(const StringView &) const { return false; }
|
bool isSuffix(const std::string_view) const { return false; }
|
||||||
} static const table;
|
} static const table;
|
||||||
|
|
||||||
return requiresNameAnnounced(util::StringView(from_name),
|
return requiresNameAnnounced(std::string_view(from_name),
|
||||||
util::StringView(from_ref),
|
std::string_view(from_ref),
|
||||||
util::StringView(from_pronunciation),
|
std::string_view(from_pronunciation),
|
||||||
util::StringView(from_exits),
|
std::string_view(from_exits),
|
||||||
util::StringView(to_name),
|
std::string_view(to_name),
|
||||||
util::StringView(to_ref),
|
std::string_view(to_ref),
|
||||||
util::StringView(to_pronunciation),
|
std::string_view(to_pronunciation),
|
||||||
util::StringView(to_exits),
|
std::string_view(to_exits),
|
||||||
table);
|
table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "storage/tar_fwd.hpp"
|
#include "storage/tar_fwd.hpp"
|
||||||
|
|
||||||
#include "util/exception.hpp"
|
#include "util/exception.hpp"
|
||||||
#include "util/string_view.hpp"
|
|
||||||
#include "util/vector_view.hpp"
|
#include "util/vector_view.hpp"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
@ -14,6 +13,7 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
@ -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>;
|
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>>
|
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
|
adapt(const Iter first, const Iter last) const
|
||||||
{
|
{
|
||||||
return ResultType(first, last);
|
return ResultType(first, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T = ResultType, typename Iter, typename = IsValueIterator<Iter, ValueType>>
|
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
|
adapt(const Iter first, const Iter last) const
|
||||||
{
|
{
|
||||||
auto diff = std::distance(first, last);
|
auto diff = std::distance(first, last);
|
||||||
|
@ -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 */
|
|
@ -4,7 +4,6 @@
|
|||||||
#include "engine/plugins/tile.hpp"
|
#include "engine/plugins/tile.hpp"
|
||||||
|
|
||||||
#include "util/coordinate_calculation.hpp"
|
#include "util/coordinate_calculation.hpp"
|
||||||
#include "util/string_view.hpp"
|
|
||||||
#include "util/vector_tile.hpp"
|
#include "util/vector_tile.hpp"
|
||||||
#include "util/web_mercator.hpp"
|
#include "util/web_mercator.hpp"
|
||||||
|
|
||||||
@ -20,6 +19,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ class SpeedLayerFeatureBuilder : public vtzero::linestring_feature_builder
|
|||||||
add_property(m_layer.key_duration, m_layer.double_index(value));
|
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(
|
add_property(
|
||||||
m_layer.key_name,
|
m_layer.key_name,
|
||||||
@ -518,7 +518,7 @@ void encodeVectorTile(const DataFacadeBase &facade,
|
|||||||
fbuilder.set_speed(speed_kmh_idx);
|
fbuilder.set_speed(speed_kmh_idx);
|
||||||
fbuilder.set_is_small(component_id.is_tiny);
|
fbuilder.set_is_small(component_id.is_tiny);
|
||||||
fbuilder.set_datasource(
|
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_weight(from_alias<double>(forward_weight) / 10.0);
|
||||||
fbuilder.set_duration(from_alias<double>(forward_duration) / 10.0);
|
fbuilder.set_duration(from_alias<double>(forward_duration) / 10.0);
|
||||||
fbuilder.set_name(name);
|
fbuilder.set_name(name);
|
||||||
@ -552,7 +552,7 @@ void encodeVectorTile(const DataFacadeBase &facade,
|
|||||||
fbuilder.set_speed(speed_kmh_idx);
|
fbuilder.set_speed(speed_kmh_idx);
|
||||||
fbuilder.set_is_small(component_id.is_tiny);
|
fbuilder.set_is_small(component_id.is_tiny);
|
||||||
fbuilder.set_datasource(
|
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_weight(from_alias<double>(reverse_weight) / 10.0);
|
||||||
fbuilder.set_duration(from_alias<double>(reverse_duration) / 10.0);
|
fbuilder.set_duration(from_alias<double>(reverse_duration) / 10.0);
|
||||||
fbuilder.set_name(name);
|
fbuilder.set_name(name);
|
||||||
|
@ -19,16 +19,16 @@ SuffixTable::SuffixTable(ScriptingEnvironment &scripting_environment)
|
|||||||
boost::algorithm::to_lower(suffix);
|
boost::algorithm::to_lower(suffix);
|
||||||
|
|
||||||
auto into = std::inserter(suffix_set, end(suffix_set));
|
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);
|
std::transform(begin(suffixes), end(suffixes), into, to_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SuffixTable::isSuffix(const std::string &possible_suffix) const
|
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;
|
return suffix_set.count(possible_suffix) > 0;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ struct EdgeInfo
|
|||||||
|
|
||||||
NodeID node;
|
NodeID node;
|
||||||
|
|
||||||
util::StringView name;
|
std::string_view name;
|
||||||
|
|
||||||
bool reversed;
|
bool reversed;
|
||||||
|
|
||||||
|
@ -203,7 +203,10 @@ class ContiguousInternalMemoryDataFacade<routing_algorithms::offline::Algorithm>
|
|||||||
return DatasourceReverseRange(DatasourceForwardRange());
|
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
|
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; }
|
bool HasLaneData(const EdgeID /*id*/) const override { return false; }
|
||||||
NameID GetNameIndex(const NodeID /*nodeID*/) const override { return EMPTY_NAMEID; }
|
NameID GetNameIndex(const NodeID /*nodeID*/) const override { return EMPTY_NAMEID; }
|
||||||
StringView GetNameForID(const NameID /*id*/) const override { return StringView{}; }
|
std::string_view GetNameForID(const NameID /*id*/) const override { return std::string_view{}; }
|
||||||
StringView GetRefForID(const NameID /*id*/) const override { return StringView{}; }
|
std::string_view GetRefForID(const NameID /*id*/) const override { return std::string_view{}; }
|
||||||
StringView GetPronunciationForID(const NameID /*id*/) const override { return StringView{}; }
|
std::string_view GetPronunciationForID(const NameID /*id*/) const override
|
||||||
StringView GetDestinationsForID(const NameID /*id*/) const override { return StringView{}; }
|
{
|
||||||
StringView GetExitsForID(const NameID /*id*/) const override { return StringView{}; }
|
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; }
|
bool GetContinueStraightDefault() const override { return false; }
|
||||||
std::string GetTimestamp() const override { return ""; }
|
std::string GetTimestamp() const override { return ""; }
|
||||||
double GetMapMatchingMaxSpeed() const override { return 0; }
|
double GetMapMatchingMaxSpeed() const override { return 0; }
|
||||||
|
@ -26,8 +26,6 @@ namespace test
|
|||||||
|
|
||||||
class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
|
class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
|
||||||
{
|
{
|
||||||
using StringView = util::StringView;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool ExcludeNode(const NodeID) const override { return false; };
|
bool ExcludeNode(const NodeID) const override { return false; };
|
||||||
|
|
||||||
@ -95,7 +93,7 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
|
|||||||
return DatasourceReverseRange(DatasourceForwardRange());
|
return DatasourceReverseRange(DatasourceForwardRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView GetDatasourceName(const DatasourceID) const override final { return {}; }
|
std::string_view GetDatasourceName(const DatasourceID) const override final { return {}; }
|
||||||
|
|
||||||
osrm::guidance::TurnInstruction
|
osrm::guidance::TurnInstruction
|
||||||
GetTurnInstructionForEdgeID(const EdgeID /* id */) const override
|
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; }
|
NameID GetNameIndex(const NodeID /* id */) const override { return 0; }
|
||||||
|
|
||||||
StringView GetNameForID(const NameID) const override final { return {}; }
|
std::string_view GetNameForID(const NameID) const override final { return {}; }
|
||||||
StringView GetRefForID(const NameID) const override final { return {}; }
|
std::string_view GetRefForID(const NameID) const override final { return {}; }
|
||||||
StringView GetPronunciationForID(const NameID) const override final { return {}; }
|
std::string_view GetPronunciationForID(const NameID) const override final { return {}; }
|
||||||
StringView GetDestinationsForID(const NameID) const override final { return {}; }
|
std::string_view GetDestinationsForID(const NameID) const override final { return {}; }
|
||||||
StringView GetExitsForID(const NameID) const override final { return {}; }
|
std::string_view GetExitsForID(const NameID) const override final { return {}; }
|
||||||
|
|
||||||
bool GetContinueStraightDefault() const override { return true; }
|
bool GetContinueStraightDefault() const override { return true; }
|
||||||
double GetMapMatchingMaxSpeed() const override { return 180 / 3.6; }
|
double GetMapMatchingMaxSpeed() const override { return 180 / 3.6; }
|
||||||
|
@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(check_string_view)
|
|||||||
std::string name_data = "hellostringview";
|
std::string name_data = "hellostringview";
|
||||||
std::vector<std::uint32_t> name_offsets = {0, 5, 11, 15};
|
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());
|
name_offsets.begin(), name_offsets.end(), name_data.begin());
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(indexed_data.at(0), "hello");
|
BOOST_CHECK_EQUAL(indexed_data.at(0), "hello");
|
||||||
|
Loading…
Reference in New Issue
Block a user