osrm-backend/include/customizer/files.hpp

63 lines
1.6 KiB
C++
Raw Normal View History

#ifndef OSRM_CUSTOMIZER_FILES_HPP
#define OSRM_CUSTOMIZER_FILES_HPP
#include "customizer/serialization.hpp"
2018-03-15 12:34:16 -04:00
#include "storage/tar.hpp"
#include "util/integer_range.hpp"
namespace osrm
{
namespace customizer
{
namespace files
{
// reads .osrm.cell_metrics file
template <typename CellMetricT>
inline void readCellMetrics(const boost::filesystem::path &path, std::vector<CellMetricT> &metrics)
{
static_assert(std::is_same<CellMetricView, CellMetricT>::value ||
std::is_same<CellMetric, CellMetricT>::value,
"");
2018-03-15 12:34:16 -04:00
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
storage::tar::FileReader reader{path, fingerprint};
2018-03-15 12:34:16 -04:00
auto num_metrics = reader.ReadElementCount64("/mld/metrics");
metrics.resize(num_metrics);
2018-03-15 12:34:16 -04:00
auto id = 0;
2017-08-14 17:24:33 -04:00
for (auto &metric : metrics)
{
2018-03-15 12:34:16 -04:00
serialization::read(reader, "/mld/metrics/" + std::to_string(id++), metric);
}
}
// writes .osrm.cell_metrics file
template <typename CellMetricT>
2017-08-14 17:24:33 -04:00
inline void writeCellMetrics(const boost::filesystem::path &path,
const std::vector<CellMetricT> &metrics)
{
static_assert(std::is_same<CellMetricView, CellMetricT>::value ||
std::is_same<CellMetric, CellMetricT>::value,
"");
2018-03-15 12:34:16 -04:00
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
storage::tar::FileWriter writer{path, fingerprint};
2018-03-15 12:34:16 -04:00
writer.WriteElementCount64("/mld/metrics", metrics.size());
auto id = 0;
2017-08-14 17:24:33 -04:00
for (const auto &metric : metrics)
{
2018-03-15 12:34:16 -04:00
serialization::write(writer, "/mld/metrics/" + std::to_string(id++), metric);
}
}
}
}
}
#endif