osrm-backend/include/partitioner/files.hpp

98 lines
3.5 KiB
C++
Raw Normal View History

#ifndef OSRM_PARTITIONER_SERILIZATION_HPP
#define OSRM_PARTITIONER_SERILIZATION_HPP
2017-04-01 17:56:47 -04:00
#include "partitioner/serialization.hpp"
2017-04-01 17:56:47 -04:00
#include "storage/io.hpp"
namespace osrm::partitioner::files
2017-04-01 17:56:47 -04:00
{
// read .osrm.partition file
template <typename MultiLevelPartitionT>
inline void readPartition(const std::filesystem::path &path, MultiLevelPartitionT &mlp)
2017-04-01 17:56:47 -04:00
{
static_assert(std::is_same<MultiLevelPartitionView, MultiLevelPartitionT>::value ||
std::is_same<MultiLevelPartition, MultiLevelPartitionT>::value,
"");
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
storage::tar::FileReader reader{path, fingerprint};
2017-04-01 17:56:47 -04:00
serialization::read(reader, "/mld/multilevelpartition", mlp);
2017-04-01 17:56:47 -04:00
}
// writes .osrm.partition file
template <typename MultiLevelPartitionT>
inline void writePartition(const std::filesystem::path &path, const MultiLevelPartitionT &mlp)
2017-04-01 17:56:47 -04:00
{
static_assert(std::is_same<MultiLevelPartitionView, MultiLevelPartitionT>::value ||
std::is_same<MultiLevelPartition, MultiLevelPartitionT>::value,
"");
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
storage::tar::FileWriter writer{path, fingerprint};
2017-04-01 17:56:47 -04:00
serialization::write(writer, "/mld/multilevelpartition", mlp);
2017-04-01 17:56:47 -04:00
}
// reads .osrm.cells file
template <typename CellStorageT>
inline void readCells(const std::filesystem::path &path, CellStorageT &storage)
2017-04-01 17:56:47 -04:00
{
static_assert(std::is_same<CellStorageView, CellStorageT>::value ||
std::is_same<CellStorage, CellStorageT>::value,
"");
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
storage::tar::FileReader reader{path, fingerprint};
2017-04-01 17:56:47 -04:00
serialization::read(reader, "/mld/cellstorage", storage);
2017-04-01 17:56:47 -04:00
}
// writes .osrm.cells file
template <typename CellStorageT>
inline void writeCells(const std::filesystem::path &path, CellStorageT &storage)
2017-04-01 17:56:47 -04:00
{
static_assert(std::is_same<CellStorageView, CellStorageT>::value ||
std::is_same<CellStorage, CellStorageT>::value,
"");
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
storage::tar::FileWriter writer{path, fingerprint};
2017-04-01 17:56:47 -04:00
serialization::write(writer, "/mld/cellstorage", storage);
2017-04-01 17:56:47 -04:00
}
2018-04-21 02:41:40 -04:00
// reads .osrm.mldgr file
template <typename MultiLevelGraphT>
inline void readGraph(const std::filesystem::path &path,
2018-04-21 02:41:40 -04:00
MultiLevelGraphT &graph,
std::uint32_t &connectivity_checksum)
{
static_assert(std::is_same<partitioner::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value, "");
storage::tar::FileReader reader{path, storage::tar::FileReader::VerifyFingerprint};
reader.ReadInto("/mld/connectivity_checksum", connectivity_checksum);
serialization::read(reader, "/mld/multilevelgraph", graph);
}
// writes .osrm.mldgr file
template <typename MultiLevelGraphT>
inline void writeGraph(const std::filesystem::path &path,
2018-04-21 02:41:40 -04:00
const MultiLevelGraphT &graph,
const std::uint32_t connectivity_checksum)
{
static_assert(std::is_same<partitioner::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value, "");
storage::tar::FileWriter writer{path, storage::tar::FileWriter::GenerateFingerprint};
writer.WriteElementCount64("/mld/connectivity_checksum", 1);
writer.WriteFrom("/mld/connectivity_checksum", connectivity_checksum);
serialization::write(writer, "/mld/multilevelgraph", graph);
}
2022-12-20 12:00:11 -05:00
} // namespace osrm::partitioner::files
2017-04-01 17:56:47 -04:00
#endif