1 #ifndef OSRM_EXTRACTOR_FILES_HPP
2 #define OSRM_EXTRACTOR_FILES_HPP
3
4 #include "extractor/edge_based_edge.hpp"
5 #include "extractor/node_data_container.hpp"
6 #include "extractor/profile_properties.hpp"
7 #include "extractor/query_node.hpp"
8 #include "extractor/serialization.hpp"
9 #include "extractor/turn_lane_types.hpp"
10
11 #include "util/coordinate.hpp"
12 #include "util/guidance/bearing_class.hpp"
13 #include "util/guidance/entry_class.hpp"
14 #include "util/guidance/turn_lanes.hpp"
15 #include "util/packed_vector.hpp"
16 #include "util/range_table.hpp"
17 #include "util/serialization.hpp"
18
19 #include <boost/assert.hpp>
20
21 namespace osrm
22 {
23 namespace extractor
24 {
25 namespace files
26 {
27
28 // writes the .osrm.icd file
29 template <typename IntersectionBearingsT, typename EntryClassVectorT>
writeIntersections(const boost::filesystem::path & path,const IntersectionBearingsT & intersection_bearings,const EntryClassVectorT & entry_classes)30 inline void writeIntersections(const boost::filesystem::path &path,
31 const IntersectionBearingsT &intersection_bearings,
32 const EntryClassVectorT &entry_classes)
33 {
34 static_assert(std::is_same<IntersectionBearingsContainer, IntersectionBearingsT>::value ||
35 std::is_same<IntersectionBearingsView, IntersectionBearingsT>::value,
36 "");
37
38 storage::tar::FileWriter writer(path, storage::tar::FileWriter::GenerateFingerprint);
39
40 serialization::write(writer, "/common/intersection_bearings", intersection_bearings);
41 storage::serialization::write(writer, "/common/entry_classes", entry_classes);
42 }
43
44 // read the .osrm.icd file
45 template <typename IntersectionBearingsT, typename EntryClassVectorT>
readIntersections(const boost::filesystem::path & path,IntersectionBearingsT & intersection_bearings,EntryClassVectorT & entry_classes)46 inline void readIntersections(const boost::filesystem::path &path,
47 IntersectionBearingsT &intersection_bearings,
48 EntryClassVectorT &entry_classes)
49 {
50 static_assert(std::is_same<IntersectionBearingsContainer, IntersectionBearingsT>::value ||
51 std::is_same<IntersectionBearingsView, IntersectionBearingsT>::value,
52 "");
53
54 storage::tar::FileReader reader(path, storage::tar::FileReader::VerifyFingerprint);
55
56 serialization::read(reader, "/common/intersection_bearings", intersection_bearings);
57 storage::serialization::read(reader, "/common/entry_classes", entry_classes);
58 }
59
60 // reads .osrm.properties
readProfileProperties(const boost::filesystem::path & path,ProfileProperties & properties)61 inline void readProfileProperties(const boost::filesystem::path &path,
62 ProfileProperties &properties)
63 {
64 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
65 storage::tar::FileReader reader{path, fingerprint};
66
67 serialization::read(reader, "/common/properties", properties);
68 }
69
70 // writes .osrm.properties
writeProfileProperties(const boost::filesystem::path & path,const ProfileProperties & properties)71 inline void writeProfileProperties(const boost::filesystem::path &path,
72 const ProfileProperties &properties)
73 {
74 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
75 storage::tar::FileWriter writer{path, fingerprint};
76
77 serialization::write(writer, "/common/properties", properties);
78 }
79
80 template <typename EdgeBasedEdgeVector>
writeEdgeBasedGraph(const boost::filesystem::path & path,EdgeID const number_of_edge_based_nodes,const EdgeBasedEdgeVector & edge_based_edge_list,const std::uint32_t connectivity_checksum)81 void writeEdgeBasedGraph(const boost::filesystem::path &path,
82 EdgeID const number_of_edge_based_nodes,
83 const EdgeBasedEdgeVector &edge_based_edge_list,
84 const std::uint32_t connectivity_checksum)
85 {
86 static_assert(std::is_same<typename EdgeBasedEdgeVector::value_type, EdgeBasedEdge>::value, "");
87
88 storage::tar::FileWriter writer(path, storage::tar::FileWriter::GenerateFingerprint);
89
90 writer.WriteElementCount64("/common/number_of_edge_based_nodes", 1);
91 writer.WriteFrom("/common/number_of_edge_based_nodes", number_of_edge_based_nodes);
92 storage::serialization::write(writer, "/common/edge_based_edge_list", edge_based_edge_list);
93 writer.WriteElementCount64("/common/connectivity_checksum", 1);
94 writer.WriteFrom("/common/connectivity_checksum", connectivity_checksum);
95 }
96
97 // reads .osrm.ebg file
98 template <typename EdgeBasedEdgeVector>
readEdgeBasedGraph(const boost::filesystem::path & path,EdgeID & number_of_edge_based_nodes,EdgeBasedEdgeVector & edge_based_edge_list,std::uint32_t & connectivity_checksum)99 void readEdgeBasedGraph(const boost::filesystem::path &path,
100 EdgeID &number_of_edge_based_nodes,
101 EdgeBasedEdgeVector &edge_based_edge_list,
102 std::uint32_t &connectivity_checksum)
103 {
104 static_assert(std::is_same<typename EdgeBasedEdgeVector::value_type, EdgeBasedEdge>::value, "");
105
106 storage::tar::FileReader reader(path, storage::tar::FileReader::VerifyFingerprint);
107
108 reader.ReadInto("/common/number_of_edge_based_nodes", number_of_edge_based_nodes);
109 storage::serialization::read(reader, "/common/edge_based_edge_list", edge_based_edge_list);
110 reader.ReadInto("/common/connectivity_checksum", connectivity_checksum);
111 }
112
113 // reads .osrm.nbg_nodes
114 template <typename CoordinatesT, typename PackedOSMIDsT>
readNodes(const boost::filesystem::path & path,CoordinatesT & coordinates,PackedOSMIDsT & osm_node_ids)115 inline void readNodes(const boost::filesystem::path &path,
116 CoordinatesT &coordinates,
117 PackedOSMIDsT &osm_node_ids)
118 {
119 static_assert(std::is_same<typename CoordinatesT::value_type, util::Coordinate>::value, "");
120 static_assert(std::is_same<typename PackedOSMIDsT::value_type, OSMNodeID>::value, "");
121
122 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
123 storage::tar::FileReader reader{path, fingerprint};
124
125 storage::serialization::read(reader, "/common/nbn_data/coordinates", coordinates);
126 util::serialization::read(reader, "/common/nbn_data/osm_node_ids", osm_node_ids);
127 }
128
129 // reads only coordinates from .osrm.nbg_nodes
130 template <typename CoordinatesT>
readNodeCoordinates(const boost::filesystem::path & path,CoordinatesT & coordinates)131 inline void readNodeCoordinates(const boost::filesystem::path &path, CoordinatesT &coordinates)
132 {
133 static_assert(std::is_same<typename CoordinatesT::value_type, util::Coordinate>::value, "");
134
135 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
136 storage::tar::FileReader reader{path, fingerprint};
137
138 storage::serialization::read(reader, "/common/nbn_data/coordinates", coordinates);
139 }
140
141 // writes .osrm.nbg_nodes
142 template <typename CoordinatesT, typename PackedOSMIDsT>
writeNodes(const boost::filesystem::path & path,const CoordinatesT & coordinates,const PackedOSMIDsT & osm_node_ids)143 inline void writeNodes(const boost::filesystem::path &path,
144 const CoordinatesT &coordinates,
145 const PackedOSMIDsT &osm_node_ids)
146 {
147 static_assert(std::is_same<typename CoordinatesT::value_type, util::Coordinate>::value, "");
148 static_assert(std::is_same<typename PackedOSMIDsT::value_type, OSMNodeID>::value, "");
149
150 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
151 storage::tar::FileWriter writer{path, fingerprint};
152
153 storage::serialization::write(writer, "/common/nbn_data/coordinates", coordinates);
154 util::serialization::write(writer, "/common/nbn_data/osm_node_ids", osm_node_ids);
155 }
156
157 // reads .osrm.cnbg_to_ebg
readNBGMapping(const boost::filesystem::path & path,std::vector<NBGToEBG> & mapping)158 inline void readNBGMapping(const boost::filesystem::path &path, std::vector<NBGToEBG> &mapping)
159 {
160 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
161 storage::tar::FileReader reader{path, fingerprint};
162
163 storage::serialization::read(reader, "/common/cnbg_to_ebg", mapping);
164 }
165
166 // writes .osrm.cnbg_to_ebg
writeNBGMapping(const boost::filesystem::path & path,const std::vector<NBGToEBG> & mapping)167 inline void writeNBGMapping(const boost::filesystem::path &path,
168 const std::vector<NBGToEBG> &mapping)
169 {
170 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
171 storage::tar::FileWriter writer{path, fingerprint};
172
173 storage::serialization::write(writer, "/common/cnbg_to_ebg", mapping);
174 }
175
176 // reads .osrm.datasource_names
readDatasources(const boost::filesystem::path & path,Datasources & sources)177 inline void readDatasources(const boost::filesystem::path &path, Datasources &sources)
178 {
179 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
180 storage::tar::FileReader reader{path, fingerprint};
181
182 serialization::read(reader, "/common/data_sources_names", sources);
183 }
184
185 // writes .osrm.datasource_names
writeDatasources(const boost::filesystem::path & path,Datasources & sources)186 inline void writeDatasources(const boost::filesystem::path &path, Datasources &sources)
187 {
188 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
189 storage::tar::FileWriter writer{path, fingerprint};
190
191 serialization::write(writer, "/common/data_sources_names", sources);
192 }
193
194 // reads .osrm.geometry
195 template <typename SegmentDataT>
readSegmentData(const boost::filesystem::path & path,SegmentDataT & segment_data)196 inline void readSegmentData(const boost::filesystem::path &path, SegmentDataT &segment_data)
197 {
198 static_assert(std::is_same<SegmentDataContainer, SegmentDataT>::value ||
199 std::is_same<SegmentDataView, SegmentDataT>::value,
200 "");
201 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
202 storage::tar::FileReader reader{path, fingerprint};
203
204 serialization::read(reader, "/common/segment_data", segment_data);
205 }
206
207 // writes .osrm.geometry
208 template <typename SegmentDataT>
writeSegmentData(const boost::filesystem::path & path,const SegmentDataT & segment_data)209 inline void writeSegmentData(const boost::filesystem::path &path, const SegmentDataT &segment_data)
210 {
211 static_assert(std::is_same<SegmentDataContainer, SegmentDataT>::value ||
212 std::is_same<SegmentDataView, SegmentDataT>::value,
213 "");
214 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
215 storage::tar::FileWriter writer{path, fingerprint};
216
217 serialization::write(writer, "/common/segment_data", segment_data);
218 }
219
220 // reads .osrm.ebg_nodes
221 template <typename NodeDataT>
readNodeData(const boost::filesystem::path & path,NodeDataT & node_data)222 inline void readNodeData(const boost::filesystem::path &path, NodeDataT &node_data)
223 {
224 static_assert(std::is_same<EdgeBasedNodeDataContainer, NodeDataT>::value ||
225 std::is_same<EdgeBasedNodeDataView, NodeDataT>::value ||
226 std::is_same<EdgeBasedNodeDataExternalContainer, NodeDataT>::value,
227 "");
228 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
229 storage::tar::FileReader reader{path, fingerprint};
230
231 serialization::read(reader, "/common/ebg_node_data", node_data);
232 }
233
234 // writes .osrm.ebg_nodes
235 template <typename NodeDataT>
writeNodeData(const boost::filesystem::path & path,const NodeDataT & node_data)236 inline void writeNodeData(const boost::filesystem::path &path, const NodeDataT &node_data)
237 {
238 static_assert(std::is_same<EdgeBasedNodeDataContainer, NodeDataT>::value ||
239 std::is_same<EdgeBasedNodeDataView, NodeDataT>::value ||
240 std::is_same<EdgeBasedNodeDataExternalContainer, NodeDataT>::value,
241 "");
242 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
243 storage::tar::FileWriter writer{path, fingerprint};
244
245 serialization::write(writer, "/common/ebg_node_data", node_data);
246 }
247
248 // reads .osrm.tls
249 template <typename OffsetsT, typename MaskT>
readTurnLaneDescriptions(const boost::filesystem::path & path,OffsetsT & turn_offsets,MaskT & turn_masks)250 inline void readTurnLaneDescriptions(const boost::filesystem::path &path,
251 OffsetsT &turn_offsets,
252 MaskT &turn_masks)
253 {
254 static_assert(std::is_same<typename MaskT::value_type, extractor::TurnLaneType::Mask>::value,
255 "");
256 static_assert(std::is_same<typename OffsetsT::value_type, std::uint32_t>::value, "");
257
258 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
259 storage::tar::FileReader reader{path, fingerprint};
260
261 storage::serialization::read(reader, "/common/turn_lanes/offsets", turn_offsets);
262 storage::serialization::read(reader, "/common/turn_lanes/masks", turn_masks);
263 }
264
265 // writes .osrm.tls
266 template <typename OffsetsT, typename MaskT>
writeTurnLaneDescriptions(const boost::filesystem::path & path,const OffsetsT & turn_offsets,const MaskT & turn_masks)267 inline void writeTurnLaneDescriptions(const boost::filesystem::path &path,
268 const OffsetsT &turn_offsets,
269 const MaskT &turn_masks)
270 {
271 static_assert(std::is_same<typename MaskT::value_type, extractor::TurnLaneType::Mask>::value,
272 "");
273 static_assert(std::is_same<typename OffsetsT::value_type, std::uint32_t>::value, "");
274
275 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
276 storage::tar::FileWriter writer{path, fingerprint};
277
278 storage::serialization::write(writer, "/common/turn_lanes/offsets", turn_offsets);
279 storage::serialization::write(writer, "/common/turn_lanes/masks", turn_masks);
280 }
281
282 // reads .osrm.tld
283 template <typename TurnLaneDataT>
readTurnLaneData(const boost::filesystem::path & path,TurnLaneDataT & turn_lane_data)284 inline void readTurnLaneData(const boost::filesystem::path &path, TurnLaneDataT &turn_lane_data)
285 {
286 static_assert(
287 std::is_same<typename TurnLaneDataT::value_type, util::guidance::LaneTupleIdPair>::value,
288 "");
289
290 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
291 storage::tar::FileReader reader{path, fingerprint};
292
293 storage::serialization::read(reader, "/common/turn_lanes/data", turn_lane_data);
294 }
295
296 // writes .osrm.tld
297 template <typename TurnLaneDataT>
writeTurnLaneData(const boost::filesystem::path & path,const TurnLaneDataT & turn_lane_data)298 inline void writeTurnLaneData(const boost::filesystem::path &path,
299 const TurnLaneDataT &turn_lane_data)
300 {
301 static_assert(
302 std::is_same<typename TurnLaneDataT::value_type, util::guidance::LaneTupleIdPair>::value,
303 "");
304
305 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
306 storage::tar::FileWriter writer{path, fingerprint};
307
308 storage::serialization::write(writer, "/common/turn_lanes/data", turn_lane_data);
309 }
310
311 // reads .osrm.timestamp
312 template <typename TimestampDataT>
readTimestamp(const boost::filesystem::path & path,TimestampDataT & timestamp)313 inline void readTimestamp(const boost::filesystem::path &path, TimestampDataT ×tamp)
314 {
315 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
316 storage::tar::FileReader reader{path, fingerprint};
317
318 storage::serialization::read(reader, "/common/timestamp", timestamp);
319 }
320
321 // writes .osrm.timestamp
322 template <typename TimestampDataT>
writeTimestamp(const boost::filesystem::path & path,const TimestampDataT & timestamp)323 inline void writeTimestamp(const boost::filesystem::path &path, const TimestampDataT ×tamp)
324 {
325 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
326 storage::tar::FileWriter writer{path, fingerprint};
327
328 storage::serialization::write(writer, "/common/timestamp", timestamp);
329 }
330
331 // reads .osrm.maneuver_overrides
332 template <typename StorageManeuverOverrideT, typename NodeSequencesT>
readManeuverOverrides(const boost::filesystem::path & path,StorageManeuverOverrideT & maneuver_overrides,NodeSequencesT & node_sequences)333 inline void readManeuverOverrides(const boost::filesystem::path &path,
334 StorageManeuverOverrideT &maneuver_overrides,
335 NodeSequencesT &node_sequences)
336 {
337 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
338 storage::tar::FileReader reader{path, fingerprint};
339
340 storage::serialization::read(
341 reader, "/common/maneuver_overrides/overrides", maneuver_overrides);
342 storage::serialization::read(
343 reader, "/common/maneuver_overrides/node_sequences", node_sequences);
344 }
345
346 // writes .osrm.maneuver_overrides
writeManeuverOverrides(const boost::filesystem::path & path,const std::vector<StorageManeuverOverride> & maneuver_overrides,const std::vector<NodeID> & node_sequences)347 inline void writeManeuverOverrides(const boost::filesystem::path &path,
348 const std::vector<StorageManeuverOverride> &maneuver_overrides,
349 const std::vector<NodeID> &node_sequences)
350 {
351 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
352 storage::tar::FileWriter writer{path, fingerprint};
353
354 storage::serialization::write(
355 writer, "/common/maneuver_overrides/overrides", maneuver_overrides);
356 storage::serialization::write(
357 writer, "/common/maneuver_overrides/node_sequences", node_sequences);
358 }
359
360 // writes .osrm.turn_weight_penalties
361 template <typename TurnPenaltyT>
writeTurnWeightPenalty(const boost::filesystem::path & path,const TurnPenaltyT & turn_penalty)362 inline void writeTurnWeightPenalty(const boost::filesystem::path &path,
363 const TurnPenaltyT &turn_penalty)
364 {
365 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
366 storage::tar::FileWriter writer{path, fingerprint};
367
368 storage::serialization::write(writer, "/common/turn_penalty/weight", turn_penalty);
369 }
370
371 // read .osrm.turn_weight_penalties
372 template <typename TurnPenaltyT>
readTurnWeightPenalty(const boost::filesystem::path & path,TurnPenaltyT & turn_penalty)373 inline void readTurnWeightPenalty(const boost::filesystem::path &path, TurnPenaltyT &turn_penalty)
374 {
375 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
376 storage::tar::FileReader reader{path, fingerprint};
377
378 storage::serialization::read(reader, "/common/turn_penalty/weight", turn_penalty);
379 }
380
381 // writes .osrm.turn_duration_penalties
382 template <typename TurnPenaltyT>
writeTurnDurationPenalty(const boost::filesystem::path & path,const TurnPenaltyT & turn_penalty)383 inline void writeTurnDurationPenalty(const boost::filesystem::path &path,
384 const TurnPenaltyT &turn_penalty)
385 {
386 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
387 storage::tar::FileWriter writer{path, fingerprint};
388
389 storage::serialization::write(writer, "/common/turn_penalty/duration", turn_penalty);
390 }
391
392 // read .osrm.turn_weight_penalties
393 template <typename TurnPenaltyT>
readTurnDurationPenalty(const boost::filesystem::path & path,TurnPenaltyT & turn_penalty)394 inline void readTurnDurationPenalty(const boost::filesystem::path &path, TurnPenaltyT &turn_penalty)
395 {
396 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
397 storage::tar::FileReader reader{path, fingerprint};
398
399 storage::serialization::read(reader, "/common/turn_penalty/duration", turn_penalty);
400 }
401
402 // writes .osrm.turn_penalties_index
403 template <typename TurnIndexT>
writeTurnPenaltiesIndex(const boost::filesystem::path & path,const TurnIndexT & turn_penalties_index)404 inline void writeTurnPenaltiesIndex(const boost::filesystem::path &path,
405 const TurnIndexT &turn_penalties_index)
406 {
407 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
408 storage::tar::FileWriter writer{path, fingerprint};
409
410 storage::serialization::write(writer, "/extractor/turn_index", turn_penalties_index);
411 }
412
413 // read .osrm.turn_penalties_index
414 template <typename TurnIndexT>
readTurnPenaltiesIndex(const boost::filesystem::path & path,TurnIndexT & turn_penalties_index)415 inline void readTurnPenaltiesIndex(const boost::filesystem::path &path,
416 TurnIndexT &turn_penalties_index)
417 {
418 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
419 storage::tar::FileReader reader{path, fingerprint};
420
421 storage::serialization::read(reader, "/extractor/turn_index", turn_penalties_index);
422 }
423
424 // writes .osrm.restrictions
425 template <typename ConditionalRestrictionsT>
writeConditionalRestrictions(const boost::filesystem::path & path,const ConditionalRestrictionsT & conditional_restrictions)426 inline void writeConditionalRestrictions(const boost::filesystem::path &path,
427 const ConditionalRestrictionsT &conditional_restrictions)
428 {
429 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
430 storage::tar::FileWriter writer{path, fingerprint};
431
432 serialization::write(writer, "/common/conditional_restrictions", conditional_restrictions);
433 }
434
435 // read .osrm.restrictions
436 template <typename ConditionalRestrictionsT>
readConditionalRestrictions(const boost::filesystem::path & path,ConditionalRestrictionsT & conditional_restrictions)437 inline void readConditionalRestrictions(const boost::filesystem::path &path,
438 ConditionalRestrictionsT &conditional_restrictions)
439 {
440 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
441 storage::tar::FileReader reader{path, fingerprint};
442
443 serialization::read(reader, "/common/conditional_restrictions", conditional_restrictions);
444 }
445
446 // reads .osrm file which is a temporary file of osrm-extract
447 template <typename BarrierOutIter, typename TrafficSignalsOutIter, typename PackedOSMIDsT>
readRawNBGraph(const boost::filesystem::path & path,BarrierOutIter barriers,TrafficSignalsOutIter traffic_signals,std::vector<util::Coordinate> & coordinates,PackedOSMIDsT & osm_node_ids,std::vector<extractor::NodeBasedEdge> & edge_list,std::vector<extractor::NodeBasedEdgeAnnotation> & annotations)448 void readRawNBGraph(const boost::filesystem::path &path,
449 BarrierOutIter barriers,
450 TrafficSignalsOutIter traffic_signals,
451 std::vector<util::Coordinate> &coordinates,
452 PackedOSMIDsT &osm_node_ids,
453 std::vector<extractor::NodeBasedEdge> &edge_list,
454 std::vector<extractor::NodeBasedEdgeAnnotation> &annotations)
455 {
456 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
457 storage::tar::FileReader reader{path, fingerprint};
458
459 auto number_of_nodes = reader.ReadElementCount64("/extractor/nodes");
460 coordinates.resize(number_of_nodes);
461 osm_node_ids.reserve(number_of_nodes);
462 auto index = 0;
463 auto decode = [&](const auto ¤t_node) {
464 coordinates[index].lon = current_node.lon;
465 coordinates[index].lat = current_node.lat;
466 osm_node_ids.push_back(current_node.node_id);
467 index++;
468 };
469 reader.ReadStreaming<extractor::QueryNode>("/extractor/nodes",
470 boost::make_function_output_iterator(decode));
471
472 reader.ReadStreaming<NodeID>("/extractor/barriers", barriers);
473
474 reader.ReadStreaming<NodeID>("/extractor/traffic_lights", traffic_signals);
475
476 storage::serialization::read(reader, "/extractor/edges", edge_list);
477 storage::serialization::read(reader, "/extractor/annotations", annotations);
478 }
479
480 template <typename NameTableT>
readNames(const boost::filesystem::path & path,NameTableT & table)481 void readNames(const boost::filesystem::path &path, NameTableT &table)
482 {
483 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
484 storage::tar::FileReader reader{path, fingerprint};
485
486 serialization::read(reader, "/common/names", table);
487 }
488
489 template <typename NameTableT>
writeNames(const boost::filesystem::path & path,const NameTableT & table)490 void writeNames(const boost::filesystem::path &path, const NameTableT &table)
491 {
492 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
493 storage::tar::FileWriter writer{path, fingerprint};
494
495 serialization::write(writer, "/common/names", table);
496 }
497
498 template <typename NodeWeightsVectorT>
readEdgeBasedNodeWeights(const boost::filesystem::path & path,NodeWeightsVectorT & weights)499 void readEdgeBasedNodeWeights(const boost::filesystem::path &path, NodeWeightsVectorT &weights)
500 {
501 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
502 storage::tar::FileReader reader{path, fingerprint};
503
504 storage::serialization::read(reader, "/extractor/edge_based_node_weights", weights);
505 }
506
507 template <typename NodeDistancesVectorT>
readEdgeBasedNodeDistances(const boost::filesystem::path & path,NodeDistancesVectorT & distances)508 void readEdgeBasedNodeDistances(const boost::filesystem::path &path,
509 NodeDistancesVectorT &distances)
510 {
511 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
512 storage::tar::FileReader reader{path, fingerprint};
513
514 storage::serialization::read(reader, "/extractor/edge_based_node_distances", distances);
515 }
516
517 template <typename NodeWeightsVectorT, typename NodeDurationsVectorT, typename NodeDistancesVectorT>
writeEdgeBasedNodeWeightsDurationsDistances(const boost::filesystem::path & path,const NodeWeightsVectorT & weights,const NodeDurationsVectorT & durations,const NodeDistancesVectorT & distances)518 void writeEdgeBasedNodeWeightsDurationsDistances(const boost::filesystem::path &path,
519 const NodeWeightsVectorT &weights,
520 const NodeDurationsVectorT &durations,
521 const NodeDistancesVectorT &distances)
522 {
523 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
524 storage::tar::FileWriter writer{path, fingerprint};
525
526 storage::serialization::write(writer, "/extractor/edge_based_node_weights", weights);
527 storage::serialization::write(writer, "/extractor/edge_based_node_durations", durations);
528 storage::serialization::write(writer, "/extractor/edge_based_node_distances", distances);
529 }
530
531 template <typename NodeWeightsVectorT, typename NodeDurationsVectorT>
readEdgeBasedNodeWeightsDurations(const boost::filesystem::path & path,NodeWeightsVectorT & weights,NodeDurationsVectorT & durations)532 void readEdgeBasedNodeWeightsDurations(const boost::filesystem::path &path,
533 NodeWeightsVectorT &weights,
534 NodeDurationsVectorT &durations)
535 {
536 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
537 storage::tar::FileReader reader{path, fingerprint};
538
539 storage::serialization::read(reader, "/extractor/edge_based_node_weights", weights);
540 storage::serialization::read(reader, "/extractor/edge_based_node_durations", durations);
541 }
542
543 template <typename NodeWeightsVectorT, typename NodeDurationsVectorT>
writeEdgeBasedNodeWeightsDurations(const boost::filesystem::path & path,const NodeWeightsVectorT & weights,const NodeDurationsVectorT & durations)544 void writeEdgeBasedNodeWeightsDurations(const boost::filesystem::path &path,
545 const NodeWeightsVectorT &weights,
546 const NodeDurationsVectorT &durations)
547 {
548 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
549 storage::tar::FileWriter writer{path, fingerprint};
550
551 storage::serialization::write(writer, "/extractor/edge_based_node_weights", weights);
552 storage::serialization::write(writer, "/extractor/edge_based_node_durations", durations);
553 }
554
555 template <typename RTreeT>
writeRamIndex(const boost::filesystem::path & path,const RTreeT & rtree)556 void writeRamIndex(const boost::filesystem::path &path, const RTreeT &rtree)
557 {
558 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
559 storage::tar::FileWriter writer{path, fingerprint};
560
561 util::serialization::write(writer, "/common/rtree", rtree);
562 }
563
readRamIndex(const boost::filesystem::path & path,RTreeT & rtree)564 template <typename RTreeT> void readRamIndex(const boost::filesystem::path &path, RTreeT &rtree)
565 {
566 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
567 storage::tar::FileReader reader{path, fingerprint};
568
569 util::serialization::read(reader, "/common/rtree", rtree);
570 }
571
572 template <typename EdgeListT>
writeCompressedNodeBasedGraph(const boost::filesystem::path & path,const EdgeListT & edge_list)573 void writeCompressedNodeBasedGraph(const boost::filesystem::path &path, const EdgeListT &edge_list)
574 {
575 const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
576 storage::tar::FileWriter writer{path, fingerprint};
577
578 storage::serialization::write(writer, "/extractor/cnbg", edge_list);
579 }
580
581 template <typename EdgeListT>
readCompressedNodeBasedGraph(const boost::filesystem::path & path,EdgeListT & edge_list)582 void readCompressedNodeBasedGraph(const boost::filesystem::path &path, EdgeListT &edge_list)
583 {
584 const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
585 storage::tar::FileReader reader{path, fingerprint};
586
587 storage::serialization::read(reader, "/extractor/cnbg", edge_list);
588 }
589 } // namespace files
590 } // namespace extractor
591 } // namespace osrm
592
593 #endif
594