1 #ifndef EXTRACTION_WAY_HPP
2 #define EXTRACTION_WAY_HPP
3 
4 #include "extractor/road_classification.hpp"
5 #include "extractor/travel_mode.hpp"
6 #include "util/guidance/turn_lanes.hpp"
7 #include "util/typedefs.hpp"
8 
9 #include <string>
10 #include <vector>
11 
12 namespace osrm
13 {
14 namespace extractor
15 {
16 namespace detail
17 {
maybeSetString(std::string & str,const char * value)18 inline void maybeSetString(std::string &str, const char *value)
19 {
20     if (value == nullptr)
21     {
22         str.clear();
23     }
24     else
25     {
26         str = std::string(value);
27     }
28 }
29 } // namespace detail
30 
31 /**
32  * This struct is the direct result of the call to ```way_function```
33  * in the lua based profile.
34  *
35  * It is split into multiple edge segments in the ExtractorCallback.
36  */
37 struct ExtractionWay
38 {
ExtractionWayosrm::extractor::ExtractionWay39     ExtractionWay() { clear(); }
40 
clearosrm::extractor::ExtractionWay41     void clear()
42     {
43         forward_speed = -1;
44         backward_speed = -1;
45         forward_rate = -1;
46         backward_rate = -1;
47         duration = -1;
48         weight = -1;
49         name.clear();
50         forward_ref.clear();
51         backward_ref.clear();
52         pronunciation.clear();
53         destinations.clear();
54         exits.clear();
55         turn_lanes_forward.clear();
56         turn_lanes_backward.clear();
57         road_classification = RoadClassification();
58         forward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
59         backward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
60         roundabout = false;
61         circular = false;
62         is_startpoint = true;
63         forward_restricted = false;
64         backward_restricted = false;
65         is_left_hand_driving = false;
66         highway_turn_classification = 0;
67         access_turn_classification = 0;
68     }
69 
70     // wrappers to allow assigning nil (nullptr) to string values
SetNameosrm::extractor::ExtractionWay71     void SetName(const char *value) { detail::maybeSetString(name, value); }
GetNameosrm::extractor::ExtractionWay72     const char *GetName() const { return name.c_str(); }
SetForwardRefosrm::extractor::ExtractionWay73     void SetForwardRef(const char *value) { detail::maybeSetString(forward_ref, value); }
GetForwardRefosrm::extractor::ExtractionWay74     const char *GetForwardRef() const { return forward_ref.c_str(); }
SetBackwardRefosrm::extractor::ExtractionWay75     void SetBackwardRef(const char *value) { detail::maybeSetString(backward_ref, value); }
GetBackwardRefosrm::extractor::ExtractionWay76     const char *GetBackwardRef() const { return backward_ref.c_str(); }
SetDestinationsosrm::extractor::ExtractionWay77     void SetDestinations(const char *value) { detail::maybeSetString(destinations, value); }
GetDestinationsosrm::extractor::ExtractionWay78     const char *GetDestinations() const { return destinations.c_str(); }
SetExitsosrm::extractor::ExtractionWay79     void SetExits(const char *value) { detail::maybeSetString(exits, value); }
GetExitsosrm::extractor::ExtractionWay80     const char *GetExits() const { return exits.c_str(); }
SetPronunciationosrm::extractor::ExtractionWay81     void SetPronunciation(const char *value) { detail::maybeSetString(pronunciation, value); }
GetPronunciationosrm::extractor::ExtractionWay82     const char *GetPronunciation() const { return pronunciation.c_str(); }
SetTurnLanesForwardosrm::extractor::ExtractionWay83     void SetTurnLanesForward(const char *value)
84     {
85         detail::maybeSetString(turn_lanes_forward, value);
86     }
GetTurnLanesForwardosrm::extractor::ExtractionWay87     const char *GetTurnLanesForward() const { return turn_lanes_forward.c_str(); }
SetTurnLanesBackwardosrm::extractor::ExtractionWay88     void SetTurnLanesBackward(const char *value)
89     {
90         detail::maybeSetString(turn_lanes_backward, value);
91     }
GetTurnLanesBackwardosrm::extractor::ExtractionWay92     const char *GetTurnLanesBackward() const { return turn_lanes_backward.c_str(); }
93 
94     // markers for determining user-defined classes for each way
95     std::unordered_map<std::string, bool> forward_classes;
96     std::unordered_map<std::string, bool> backward_classes;
97 
98     // speed in km/h
99     double forward_speed;
100     double backward_speed;
101     // weight per meter
102     double forward_rate;
103     double backward_rate;
104     // duration of the whole way in both directions
105     double duration;
106     // weight of the whole way in both directions
107     double weight;
108     std::string name;
109     std::string forward_ref;
110     std::string backward_ref;
111     std::string pronunciation;
112     std::string destinations;
113     std::string exits;
114     std::string turn_lanes_forward;
115     std::string turn_lanes_backward;
116     RoadClassification road_classification;
117     TravelMode forward_travel_mode : 4;
118     TravelMode backward_travel_mode : 4;
119 
120     // Boolean flags
121     bool roundabout : 1;
122     bool circular : 1;
123     bool is_startpoint : 1;
124     bool forward_restricted : 1;
125     bool backward_restricted : 1;
126     bool is_left_hand_driving : 1;
127     bool : 2;
128 
129     // user classifications for turn penalties
130     std::uint8_t highway_turn_classification : 4;
131     std::uint8_t access_turn_classification : 4;
132 };
133 } // namespace extractor
134 } // namespace osrm
135 
136 #endif // EXTRACTION_WAY_HPP
137