#ifndef OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_ #define OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_ #include "util/shared_memory_vector_wrapper.hpp" #include "util/typedefs.hpp" #include "storage/shared_memory_ownership.hpp" #include #include #include #include #include #include namespace osrm { namespace storage { namespace io { class FileReader; class FileWriter; } } namespace extractor { class CompressedEdgeContainer; namespace detail { template class SegmentDataContainerImpl; } namespace serialization { template inline void read(storage::io::FileReader &reader, detail::SegmentDataContainerImpl &segment_data); template inline void write(storage::io::FileWriter &writer, const detail::SegmentDataContainerImpl &segment_data); } namespace detail { template class SegmentDataContainerImpl { template using Vector = typename util::ShM::vector; friend CompressedEdgeContainer; public: // FIXME We should change the indexing to Edge-Based-Node id using DirectionalGeometryID = std::uint32_t; using SegmentOffset = std::uint32_t; SegmentDataContainerImpl() = default; SegmentDataContainerImpl(Vector index_, Vector nodes_, Vector fwd_weights_, Vector rev_weights_, Vector fwd_durations_, Vector rev_durations_, Vector datasources_) : index(std::move(index_)), nodes(std::move(nodes_)), fwd_weights(std::move(fwd_weights_)), rev_weights(std::move(rev_weights_)), fwd_durations(std::move(fwd_durations_)), rev_durations(std::move(rev_durations_)), datasources(std::move(datasources_)) { } auto GetForwardGeometry(const DirectionalGeometryID id) { const auto begin = nodes.begin() + index[id]; const auto end = nodes.begin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseGeometry(const DirectionalGeometryID id) { return boost::adaptors::reverse(GetForwardGeometry(id)); } auto GetForwardDurations(const DirectionalGeometryID id) { const auto begin = fwd_durations.begin() + index[id] + 1; const auto end = fwd_durations.begin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseDurations(const DirectionalGeometryID id) { const auto begin = rev_durations.begin() + index[id]; const auto end = rev_durations.begin() + index[id + 1] - 1; return boost::adaptors::reverse(boost::make_iterator_range(begin, end)); } auto GetForwardWeights(const DirectionalGeometryID id) { const auto begin = fwd_weights.begin() + index[id] + 1; const auto end = fwd_weights.begin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseWeights(const DirectionalGeometryID id) { const auto begin = rev_weights.begin() + index[id]; const auto end = rev_weights.begin() + index[id + 1] - 1; return boost::adaptors::reverse(boost::make_iterator_range(begin, end)); } auto GetForwardDatasources(const DirectionalGeometryID id) { const auto begin = datasources.begin() + index[id] + 1; const auto end = datasources.begin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseDatasources(const DirectionalGeometryID id) { const auto begin = datasources.begin() + index[id]; const auto end = datasources.begin() + index[id + 1] - 1; return boost::adaptors::reverse(boost::make_iterator_range(begin, end)); } auto GetForwardGeometry(const DirectionalGeometryID id) const { const auto begin = nodes.cbegin() + index[id]; const auto end = nodes.cbegin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseGeometry(const DirectionalGeometryID id) const { return boost::adaptors::reverse(GetForwardGeometry(id)); } auto GetForwardDurations(const DirectionalGeometryID id) const { const auto begin = fwd_durations.cbegin() + index[id] + 1; const auto end = fwd_durations.cbegin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseDurations(const DirectionalGeometryID id) const { const auto begin = rev_durations.cbegin() + index[id]; const auto end = rev_durations.cbegin() + index[id + 1] - 1; return boost::adaptors::reverse(boost::make_iterator_range(begin, end)); } auto GetForwardWeights(const DirectionalGeometryID id) const { const auto begin = fwd_weights.cbegin() + index[id] + 1; const auto end = fwd_weights.cbegin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseWeights(const DirectionalGeometryID id) const { const auto begin = rev_weights.cbegin() + index[id]; const auto end = rev_weights.cbegin() + index[id + 1] - 1; return boost::adaptors::reverse(boost::make_iterator_range(begin, end)); } auto GetForwardDatasources(const DirectionalGeometryID id) const { const auto begin = datasources.cbegin() + index[id] + 1; const auto end = datasources.cbegin() + index[id + 1]; return boost::make_iterator_range(begin, end); } auto GetReverseDatasources(const DirectionalGeometryID id) const { const auto begin = datasources.cbegin() + index[id]; const auto end = datasources.cbegin() + index[id + 1] - 1; return boost::adaptors::reverse(boost::make_iterator_range(begin, end)); } auto GetNumberOfGeometries() const { return index.size() - 1; } auto GetNumberOfSegments() const { return fwd_weights.size(); } friend void serialization::read(storage::io::FileReader &reader, detail::SegmentDataContainerImpl &segment_data); friend void serialization::write(storage::io::FileWriter &writer, const detail::SegmentDataContainerImpl &segment_data); private: Vector index; Vector nodes; Vector fwd_weights; Vector rev_weights; Vector fwd_durations; Vector rev_durations; Vector datasources; }; } using SegmentDataView = detail::SegmentDataContainerImpl; using SegmentDataContainer = detail::SegmentDataContainerImpl; } } #endif