From 446c865415da87699ec5b895d71bf6baf41f2152 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Wed, 5 Apr 2017 00:11:39 +0000 Subject: [PATCH] Dont leak ownership in extractor::files --- include/extractor/files.hpp | 78 ++++++++++++++++++++++------------ include/util/packed_vector.hpp | 2 + src/extractor/extractor.cpp | 3 +- src/storage/storage.cpp | 5 +-- 4 files changed, 55 insertions(+), 33 deletions(-) diff --git a/include/extractor/files.hpp b/include/extractor/files.hpp index be2b39020..5b1be3350 100644 --- a/include/extractor/files.hpp +++ b/include/extractor/files.hpp @@ -18,11 +18,14 @@ namespace files { // reads .osrm.nodes -template +template inline void readNodes(const boost::filesystem::path &path, - util::ViewOrVector &coordinates, - util::detail::PackedVector &osm_node_ids) + CoordinatesT &coordinates, + PackedOSMIDsT &osm_node_ids) { + static_assert(std::is_same::value, ""); + static_assert(std::is_same::value, ""); + const auto fingerprint = storage::io::FileReader::VerifyFingerprint; storage::io::FileReader reader{path, fingerprint}; @@ -31,11 +34,14 @@ inline void readNodes(const boost::filesystem::path &path, } // writes .osrm.nodes -template +template inline void writeNodes(const boost::filesystem::path &path, - const util::ViewOrVector &coordinates, - const util::detail::PackedVector &osm_node_ids) + const CoordinatesT &coordinates, + const PackedOSMIDsT &osm_node_ids) { + static_assert(std::is_same::value, ""); + static_assert(std::is_same::value, ""); + const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; storage::io::FileWriter writer{path, fingerprint}; @@ -81,10 +87,12 @@ inline void writeDatasources(const boost::filesystem::path &path, Datasources &s } // reads .osrm.geometry -template -inline void readSegmentData(const boost::filesystem::path &path, - detail::SegmentDataContainerImpl &segment_data) +template +inline void readSegmentData(const boost::filesystem::path &path, SegmentDataT &segment_data) { + static_assert(std::is_same::value || + std::is_same::value, + ""); const auto fingerprint = storage::io::FileReader::HasNoFingerprint; storage::io::FileReader reader{path, fingerprint}; @@ -92,10 +100,12 @@ inline void readSegmentData(const boost::filesystem::path &path, } // writes .osrm.geometry -template -inline void writeSegmentData(const boost::filesystem::path &path, - const detail::SegmentDataContainerImpl &segment_data) +template +inline void writeSegmentData(const boost::filesystem::path &path, const SegmentDataT &segment_data) { + static_assert(std::is_same::value || + std::is_same::value, + ""); const auto fingerprint = storage::io::FileWriter::HasNoFingerprint; storage::io::FileWriter writer{path, fingerprint}; @@ -103,10 +113,12 @@ inline void writeSegmentData(const boost::filesystem::path &path, } // reads .osrm.edges -template -inline void readTurnData(const boost::filesystem::path &path, - detail::TurnDataContainerImpl &turn_data) +template +inline void readTurnData(const boost::filesystem::path &path, TurnDataT &turn_data) { + static_assert(std::is_same::value || + std::is_same::value, + ""); const auto fingerprint = storage::io::FileReader::HasNoFingerprint; storage::io::FileReader reader{path, fingerprint}; @@ -114,10 +126,12 @@ inline void readTurnData(const boost::filesystem::path &path, } // writes .osrm.edges -template -inline void writeTurnData(const boost::filesystem::path &path, - const detail::TurnDataContainerImpl &turn_data) +template +inline void writeTurnData(const boost::filesystem::path &path, const TurnDataT &turn_data) { + static_assert(std::is_same::value || + std::is_same::value, + ""); const auto fingerprint = storage::io::FileWriter::HasNoFingerprint; storage::io::FileWriter writer{path, fingerprint}; @@ -125,12 +139,16 @@ inline void writeTurnData(const boost::filesystem::path &path, } // reads .osrm.tls -template -inline void readTurnLaneDescriptions( - const boost::filesystem::path &path, - util::ViewOrVector &turn_offsets, - util::ViewOrVector &turn_masks) +template +inline void readTurnLaneDescriptions(const boost::filesystem::path &path, + OffsetsT &turn_offsets, + MaskT &turn_masks) { + static_assert( + std::is_same::value, + ""); + static_assert(std::is_same::value, ""); + const auto fingerprint = storage::io::FileReader::HasNoFingerprint; storage::io::FileReader reader{path, fingerprint}; @@ -139,12 +157,16 @@ inline void readTurnLaneDescriptions( } // writes .osrm.tls -template -inline void writeTurnLaneDescriptions( - const boost::filesystem::path &path, - const util::ViewOrVector &turn_offsets, - const util::ViewOrVector &turn_masks) +template +inline void writeTurnLaneDescriptions(const boost::filesystem::path &path, + const OffsetsT &turn_offsets, + const MaskT &turn_masks) { + static_assert( + std::is_same::value, + ""); + static_assert(std::is_same::value, ""); + const auto fingerprint = storage::io::FileWriter::HasNoFingerprint; storage::io::FileWriter writer{path, fingerprint}; diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index bb8472cfc..4fa77bf48 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -45,6 +45,8 @@ template class PackedVector static const constexpr std::size_t PACKSIZE = BITSIZE * ELEMSIZE; public: + using value_type = T; + /** * Returns the size of the packed vector datastructure with `elements` packed elements (the size * of diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 4f3033c86..e1074413d 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -299,8 +299,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) TIMER_STOP(rtree); util::Log() << "Writing node map ..."; - files::writeNodes( - config.node_output_path, coordinates, osm_node_ids); + files::writeNodes(config.node_output_path, coordinates, osm_node_ids); WriteEdgeBasedGraph(config.edge_graph_output_path, max_edge_id, edge_based_edge_list); diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index e2482361b..1c9aae10f 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -566,7 +566,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) util::vector_view masks( masks_ptr, layout.num_entries[storage::DataLayout::LANE_DESCRIPTION_MASKS]); - extractor::files::readTurnLaneDescriptions( + extractor::files::readTurnLaneDescriptions( config.turn_lane_description_path, offsets, masks); } @@ -695,8 +695,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) util::PackedVectorView osm_node_ids; osm_node_ids.reset(osmnodeid_ptr, layout.num_entries[DataLayout::OSM_NODE_ID_LIST]); - extractor::files::readNodes( - config.nodes_data_path, coordinates, osm_node_ids); + extractor::files::readNodes(config.nodes_data_path, coordinates, osm_node_ids); } // load turn weight penalties