2017-04-04 18:00:17 -04:00
|
|
|
#ifndef OSRM_EXTRACTOR_IO_HPP
|
|
|
|
#define OSRM_EXTRACTOR_IO_HPP
|
|
|
|
|
|
|
|
#include "extractor/datasources.hpp"
|
2017-06-19 09:27:46 -04:00
|
|
|
#include "extractor/intersection_bearings_container.hpp"
|
2017-04-04 18:00:17 -04:00
|
|
|
#include "extractor/nbg_to_ebg.hpp"
|
2017-04-25 05:36:34 -04:00
|
|
|
#include "extractor/node_data_container.hpp"
|
2017-06-19 09:27:46 -04:00
|
|
|
#include "extractor/profile_properties.hpp"
|
2017-05-11 06:13:52 -04:00
|
|
|
#include "extractor/restriction.hpp"
|
2017-04-04 18:00:17 -04:00
|
|
|
#include "extractor/segment_data_container.hpp"
|
|
|
|
#include "extractor/turn_data_container.hpp"
|
|
|
|
|
|
|
|
#include "storage/io.hpp"
|
|
|
|
#include "storage/serialization.hpp"
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
|
|
|
namespace serialization
|
|
|
|
{
|
|
|
|
|
2017-06-19 09:27:46 -04:00
|
|
|
// read/write for bearing data
|
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void read(storage::io::FileReader &reader,
|
|
|
|
detail::IntersectionBearingsContainer<Ownership> &intersection_bearings)
|
|
|
|
{
|
|
|
|
storage::serialization::read(reader, intersection_bearings.values);
|
|
|
|
storage::serialization::read(reader, intersection_bearings.node_to_class_id);
|
|
|
|
util::serialization::read(reader, intersection_bearings.class_id_to_ranges_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void write(storage::io::FileWriter &writer,
|
|
|
|
const detail::IntersectionBearingsContainer<Ownership> &intersection_bearings)
|
|
|
|
{
|
|
|
|
storage::serialization::write(writer, intersection_bearings.values);
|
|
|
|
storage::serialization::write(writer, intersection_bearings.node_to_class_id);
|
|
|
|
util::serialization::write(writer, intersection_bearings.class_id_to_ranges_table);
|
|
|
|
}
|
|
|
|
|
2017-06-16 05:30:37 -04:00
|
|
|
// read/write for properties file
|
|
|
|
inline void read(storage::io::FileReader &reader, ProfileProperties &properties)
|
|
|
|
{
|
|
|
|
reader.ReadInto(properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void write(storage::io::FileWriter &writer, const ProfileProperties &properties)
|
|
|
|
{
|
|
|
|
writer.WriteFrom(properties);
|
|
|
|
}
|
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
// read/write for datasources file
|
2017-04-04 18:00:17 -04:00
|
|
|
inline void read(storage::io::FileReader &reader, Datasources &sources)
|
|
|
|
{
|
|
|
|
reader.ReadInto(sources);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void write(storage::io::FileWriter &writer, Datasources &sources)
|
|
|
|
{
|
|
|
|
writer.WriteFrom(sources);
|
|
|
|
}
|
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
// read/write for segment data file
|
2017-04-04 18:00:17 -04:00
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void read(storage::io::FileReader &reader,
|
|
|
|
detail::SegmentDataContainerImpl<Ownership> &segment_data)
|
|
|
|
{
|
|
|
|
storage::serialization::read(reader, segment_data.index);
|
|
|
|
storage::serialization::read(reader, segment_data.nodes);
|
2017-05-10 19:04:09 -04:00
|
|
|
util::serialization::read(reader, segment_data.fwd_weights);
|
|
|
|
util::serialization::read(reader, segment_data.rev_weights);
|
|
|
|
util::serialization::read(reader, segment_data.fwd_durations);
|
|
|
|
util::serialization::read(reader, segment_data.rev_durations);
|
2017-07-27 13:24:34 -04:00
|
|
|
storage::serialization::read(reader, segment_data.fwd_datasources);
|
|
|
|
storage::serialization::read(reader, segment_data.rev_datasources);
|
2017-04-04 18:00:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void write(storage::io::FileWriter &writer,
|
|
|
|
const detail::SegmentDataContainerImpl<Ownership> &segment_data)
|
|
|
|
{
|
|
|
|
storage::serialization::write(writer, segment_data.index);
|
|
|
|
storage::serialization::write(writer, segment_data.nodes);
|
2017-05-10 19:04:09 -04:00
|
|
|
util::serialization::write(writer, segment_data.fwd_weights);
|
|
|
|
util::serialization::write(writer, segment_data.rev_weights);
|
|
|
|
util::serialization::write(writer, segment_data.fwd_durations);
|
|
|
|
util::serialization::write(writer, segment_data.rev_durations);
|
2017-07-27 13:24:34 -04:00
|
|
|
storage::serialization::write(writer, segment_data.fwd_datasources);
|
|
|
|
storage::serialization::write(writer, segment_data.rev_datasources);
|
2017-04-04 18:00:17 -04:00
|
|
|
}
|
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
// read/write for turn data file
|
2017-04-04 18:00:17 -04:00
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void read(storage::io::FileReader &reader,
|
|
|
|
detail::TurnDataContainerImpl<Ownership> &turn_data_container)
|
|
|
|
{
|
|
|
|
storage::serialization::read(reader, turn_data_container.turn_instructions);
|
|
|
|
storage::serialization::read(reader, turn_data_container.lane_data_ids);
|
|
|
|
storage::serialization::read(reader, turn_data_container.entry_class_ids);
|
|
|
|
storage::serialization::read(reader, turn_data_container.pre_turn_bearings);
|
|
|
|
storage::serialization::read(reader, turn_data_container.post_turn_bearings);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void write(storage::io::FileWriter &writer,
|
|
|
|
const detail::TurnDataContainerImpl<Ownership> &turn_data_container)
|
|
|
|
{
|
|
|
|
storage::serialization::write(writer, turn_data_container.turn_instructions);
|
|
|
|
storage::serialization::write(writer, turn_data_container.lane_data_ids);
|
|
|
|
storage::serialization::write(writer, turn_data_container.entry_class_ids);
|
|
|
|
storage::serialization::write(writer, turn_data_container.pre_turn_bearings);
|
|
|
|
storage::serialization::write(writer, turn_data_container.post_turn_bearings);
|
|
|
|
}
|
2017-04-25 05:36:34 -04:00
|
|
|
|
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void read(storage::io::FileReader &reader,
|
|
|
|
detail::EdgeBasedNodeDataContainerImpl<Ownership> &node_data_container)
|
|
|
|
{
|
|
|
|
storage::serialization::read(reader, node_data_container.geometry_ids);
|
|
|
|
storage::serialization::read(reader, node_data_container.name_ids);
|
2017-05-15 06:15:00 -04:00
|
|
|
storage::serialization::read(reader, node_data_container.component_ids);
|
2017-04-25 05:36:34 -04:00
|
|
|
storage::serialization::read(reader, node_data_container.travel_modes);
|
2017-06-27 18:01:05 -04:00
|
|
|
storage::serialization::read(reader, node_data_container.classes);
|
2017-04-25 05:36:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template <storage::Ownership Ownership>
|
|
|
|
inline void write(storage::io::FileWriter &writer,
|
|
|
|
const detail::EdgeBasedNodeDataContainerImpl<Ownership> &node_data_container)
|
|
|
|
{
|
|
|
|
storage::serialization::write(writer, node_data_container.geometry_ids);
|
|
|
|
storage::serialization::write(writer, node_data_container.name_ids);
|
2017-05-15 06:15:00 -04:00
|
|
|
storage::serialization::write(writer, node_data_container.component_ids);
|
2017-04-25 05:36:34 -04:00
|
|
|
storage::serialization::write(writer, node_data_container.travel_modes);
|
2017-06-27 18:01:05 -04:00
|
|
|
storage::serialization::write(writer, node_data_container.classes);
|
2017-04-25 05:36:34 -04:00
|
|
|
}
|
2017-05-11 06:13:52 -04:00
|
|
|
|
2017-07-06 11:09:24 -04:00
|
|
|
inline void read(storage::io::FileReader &reader, NodeRestriction &restriction)
|
|
|
|
{
|
|
|
|
reader.ReadInto(restriction.from);
|
|
|
|
reader.ReadInto(restriction.via);
|
|
|
|
reader.ReadInto(restriction.to);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void write(storage::io::FileWriter &writer, const NodeRestriction &restriction)
|
|
|
|
{
|
|
|
|
writer.WriteOne(restriction.from);
|
|
|
|
writer.WriteOne(restriction.via);
|
|
|
|
writer.WriteOne(restriction.to);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void read(storage::io::FileReader &reader, WayRestriction &restriction)
|
|
|
|
{
|
|
|
|
read(reader, restriction.in_restriction);
|
|
|
|
read(reader, restriction.out_restriction);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void write(storage::io::FileWriter &writer, const WayRestriction &restriction)
|
|
|
|
{
|
|
|
|
write(writer, restriction.in_restriction);
|
|
|
|
write(writer, restriction.out_restriction);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void read(storage::io::FileReader &reader, TurnRestriction &restriction)
|
|
|
|
{
|
2017-07-11 08:22:28 -04:00
|
|
|
reader.ReadInto(restriction.is_only);
|
2017-07-06 11:09:24 -04:00
|
|
|
if (restriction.Type() == RestrictionType::WAY_RESTRICTION)
|
|
|
|
{
|
|
|
|
WayRestriction way_restriction;
|
|
|
|
read(reader, way_restriction);
|
|
|
|
restriction.node_or_way = std::move(way_restriction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(restriction.Type() == RestrictionType::NODE_RESTRICTION);
|
|
|
|
NodeRestriction node_restriction;
|
|
|
|
read(reader, node_restriction);
|
|
|
|
restriction.node_or_way = std::move(node_restriction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void write(storage::io::FileWriter &writer, const TurnRestriction &restriction)
|
|
|
|
{
|
2017-07-11 08:22:28 -04:00
|
|
|
writer.WriteOne(restriction.is_only);
|
2017-07-06 11:09:24 -04:00
|
|
|
if (restriction.Type() == RestrictionType::WAY_RESTRICTION)
|
|
|
|
{
|
|
|
|
write(writer, boost::get<WayRestriction>(restriction.node_or_way));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(restriction.Type() == RestrictionType::NODE_RESTRICTION);
|
|
|
|
write(writer, boost::get<NodeRestriction>(restriction.node_or_way));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void write(storage::io::FileWriter &writer, const ConditionalTurnRestriction &restriction)
|
|
|
|
{
|
|
|
|
write(writer, static_cast<TurnRestriction>(restriction));
|
|
|
|
writer.WriteElementCount64(restriction.condition.size());
|
|
|
|
for (const auto &c : restriction.condition)
|
|
|
|
{
|
|
|
|
writer.WriteOne(c.modifier);
|
|
|
|
storage::serialization::write(writer, c.times);
|
|
|
|
storage::serialization::write(writer, c.weekdays);
|
|
|
|
storage::serialization::write(writer, c.monthdays);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void read(storage::io::FileReader &reader, ConditionalTurnRestriction &restriction)
|
|
|
|
{
|
|
|
|
TurnRestriction base;
|
|
|
|
read(reader, base);
|
|
|
|
reinterpret_cast<TurnRestriction &>(restriction) = std::move(base);
|
2017-07-11 08:22:28 -04:00
|
|
|
const auto num_conditions = reader.ReadElementCount64();
|
2017-07-06 11:09:24 -04:00
|
|
|
restriction.condition.resize(num_conditions);
|
|
|
|
for (uint64_t i = 0; i < num_conditions; i++)
|
|
|
|
{
|
|
|
|
reader.ReadInto(restriction.condition[i].modifier);
|
|
|
|
storage::serialization::read(reader, restriction.condition[i].times);
|
|
|
|
storage::serialization::read(reader, restriction.condition[i].weekdays);
|
|
|
|
storage::serialization::read(reader, restriction.condition[i].monthdays);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 06:13:52 -04:00
|
|
|
// read/write for conditional turn restrictions file
|
|
|
|
inline void read(storage::io::FileReader &reader, std::vector<TurnRestriction> &restrictions)
|
|
|
|
{
|
|
|
|
auto num_indices = reader.ReadElementCount64();
|
|
|
|
restrictions.reserve(num_indices);
|
|
|
|
TurnRestriction restriction;
|
2017-07-11 08:22:28 -04:00
|
|
|
while (num_indices-- > 0)
|
2017-05-11 06:13:52 -04:00
|
|
|
{
|
2017-07-06 11:09:24 -04:00
|
|
|
read(reader, restriction);
|
2017-05-11 06:13:52 -04:00
|
|
|
restrictions.push_back(std::move(restriction));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 11:09:24 -04:00
|
|
|
inline void write(storage::io::FileWriter &writer, const std::vector<TurnRestriction> &restrictions)
|
2017-05-11 06:13:52 -04:00
|
|
|
{
|
2017-07-11 08:22:28 -04:00
|
|
|
const auto num_indices = restrictions.size();
|
2017-07-06 11:09:24 -04:00
|
|
|
writer.WriteElementCount64(num_indices);
|
2017-07-11 08:22:28 -04:00
|
|
|
const auto write_restriction = [&writer](const auto &restriction) {
|
2017-07-06 11:09:24 -04:00
|
|
|
write(writer, restriction);
|
|
|
|
};
|
|
|
|
std::for_each(restrictions.begin(), restrictions.end(), write_restriction);
|
|
|
|
}
|
|
|
|
|
|
|
|
// read/write for conditional turn restrictions file
|
|
|
|
inline void read(storage::io::FileReader &reader,
|
|
|
|
std::vector<ConditionalTurnRestriction> &restrictions)
|
|
|
|
{
|
|
|
|
auto num_indices = reader.ReadElementCount64();
|
|
|
|
restrictions.reserve(num_indices);
|
|
|
|
ConditionalTurnRestriction restriction;
|
2017-07-11 08:22:28 -04:00
|
|
|
while (num_indices-- > 0)
|
2017-05-11 06:13:52 -04:00
|
|
|
{
|
2017-07-06 11:09:24 -04:00
|
|
|
read(reader, restriction);
|
|
|
|
restrictions.push_back(std::move(restriction));
|
2017-05-11 06:13:52 -04:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 11:09:24 -04:00
|
|
|
|
|
|
|
inline void write(storage::io::FileWriter &writer,
|
|
|
|
const std::vector<ConditionalTurnRestriction> &restrictions)
|
|
|
|
{
|
2017-07-11 08:22:28 -04:00
|
|
|
const auto num_indices = restrictions.size();
|
2017-07-06 11:09:24 -04:00
|
|
|
writer.WriteElementCount64(num_indices);
|
2017-07-11 08:22:28 -04:00
|
|
|
const auto write_restriction = [&writer](const auto &restriction) {
|
2017-07-06 11:09:24 -04:00
|
|
|
write(writer, restriction);
|
|
|
|
};
|
|
|
|
std::for_each(restrictions.begin(), restrictions.end(), write_restriction);
|
|
|
|
}
|
2017-04-04 18:00:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|