2017-04-02 19:02:57 -04:00
|
|
|
#ifndef OSRM_CONTRACTOR_FILES_HPP
|
|
|
|
#define OSRM_CONTRACTOR_FILES_HPP
|
|
|
|
|
2018-03-27 05:44:13 -04:00
|
|
|
#include "contractor/serialization.hpp"
|
2017-04-02 19:02:57 -04:00
|
|
|
|
2018-03-27 05:44:13 -04:00
|
|
|
#include <unordered_map>
|
2017-04-02 19:02:57 -04:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace contractor
|
|
|
|
{
|
|
|
|
namespace files
|
|
|
|
{
|
|
|
|
// reads .osrm.hsgr file
|
2018-03-27 05:44:13 -04:00
|
|
|
template <typename ContractedMetricT>
|
2017-08-20 19:24:05 -04:00
|
|
|
inline void readGraph(const boost::filesystem::path &path,
|
2018-03-27 05:44:13 -04:00
|
|
|
std::unordered_map<std::string, ContractedMetricT> &metrics,
|
2018-02-01 10:00:15 -05:00
|
|
|
std::uint32_t &connectivity_checksum)
|
2017-04-02 19:02:57 -04:00
|
|
|
{
|
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<>");
|
2017-04-03 10:21:13 -04:00
|
|
|
|
2018-03-15 16:10:21 -04:00
|
|
|
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
|
|
|
|
storage::tar::FileReader reader{path, fingerprint};
|
2017-04-02 19:02:57 -04:00
|
|
|
|
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)
|
2017-08-20 19:24:05 -04:00
|
|
|
{
|
2018-03-27 05:44:13 -04:00
|
|
|
serialization::read(reader, "/ch/metrics/" + pair.first, pair.second);
|
2017-08-20 19:24:05 -04:00
|
|
|
}
|
2017-04-02 19:02:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// writes .osrm.hsgr file
|
2018-03-27 05:44:13 -04:00
|
|
|
template <typename ContractedMetricT>
|
2017-08-20 19:24:05 -04:00
|
|
|
inline void writeGraph(const boost::filesystem::path &path,
|
2018-03-27 05:44:13 -04:00
|
|
|
const std::unordered_map<std::string, ContractedMetricT> &metrics,
|
2018-02-01 10:00:15 -05:00
|
|
|
const std::uint32_t connectivity_checksum)
|
2017-04-02 19:02:57 -04:00
|
|
|
{
|
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};
|
2017-04-02 19:02:57 -04:00
|
|
|
|
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)
|
2017-08-20 19:24:05 -04:00
|
|
|
{
|
2018-03-27 05:44:13 -04:00
|
|
|
serialization::write(writer, "/ch/metrics/" + pair.first, pair.second);
|
2017-08-20 19:24:05 -04:00
|
|
|
}
|
2017-04-02 19:02:57 -04:00
|
|
|
}
|
2020-11-26 10:21:39 -05:00
|
|
|
} // namespace files
|
|
|
|
} // namespace contractor
|
|
|
|
} // namespace osrm
|
2017-04-02 19:02:57 -04:00
|
|
|
|
|
|
|
#endif
|