osrm-backend/include/contractor/files.hpp

60 lines
1.9 KiB
C++
Raw Normal View History

#ifndef OSRM_CONTRACTOR_FILES_HPP
#define OSRM_CONTRACTOR_FILES_HPP
2018-03-27 05:44:13 -04:00
#include "contractor/serialization.hpp"
2018-03-27 05:44:13 -04:00
#include <unordered_map>
namespace osrm
{
namespace contractor
{
namespace files
{
// reads .osrm.hsgr file
2018-03-27 05:44:13 -04:00
template <typename ContractedMetricT>
inline void readGraph(const boost::filesystem::path &path,
2018-03-27 05:44:13 -04:00
std::unordered_map<std::string, ContractedMetricT> &metrics,
std::uint32_t &connectivity_checksum)
{
2018-03-27 05:44:13 -04:00
static_assert(std::is_same<ContractedMetric, ContractedMetricT>::value ||
std::is_same<ContractedMetricView, ContractedMetricT>::value,
"metric must be of type ContractedMetric<>");
2018-03-15 16:10:21 -04:00
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
storage::tar::FileReader reader{path, fingerprint};
2018-03-27 05:44:13 -04:00
reader.ReadInto("/ch/connectivity_checksum", connectivity_checksum);
2018-03-15 16:10:21 -04:00
2018-03-27 05:44:13 -04:00
for (auto &pair : metrics)
{
2018-03-27 05:44:13 -04:00
serialization::read(reader, "/ch/metrics/" + pair.first, pair.second);
}
}
// writes .osrm.hsgr file
2018-03-27 05:44:13 -04:00
template <typename ContractedMetricT>
inline void writeGraph(const boost::filesystem::path &path,
2018-03-27 05:44:13 -04:00
const std::unordered_map<std::string, ContractedMetricT> &metrics,
const std::uint32_t connectivity_checksum)
{
2018-03-27 05:44:13 -04:00
static_assert(std::is_same<ContractedMetric, ContractedMetricT>::value ||
std::is_same<ContractedMetricView, ContractedMetricT>::value,
"metric must be of type ContractedMetric<>");
2018-03-15 16:10:21 -04:00
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
storage::tar::FileWriter writer{path, fingerprint};
2018-03-27 05:44:13 -04:00
writer.WriteElementCount64("/ch/connectivity_checksum", 1);
writer.WriteFrom("/ch/connectivity_checksum", connectivity_checksum);
2018-03-15 16:10:21 -04:00
2018-03-27 05:44:13 -04:00
for (const auto &pair : metrics)
{
2018-03-27 05:44:13 -04:00
serialization::write(writer, "/ch/metrics/" + pair.first, pair.second);
}
}
}
}
}
#endif