1 #ifndef EXTRACTION_CONTAINERS_HPP
2 #define EXTRACTION_CONTAINERS_HPP
3 
4 #include "extractor/internal_extractor_edge.hpp"
5 #include "extractor/nodes_of_way.hpp"
6 #include "extractor/query_node.hpp"
7 #include "extractor/restriction.hpp"
8 #include "extractor/scripting_environment.hpp"
9 
10 #include "storage/tar_fwd.hpp"
11 
12 #include <unordered_map>
13 
14 namespace osrm
15 {
16 namespace extractor
17 {
18 
19 /**
20  * Uses  memory containers to store all the data that
21  * is collected by the extractor callbacks.
22  *
23  * The data is the filtered, aggregated and finally written to disk.
24  */
25 class ExtractionContainers
26 {
27     using ReferencedWays = std::unordered_map<OSMWayID, NodesOfWay>;
28     // The relationship between way and nodes is lost during node preparation.
29     // We identify the ways and nodes relevant to restrictions/overrides prior to
30     // node processing so that they can be referenced in the preparation phase.
31     ReferencedWays IdentifyRestrictionWays();
32     ReferencedWays IdentifyManeuverOverrideWays();
33 
34     void PrepareNodes();
35     void PrepareManeuverOverrides(const ReferencedWays &maneuver_override_ways);
36     void PrepareRestrictions(const ReferencedWays &restriction_ways);
37     void PrepareEdges(ScriptingEnvironment &scripting_environment);
38 
39     void WriteNodes(storage::tar::FileWriter &file_out) const;
40     void WriteEdges(storage::tar::FileWriter &file_out) const;
41     void WriteMetadata(storage::tar::FileWriter &file_out) const;
42     void WriteCharData(const std::string &file_name);
43 
44   public:
45     using NodeIDVector = std::vector<OSMNodeID>;
46     using NodeVector = std::vector<QueryNode>;
47     using EdgeVector = std::vector<InternalExtractorEdge>;
48     using AnnotationDataVector = std::vector<NodeBasedEdgeAnnotation>;
49     using NameCharData = std::vector<unsigned char>;
50     using NameOffsets = std::vector<size_t>;
51     using WayIDVector = std::vector<OSMWayID>;
52     using WayNodeIDOffsets = std::vector<size_t>;
53 
54     std::vector<OSMNodeID> barrier_nodes;
55     std::vector<OSMNodeID> traffic_signals;
56     NodeIDVector used_node_id_list;
57     NodeVector all_nodes_list;
58     EdgeVector all_edges_list;
59     AnnotationDataVector all_edges_annotation_data_list;
60     NameCharData name_char_data;
61     NameOffsets name_offsets;
62     WayIDVector ways_list;
63     // Offsets into used nodes for each way_list entry
64     WayNodeIDOffsets way_node_id_offsets;
65 
66     unsigned max_internal_node_id;
67 
68     // List of restrictions (conditional and unconditional) before we transform them into the
69     // output types. Input containers reference OSMNodeIDs. We can only transform them to the
70     // correct internal IDs after we've read everything. Without a multi-parse approach,
71     // we have to remember the output restrictions before converting them to the internal formats
72     std::vector<InputTurnRestriction> restrictions_list;
73     std::vector<TurnRestriction> turn_restrictions;
74 
75     std::vector<InputManeuverOverride> external_maneuver_overrides_list;
76     std::vector<UnresolvedManeuverOverride> internal_maneuver_overrides;
77 
78     ExtractionContainers();
79 
80     void PrepareData(ScriptingEnvironment &scripting_environment,
81                      const std::string &osrm_path,
82                      const std::string &names_data_path);
83 };
84 } // namespace extractor
85 } // namespace osrm
86 
87 #endif /* EXTRACTION_CONTAINERS_HPP */
88