2017-04-02 13:15:20 -04:00
|
|
|
#ifndef OSMR_UTIL_SERIALIZATION_HPP
|
|
|
|
#define OSMR_UTIL_SERIALIZATION_HPP
|
|
|
|
|
2017-04-04 19:01:00 -04:00
|
|
|
#include "util/dynamic_graph.hpp"
|
2017-04-02 19:58:06 -04:00
|
|
|
#include "util/packed_vector.hpp"
|
2017-04-02 13:15:20 -04:00
|
|
|
#include "util/static_graph.hpp"
|
2017-04-04 18:00:17 -04:00
|
|
|
|
2017-04-02 13:15:20 -04:00
|
|
|
#include "storage/io.hpp"
|
2017-04-04 18:00:17 -04:00
|
|
|
#include "storage/serialization.hpp"
|
2017-04-02 13:15:20 -04:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
2017-04-02 19:02:57 -04:00
|
|
|
namespace serialization
|
|
|
|
{
|
2017-04-02 19:58:06 -04:00
|
|
|
template <typename T, storage::Ownership Ownership>
|
2017-04-04 19:01:00 -04:00
|
|
|
inline void read(storage::io::FileReader &reader, detail::PackedVector<T, Ownership> &vec)
|
2017-04-02 19:58:06 -04:00
|
|
|
{
|
2017-04-04 19:01:00 -04:00
|
|
|
vec.num_elements = reader.ReadOne<std::uint64_t>();
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::serialization::read(reader, vec.vec);
|
2017-04-02 19:58:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, storage::Ownership Ownership>
|
2017-04-04 19:01:00 -04:00
|
|
|
inline void write(storage::io::FileWriter &writer, const detail::PackedVector<T, Ownership> &vec)
|
2017-04-02 19:58:06 -04:00
|
|
|
{
|
|
|
|
writer.WriteOne(vec.num_elements);
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::serialization::write(writer, vec.vec);
|
2017-04-02 19:58:06 -04:00
|
|
|
}
|
2017-04-02 13:15:20 -04:00
|
|
|
|
|
|
|
template <typename EdgeDataT, storage::Ownership Ownership>
|
2017-04-04 19:01:00 -04:00
|
|
|
inline void read(storage::io::FileReader &reader, StaticGraph<EdgeDataT, Ownership> &graph)
|
2017-04-02 13:15:20 -04:00
|
|
|
{
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::serialization::read(reader, graph.node_array);
|
|
|
|
storage::serialization::read(reader, graph.edge_array);
|
2017-04-02 13:15:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename EdgeDataT, storage::Ownership Ownership>
|
2017-04-04 19:01:00 -04:00
|
|
|
inline void write(storage::io::FileWriter &writer, const StaticGraph<EdgeDataT, Ownership> &graph)
|
2017-04-02 13:15:20 -04:00
|
|
|
{
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::serialization::write(writer, graph.node_array);
|
|
|
|
storage::serialization::write(writer, graph.edge_array);
|
2017-04-02 13:15:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename EdgeDataT>
|
2017-04-04 19:01:00 -04:00
|
|
|
inline void read(storage::io::FileReader &reader, DynamicGraph<EdgeDataT> &graph)
|
2017-04-02 13:15:20 -04:00
|
|
|
{
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::serialization::read(reader, graph.node_array);
|
2017-04-02 13:15:20 -04:00
|
|
|
auto num_edges = reader.ReadElementCount64();
|
|
|
|
graph.edge_list.resize(num_edges);
|
|
|
|
for (auto index : irange<std::size_t>(0, num_edges))
|
|
|
|
{
|
|
|
|
reader.ReadOne(graph.edge_list[index]);
|
|
|
|
}
|
|
|
|
graph.number_of_nodes = graph.node_array.size();
|
|
|
|
graph.number_of_edges = num_edges;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename EdgeDataT>
|
2017-04-04 19:01:00 -04:00
|
|
|
inline void write(storage::io::FileWriter &writer, const DynamicGraph<EdgeDataT> &graph)
|
2017-04-02 13:15:20 -04:00
|
|
|
{
|
2017-04-04 18:00:17 -04:00
|
|
|
storage::serialization::write(writer, graph.node_array);
|
2017-04-02 13:15:20 -04:00
|
|
|
writer.WriteElementCount64(graph.number_of_edges);
|
|
|
|
for (auto index : irange<std::size_t>(0, graph.number_of_edges))
|
|
|
|
{
|
|
|
|
writer.WriteOne(graph.edge_list[index]);
|
|
|
|
}
|
|
|
|
}
|
2017-04-02 19:02:57 -04:00
|
|
|
}
|
2017-04-02 13:15:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|