1 #ifndef EXTRACTOR_CALLBACKS_HPP 2 #define EXTRACTOR_CALLBACKS_HPP 3 4 #include "extractor/class_data.hpp" 5 #include "extractor/turn_lane_types.hpp" 6 #include "util/typedefs.hpp" 7 8 #include <boost/functional/hash.hpp> 9 #include <boost/optional/optional_fwd.hpp> 10 11 #include <string> 12 #include <unordered_map> 13 14 namespace osmium 15 { 16 class Node; 17 class Way; 18 class Relation; 19 } // namespace osmium 20 21 namespace std 22 { 23 template <> struct hash<std::tuple<std::string, std::string, std::string, std::string, std::string>> 24 { operator ()std::hash25 std::size_t operator()( 26 const std::tuple<std::string, std::string, std::string, std::string, std::string> &mk) 27 const noexcept 28 { 29 std::size_t seed = 0; 30 boost::hash_combine(seed, std::get<0>(mk)); 31 boost::hash_combine(seed, std::get<1>(mk)); 32 boost::hash_combine(seed, std::get<2>(mk)); 33 boost::hash_combine(seed, std::get<3>(mk)); 34 boost::hash_combine(seed, std::get<4>(mk)); 35 return seed; 36 } 37 }; 38 } // namespace std 39 40 namespace osrm 41 { 42 namespace extractor 43 { 44 45 class ExtractionContainers; 46 struct ExtractionNode; 47 struct ExtractionWay; 48 struct ExtractionRelation; 49 struct ProfileProperties; 50 struct InputTurnRestriction; 51 struct InputManeuverOverride; 52 53 /** 54 * This class is used by the extractor with the results of the 55 * osmium based parsing and the customization through the lua profile. 56 * 57 * It mediates between the multi-threaded extraction process and the external memory containers. 58 * Thus the synchronization is handled inside of the extractor. 59 */ 60 class ExtractorCallbacks 61 { 62 private: 63 // used to deduplicate street names, refs, destinations, pronunciation, exits: 64 // actually maps to name ids 65 using MapKey = std::tuple<std::string, std::string, std::string, std::string, std::string>; 66 using MapVal = unsigned; 67 using StringMap = std::unordered_map<MapKey, MapVal>; 68 StringMap string_map; 69 ExtractionContainers &external_memory; 70 std::unordered_map<std::string, ClassData> &classes_map; 71 LaneDescriptionMap &lane_description_map; 72 bool fallback_to_duration; 73 bool force_split_edges; 74 75 public: 76 using ClassesMap = std::unordered_map<std::string, ClassData>; 77 78 explicit ExtractorCallbacks(ExtractionContainers &extraction_containers, 79 std::unordered_map<std::string, ClassData> &classes_map, 80 LaneDescriptionMap &lane_description_map, 81 const ProfileProperties &properties); 82 83 ExtractorCallbacks(const ExtractorCallbacks &) = delete; 84 ExtractorCallbacks &operator=(const ExtractorCallbacks &) = delete; 85 86 // warning: caller needs to take care of synchronization! 87 void ProcessNode(const osmium::Node ¤t_node, const ExtractionNode &result_node); 88 89 // warning: caller needs to take care of synchronization! 90 void ProcessRestriction(const InputTurnRestriction &restriction); 91 92 // warning: caller needs to take care of synchronization! 93 void ProcessWay(const osmium::Way ¤t_way, const ExtractionWay &result_way); 94 95 // warning: caller needs to take care of synchronization! 96 void ProcessManeuverOverride(const InputManeuverOverride &override); 97 }; 98 } // namespace extractor 99 } // namespace osrm 100 101 #endif /* EXTRACTOR_CALLBACKS_HPP */ 102