1 #ifndef OSRM_EXTRACTOR_NODE_RESTRICTION_MAP_HPP_ 2 #define OSRM_EXTRACTOR_NODE_RESTRICTION_MAP_HPP_ 3 4 #include "extractor/restriction.hpp" 5 #include "restriction_graph.hpp" 6 #include "util/typedefs.hpp" 7 8 #include <boost/range/adaptor/filtered.hpp> 9 #include <boost/unordered_map.hpp> 10 11 #include <utility> 12 #include <vector> 13 14 namespace osrm 15 { 16 namespace extractor 17 { 18 19 // Allows easy check for whether a node restriction is present at a given intersection 20 template <typename RestrictionFilter> class NodeRestrictionMap 21 { 22 public: NodeRestrictionMap(const RestrictionGraph & restriction_graph)23 NodeRestrictionMap(const RestrictionGraph &restriction_graph) 24 : restriction_graph(restriction_graph), index_filter(RestrictionFilter{}) 25 { 26 } 27 28 // Find all restrictions applicable to (from,via,*) turns Restrictions(NodeID from,NodeID via) const29 auto Restrictions(NodeID from, NodeID via) const 30 { 31 return getRange(from, via) | boost::adaptors::filtered(index_filter); 32 }; 33 34 // Find all restrictions applicable to (from,via,to) turns Restrictions(NodeID from,NodeID via,NodeID to) const35 auto Restrictions(NodeID from, NodeID via, NodeID to) const 36 { 37 const auto turnFilter = [this, to](const auto &restriction) { 38 return index_filter(restriction) && restriction->IsTurnRestricted(to); 39 }; 40 return getRange(from, via) | boost::adaptors::filtered(turnFilter); 41 }; 42 43 private: getRange(NodeID from,NodeID via) const44 RestrictionGraph::RestrictionRange getRange(NodeID from, NodeID via) const 45 { 46 const auto start_node_it = restriction_graph.start_edge_to_node.find({from, via}); 47 if (start_node_it != restriction_graph.start_edge_to_node.end()) 48 { 49 return restriction_graph.GetRestrictions(start_node_it->second); 50 } 51 return {}; 52 } 53 const RestrictionGraph &restriction_graph; 54 const RestrictionFilter index_filter; 55 }; 56 57 // Restriction filters to use as index defaults 58 struct ConditionalOnly 59 { operator ()osrm::extractor::ConditionalOnly60 bool operator()(const TurnRestriction *restriction) const 61 { 62 return !restriction->IsUnconditional(); 63 }; 64 }; 65 66 struct UnconditionalOnly 67 { operator ()osrm::extractor::UnconditionalOnly68 bool operator()(const TurnRestriction *restriction) const 69 { 70 return restriction->IsUnconditional(); 71 }; 72 }; 73 74 using RestrictionMap = NodeRestrictionMap<UnconditionalOnly>; 75 using ConditionalRestrictionMap = NodeRestrictionMap<ConditionalOnly>; 76 77 } // namespace extractor 78 } // namespace osrm 79 80 #endif // OSRM_EXTRACTOR_NODE_RESTRICTION_MAP_HPP_ 81