From 5c9d0d152c1f26f2d328363345ba8538b1b84ee7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 30 Oct 2022 19:52:57 +0100 Subject: [PATCH] Remove usage of StringView typedef --- .../contiguous_internalmem_datafacade.hpp | 14 +++++------ include/engine/datafacade/datafacade_base.hpp | 14 +++++------ include/extractor/datasources.hpp | 4 ++-- include/extractor/name_table.hpp | 12 +++++----- include/extractor/suffix_table.hpp | 4 ++-- include/storage/view_factory.hpp | 2 +- include/util/guidance/name_announcements.hpp | 24 +++++++++---------- include/util/indexed_data.hpp | 4 ++-- include/util/string_view.hpp | 2 +- src/extractor/suffix_table.cpp | 6 ++--- ...segregated_intersection_classification.cpp | 2 +- unit_tests/engine/offline_facade.cpp | 12 +++++----- unit_tests/mocks/mock_datafacade.hpp | 14 +++++------ unit_tests/util/indexed_data.cpp | 2 +- 14 files changed, 56 insertions(+), 60 deletions(-) diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index 0548e0569..48d00e0c1 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -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 m_coordinate_list; extractor::PackedOSMIDsView m_osmnodeid_list; util::vector_view 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); } diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 936ccf0c2..7e9e69c88 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -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; diff --git a/include/extractor/datasources.hpp b/include/extractor/datasources.hpp index a4f872656..844ceae0f 100644 --- a/include/extractor/datasources.hpp +++ b/include/extractor/datasources.hpp @@ -22,11 +22,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) diff --git a/include/extractor/name_table.hpp b/include/extractor/name_table.hpp index ff0d27ae1..35e966ee1 100644 --- a/include/extractor/name_table.hpp +++ b/include/extractor/name_table.hpp @@ -50,7 +50,7 @@ template class NameTableImpl { public: using IndexedData = - util::detail::IndexedDataImpl, Ownership>; + util::detail::IndexedDataImpl, Ownership>; using ResultType = typename IndexedData::ResultType; using ValueType = typename IndexedData::ValueType; @@ -58,7 +58,7 @@ template 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 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 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 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 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 {}; diff --git a/include/extractor/suffix_table.hpp b/include/extractor/suffix_table.hpp index 5d16fe6b7..52dc4eec4 100644 --- a/include/extractor/suffix_table.hpp +++ b/include/extractor/suffix_table.hpp @@ -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 suffixes; - std::unordered_set suffix_set; + std::unordered_set suffix_set; }; } /* namespace extractor */ diff --git a/include/storage/view_factory.hpp b/include/storage/view_factory.hpp index bbc490ce3..80db376bf 100644 --- a/include/storage/view_factory.hpp +++ b/include/storage/view_factory.hpp @@ -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(name), index.GetBlockEntries(name)); + return std::string_view(index.GetBlockPtr(name), index.GetBlockEntries(name)); } inline auto make_cell_storage_view(const SharedDataIndex &index, const std::string &name) diff --git a/include/util/guidance/name_announcements.hpp b/include/util/guidance/name_announcements.hpp index fceff6b03..06639310d 100644 --- a/include/util/guidance/name_announcements.hpp +++ b/include/util/guidance/name_announcements.hpp @@ -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 ""; @@ -132,7 +132,7 @@ inline bool requiresNameAnnounced(const StringView &from_name, 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) { + [](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); @@ -203,17 +203,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); } diff --git a/include/util/indexed_data.hpp b/include/util/indexed_data.hpp index 5ce5bd4b3..d62105d42 100644 --- a/include/util/indexed_data.hpp +++ b/include/util/indexed_data.hpp @@ -365,14 +365,14 @@ template struct Indexe std::enable_if_t::value_type>::value>; template > - typename std::enable_if::value, T>::type + typename std::enable_if::value, T>::type adapt(const Iter first, const Iter last) const { return ResultType(first, last); } template > - typename std::enable_if::value, T>::type + typename std::enable_if::value, T>::type adapt(const Iter first, const Iter last) const { auto diff = std::distance(first, last); diff --git a/include/util/string_view.hpp b/include/util/string_view.hpp index 21f34ca5c..77cbdb200 100644 --- a/include/util/string_view.hpp +++ b/include/util/string_view.hpp @@ -9,7 +9,7 @@ namespace osrm namespace util { // Convenience typedef: boost::string_ref, boost::string_view or C++17's string_view -using StringView = std::string_view; +// using StringView = std::string_view; } // namespace util } // namespace osrm diff --git a/src/extractor/suffix_table.cpp b/src/extractor/suffix_table.cpp index 26f9afd91..a835562f9 100644 --- a/src/extractor/suffix_table.cpp +++ b/src/extractor/suffix_table.cpp @@ -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; } diff --git a/src/guidance/segregated_intersection_classification.cpp b/src/guidance/segregated_intersection_classification.cpp index b87d19a35..f9411a912 100644 --- a/src/guidance/segregated_intersection_classification.cpp +++ b/src/guidance/segregated_intersection_classification.cpp @@ -24,7 +24,7 @@ struct EdgeInfo NodeID node; - util::StringView name; + std::string_view name; bool reversed; diff --git a/unit_tests/engine/offline_facade.cpp b/unit_tests/engine/offline_facade.cpp index e4b0a2be7..df30dc9a4 100644 --- a/unit_tests/engine/offline_facade.cpp +++ b/unit_tests/engine/offline_facade.cpp @@ -203,7 +203,7 @@ class ContiguousInternalMemoryDataFacade 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 +270,11 @@ class ContiguousInternalMemoryDataFacade 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; } diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index bfaf41415..81471835b 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -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; } diff --git a/unit_tests/util/indexed_data.cpp b/unit_tests/util/indexed_data.cpp index 6d9eecbe9..40b79f9be 100644 --- a/unit_tests/util/indexed_data.cpp +++ b/unit_tests/util/indexed_data.cpp @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(check_string_view) std::string name_data = "hellostringview"; std::vector name_offsets = {0, 5, 11, 15}; - IndexedData> indexed_data( + IndexedData> indexed_data( name_offsets.begin(), name_offsets.end(), name_data.begin()); BOOST_CHECK_EQUAL(indexed_data.at(0), "hello");