diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index d185be8c8..e299fc700 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -51,12 +51,13 @@ struct _DescriptorConfig { unsigned short z; }; +template class BaseDescriptor { public: BaseDescriptor() { } //Maybe someone can explain the pure virtual destructor thing to me (dennis) virtual ~BaseDescriptor() { } - virtual void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngine &sEngine) = 0; + virtual void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, const DataFacadeT * facade) = 0; virtual void SetConfig(const _DescriptorConfig & config) = 0; }; diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 67066fbd0..2b95537db 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -92,126 +92,127 @@ void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) { pc.printUnencodedString(pathDescription, output); } -void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) { - if(0 == pathDescription.size()) - return; +// void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) { -// unsigned entireLength = 0; - /** starts at index 1 */ - pathDescription[0].length = 0; - for(unsigned i = 1; i < pathDescription.size(); ++i) { - pathDescription[i].length = ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); - } +// if(0 == pathDescription.size()) +// return; - double lengthOfSegment = 0; - unsigned durationOfSegment = 0; - unsigned indexOfSegmentBegin = 0; +// // unsigned entireLength = 0; +// /** starts at index 1 */ +// pathDescription[0].length = 0; +// for(unsigned i = 1; i < pathDescription.size(); ++i) { +// pathDescription[i].length = ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); +// } - std::string string0 = sEngine.GetEscapedNameForNameID(pathDescription[0].nameID); - std::string string1; +// double lengthOfSegment = 0; +// unsigned durationOfSegment = 0; +// unsigned indexOfSegmentBegin = 0; + +// std::string string0 = sEngine.GetEscapedNameForNameID(pathDescription[0].nameID); +// std::string string1; - /*Simplify turn instructions - Input : - 10. Turn left on B 36 for 20 km - 11. Continue on B 35; B 36 for 2 km - 12. Continue on B 36 for 13 km +// /*Simplify turn instructions +// Input : +// 10. Turn left on B 36 for 20 km +// 11. Continue on B 35; B 36 for 2 km +// 12. Continue on B 36 for 13 km - becomes: - 10. Turn left on B 36 for 35 km - */ -//TODO: rework to check only end and start of string. -// stl string is way to expensive +// becomes: +// 10. Turn left on B 36 for 35 km +// */ +// //TODO: rework to check only end and start of string. +// // stl string is way to expensive -// unsigned lastTurn = 0; -// for(unsigned i = 1; i < pathDescription.size(); ++i) { -// string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); -// if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { -// if(std::string::npos != string0.find(string1+";") -// || std::string::npos != string0.find(";"+string1) -// || std::string::npos != string0.find(string1+" ;") -// || std::string::npos != string0.find("; "+string1) -// ){ -// SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; -// for(; lastTurn != i; ++lastTurn) -// pathDescription[lastTurn].nameID = pathDescription[i].nameID; -// pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; -// } else if(std::string::npos != string1.find(string0+";") -// || std::string::npos != string1.find(";"+string0) -// || std::string::npos != string1.find(string0+" ;") -// || std::string::npos != string1.find("; "+string0) -// ){ -// SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; -// pathDescription[i].nameID = pathDescription[i-1].nameID; -// pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; -// } -// } -// if (TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { -// lastTurn = i; -// } -// string0 = string1; -// } +// // unsigned lastTurn = 0; +// // for(unsigned i = 1; i < pathDescription.size(); ++i) { +// // string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); +// // if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { +// // if(std::string::npos != string0.find(string1+";") +// // || std::string::npos != string0.find(";"+string1) +// // || std::string::npos != string0.find(string1+" ;") +// // || std::string::npos != string0.find("; "+string1) +// // ){ +// // SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; +// // for(; lastTurn != i; ++lastTurn) +// // pathDescription[lastTurn].nameID = pathDescription[i].nameID; +// // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; +// // } else if(std::string::npos != string1.find(string0+";") +// // || std::string::npos != string1.find(";"+string0) +// // || std::string::npos != string1.find(string0+" ;") +// // || std::string::npos != string1.find("; "+string0) +// // ){ +// // SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; +// // pathDescription[i].nameID = pathDescription[i-1].nameID; +// // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; +// // } +// // } +// // if (TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { +// // lastTurn = i; +// // } +// // string0 = string1; +// // } - for(unsigned i = 1; i < pathDescription.size(); ++i) { - entireLength += pathDescription[i].length; - lengthOfSegment += pathDescription[i].length; - durationOfSegment += pathDescription[i].duration; - pathDescription[indexOfSegmentBegin].length = lengthOfSegment; - pathDescription[indexOfSegmentBegin].duration = durationOfSegment; +// for(unsigned i = 1; i < pathDescription.size(); ++i) { +// entireLength += pathDescription[i].length; +// lengthOfSegment += pathDescription[i].length; +// durationOfSegment += pathDescription[i].duration; +// pathDescription[indexOfSegmentBegin].length = lengthOfSegment; +// pathDescription[indexOfSegmentBegin].duration = durationOfSegment; - if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { - //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; - assert(pathDescription[i].necessary); - lengthOfSegment = 0; - durationOfSegment = 0; - indexOfSegmentBegin = i; - } - } - // SimpleLogger().Write() << "#segs: " << pathDescription.size(); +// if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { +// //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; +// assert(pathDescription[i].necessary); +// lengthOfSegment = 0; +// durationOfSegment = 0; +// indexOfSegmentBegin = i; +// } +// } +// // SimpleLogger().Write() << "#segs: " << pathDescription.size(); - //Post-processing to remove empty or nearly empty path segments - if(std::numeric_limits::epsilon() > pathDescription.back().length) { - // SimpleLogger().Write() << "#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length; - if(pathDescription.size() > 2){ - pathDescription.pop_back(); - pathDescription.back().necessary = true; - pathDescription.back().turnInstruction = TurnInstructions.NoTurn; - targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; - // SimpleLogger().Write() << "Deleting last turn instruction"; - } - } else { - pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio); - } - if(std::numeric_limits::epsilon() > pathDescription[0].length) { - //TODO: this is never called actually? - if(pathDescription.size() > 2) { - pathDescription.erase(pathDescription.begin()); - pathDescription[0].turnInstruction = TurnInstructions.HeadOn; - pathDescription[0].necessary = true; - startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID; - // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length; - } - } else { - pathDescription[0].duration *= startPhantom.ratio; - } +// //Post-processing to remove empty or nearly empty path segments +// if(FLT_EPSILON > pathDescription.back().length) { +// // SimpleLogger().Write() << "#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length; +// if(pathDescription.size() > 2){ +// pathDescription.pop_back(); +// pathDescription.back().necessary = true; +// pathDescription.back().turnInstruction = TurnInstructions.NoTurn; +// targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; +// // SimpleLogger().Write() << "Deleting last turn instruction"; +// } +// } else { +// pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio); +// } +// if(FLT_EPSILON > pathDescription[0].length) { +// //TODO: this is never called actually? +// if(pathDescription.size() > 2) { +// pathDescription.erase(pathDescription.begin()); +// pathDescription[0].turnInstruction = TurnInstructions.HeadOn; +// pathDescription[0].necessary = true; +// startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID; +// // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length; +// } +// } else { +// pathDescription[0].duration *= startPhantom.ratio; +// } - //Generalize poly line - dp.Run(pathDescription, zoomLevel); +// //Generalize poly line +// dp.Run(pathDescription, zoomLevel); - //fix what needs to be fixed else - for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){ - if(pathDescription[i].necessary) { - double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location); - pathDescription[i].bearing = angle; - } - } +// //fix what needs to be fixed else +// for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){ +// if(pathDescription[i].necessary) { +// double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location); +// pathDescription[i].bearing = angle; +// } +// } -// BuildRouteSummary(entireLength, duration); - return; -} +// // BuildRouteSummary(entireLength, duration); +// return; +// } void DescriptionFactory::BuildRouteSummary(const double distance, const unsigned time) { summary.startName = startPhantom.nodeBasedEdgeNameID; diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 0fa3e5308..72ad486bf 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -51,12 +51,18 @@ class DescriptionFactory { double DegreeToRadian(const double degree) const; double RadianToDegree(const double degree) const; public: - struct _RouteSummary { + struct RouteSummary { std::string lengthString; std::string durationString; unsigned startName; unsigned destName; - _RouteSummary() : lengthString("0"), durationString("0"), startName(0), destName(0) {} + RouteSummary() : + lengthString("0"), + durationString("0"), + startName(0), + destName(0) + {} + void BuildDurationAndLengthStrings(const double distance, const unsigned time) { //compute distance/duration for route summary intToString(round(distance), lengthString); @@ -79,7 +85,129 @@ public: void SetStartSegment(const PhantomNode & startPhantom); void SetEndSegment(const PhantomNode & startPhantom); void AppendEncodedPolylineString(std::string & output, bool isEncoded); - void Run(const SearchEngine &sEngine, const unsigned zoomLevel); + + template + void Run(const DataFacadeT * facade, const unsigned zoomLevel) { + + if( pathDescription.empty() ) { + return; + } + + // unsigned entireLength = 0; + /** starts at index 1 */ + pathDescription[0].length = 0; + for(unsigned i = 1; i < pathDescription.size(); ++i) { + pathDescription[i].length = ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); + } + + double lengthOfSegment = 0; + unsigned durationOfSegment = 0; + unsigned indexOfSegmentBegin = 0; + + std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].nameID); + std::string string1; + + + /*Simplify turn instructions + Input : + 10. Turn left on B 36 for 20 km + 11. Continue on B 35; B 36 for 2 km + 12. Continue on B 36 for 13 km + + becomes: + 10. Turn left on B 36 for 35 km + */ + //TODO: rework to check only end and start of string. + // stl string is way to expensive + + // unsigned lastTurn = 0; + // for(unsigned i = 1; i < pathDescription.size(); ++i) { + // string1 = sEngine.GetEscapedNameForNameID(pathDescription[i].nameID); + // if(TurnInstructionsClass::GoStraight == pathDescription[i].turnInstruction) { + // if(std::string::npos != string0.find(string1+";") + // || std::string::npos != string0.find(";"+string1) + // || std::string::npos != string0.find(string1+" ;") + // || std::string::npos != string0.find("; "+string1) + // ){ + // SimpleLogger().Write() << "->next correct: " << string0 << " contains " << string1; + // for(; lastTurn != i; ++lastTurn) + // pathDescription[lastTurn].nameID = pathDescription[i].nameID; + // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; + // } else if(std::string::npos != string1.find(string0+";") + // || std::string::npos != string1.find(";"+string0) + // || std::string::npos != string1.find(string0+" ;") + // || std::string::npos != string1.find("; "+string0) + // ){ + // SimpleLogger().Write() << "->prev correct: " << string1 << " contains " << string0; + // pathDescription[i].nameID = pathDescription[i-1].nameID; + // pathDescription[i].turnInstruction = TurnInstructionsClass::NoTurn; + // } + // } + // if (TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { + // lastTurn = i; + // } + // string0 = string1; + // } + + + for(unsigned i = 1; i < pathDescription.size(); ++i) { + entireLength += pathDescription[i].length; + lengthOfSegment += pathDescription[i].length; + durationOfSegment += pathDescription[i].duration; + pathDescription[indexOfSegmentBegin].length = lengthOfSegment; + pathDescription[indexOfSegmentBegin].duration = durationOfSegment; + + + if(TurnInstructionsClass::NoTurn != pathDescription[i].turnInstruction) { + //SimpleLogger().Write() << "Turn after " << lengthOfSegment << "m into way with name id " << segment.nameID; + assert(pathDescription[i].necessary); + lengthOfSegment = 0; + durationOfSegment = 0; + indexOfSegmentBegin = i; + } + } + // SimpleLogger().Write() << "#segs: " << pathDescription.size(); + + //Post-processing to remove empty or nearly empty path segments + if(FLT_EPSILON > pathDescription.back().length) { + // SimpleLogger().Write() << "#segs: " << pathDescription.size() << ", last ratio: " << targetPhantom.ratio << ", length: " << pathDescription.back().length; + if(pathDescription.size() > 2){ + pathDescription.pop_back(); + pathDescription.back().necessary = true; + pathDescription.back().turnInstruction = TurnInstructions.NoTurn; + targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID; + // SimpleLogger().Write() << "Deleting last turn instruction"; + } + } else { + pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio); + } + if(FLT_EPSILON > pathDescription[0].length) { + //TODO: this is never called actually? + if(pathDescription.size() > 2) { + pathDescription.erase(pathDescription.begin()); + pathDescription[0].turnInstruction = TurnInstructions.HeadOn; + pathDescription[0].necessary = true; + startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID; + // SimpleLogger().Write() << "Deleting first turn instruction, ratio: " << startPhantom.ratio << ", length: " << pathDescription[0].length; + } + } else { + pathDescription[0].duration *= startPhantom.ratio; + } + + //Generalize poly line + dp.Run(pathDescription, zoomLevel); + + //fix what needs to be fixed else + for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){ + if(pathDescription[i].necessary) { + double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location); + pathDescription[i].bearing = angle; + } + } + + // BuildRouteSummary(entireLength, duration); + return; + } }; #endif /* DESCRIPTIONFACTORY_H_ */ diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index af1a47aad..69a0bb296 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -32,7 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -class GPXDescriptor : public BaseDescriptor{ +template +class GPXDescriptor : public BaseDescriptor { private: _DescriptorConfig config; FixedPointCoordinate current; @@ -40,34 +41,63 @@ private: std::string tmp; public: void SetConfig(const _DescriptorConfig& c) { config = c; } - void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngine &sEngine) { + + //TODO: reorder parameters + void Run( + http::Reply & reply, + const RawRouteData &rawRoute, + PhantomNodes &phantomNodes, + const DataFacadeT * facade + ) { reply.content += (""); - reply.content += ""; - reply.content += "Data (c) OpenStreetMap contributors (ODbL)"; + reply.content += + "Data (c)" + " OpenStreetMap contributors (ODbL)" + ""; reply.content += ""; - if(rawRoute.lengthOfShortestPath != INT_MAX && rawRoute.computedShortestPath.size()) { - convertInternalLatLonToString(phantomNodes.startPhantom.location.lat, tmp); + bool found_route = (rawRoute.lengthOfShortestPath != INT_MAX) && + (rawRoute.computedShortestPath.size() ); + if( found_route ) { + convertInternalLatLonToString( + phantomNodes.startPhantom.location.lat, + tmp + ); reply.content += ""; - BOOST_FOREACH(const _PathData & pathData, rawRoute.computedShortestPath) { - sEngine.GetCoordinatesForNodeID(pathData.node, current); + BOOST_FOREACH( + const _PathData & pathData, + rawRoute.computedShortestPath + ) { + current = facade->GetCoordinateOfNode(pathData.node); convertInternalLatLonToString(current.lat, tmp); reply.content += ""; } - convertInternalLatLonToString(phantomNodes.targetPhantom.location.lat, tmp); + convertInternalLatLonToString( + phantomNodes.targetPhantom.location.lat, + tmp + ); reply.content += ""; } reply.content += ""; } }; -#endif /* GPX_DESCRIPTOR_H_ */ +#endif // GPX_DESCRIPTOR_H_ diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index f89304f99..86d545b89 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -41,7 +41,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -class JSONDescriptor : public BaseDescriptor{ +template +class JSONDescriptor : public BaseDescriptor { private: _DescriptorConfig config; DescriptionFactory descriptionFactory; @@ -79,7 +80,12 @@ public: JSONDescriptor() : numberOfEnteredRestrictedAreas(0) {} void SetConfig(const _DescriptorConfig & c) { config = c; } - void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngine &sEngine) { + void Run( + http::Reply & reply, + const RawRouteData &rawRoute, + PhantomNodes &phantomNodes, + const DataFacadeT * facade + ) { WriteHeaderToOutput(reply.content); @@ -90,7 +96,7 @@ public: //Get all the coordinates for the computed route BOOST_FOREACH(const _PathData & pathData, rawRoute.computedShortestPath) { - sEngine.GetCoordinatesForNodeID(pathData.node, current); + current = facade->GetCoordinateOfNode(pathData.node); descriptionFactory.AppendSegment(current, pathData ); } descriptionFactory.SetEndSegment(phantomNodes.targetPhantom); @@ -100,7 +106,7 @@ public: "\"status_message\": \"Cannot find route between points\","; } - descriptionFactory.Run(sEngine, config.z); + descriptionFactory.Run(facade, config.z); reply.content += "\"route_geometry\": "; if(config.geometry) { descriptionFactory.AppendEncodedPolylineString(reply.content, config.encodeGeometry); @@ -112,7 +118,7 @@ public: "\"route_instructions\": ["; numberOfEnteredRestrictedAreas = 0; if(config.instructions) { - BuildTextualDescription(descriptionFactory, reply, rawRoute.lengthOfShortestPath, sEngine, shortestSegments); + BuildTextualDescription(descriptionFactory, reply, rawRoute.lengthOfShortestPath, facade, shortestSegments); } else { BOOST_FOREACH(const SegmentInformation & segment, descriptionFactory.pathDescription) { TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; @@ -131,10 +137,10 @@ public: reply.content += descriptionFactory.summary.durationString; reply.content += "," "\"start_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.startName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.startName); reply.content += "\"," "\"end_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.destName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.destName); reply.content += "\""; reply.content += "}"; reply.content +=","; @@ -145,12 +151,12 @@ public: alternateDescriptionFactory.SetStartSegment(phantomNodes.startPhantom); //Get all the coordinates for the computed route BOOST_FOREACH(const _PathData & pathData, rawRoute.computedAlternativePath) { - sEngine.GetCoordinatesForNodeID(pathData.node, current); + current = facade->GetCoordinateOfNode(pathData.node); alternateDescriptionFactory.AppendSegment(current, pathData ); } alternateDescriptionFactory.SetEndSegment(phantomNodes.targetPhantom); } - alternateDescriptionFactory.Run(sEngine, config.z); + alternateDescriptionFactory.Run(facade, config.z); //give an array of alternative routes reply.content += "\"alternative_geometries\": ["; @@ -165,7 +171,13 @@ public: reply.content += "["; //Generate instructions for each alternative if(config.instructions) { - BuildTextualDescription(alternateDescriptionFactory, reply, rawRoute.lengthOfAlternativePath, sEngine, alternativeSegments); + BuildTextualDescription( + alternateDescriptionFactory, + reply, + rawRoute.lengthOfAlternativePath, + facade, + alternativeSegments + ); } else { BOOST_FOREACH(const SegmentInformation & segment, alternateDescriptionFactory.pathDescription) { TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag; @@ -187,10 +199,10 @@ public: reply.content += alternateDescriptionFactory.summary.durationString; reply.content += "," "\"start_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.startName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.startName); reply.content += "\"," "\"end_point\":\""; - reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.destName); + reply.content += facade->GetEscapedNameForNameID(descriptionFactory.summary.destName); reply.content += "\""; reply.content += "}"; } @@ -198,7 +210,7 @@ public: //Get Names for both routes RouteNames routeNames; - GetRouteNames(shortestSegments, alternativeSegments, sEngine, routeNames); + GetRouteNames(shortestSegments, alternativeSegments, facade, routeNames); reply.content += "\"route_name\":[\""; reply.content += routeNames.shortestPathName1; @@ -257,8 +269,13 @@ public: reply.content += "}"; } - void GetRouteNames(std::vector & shortestSegments, std::vector & alternativeSegments, const SearchEngine &sEngine, RouteNames & routeNames) { - /*** extract names for both alternatives ***/ + // construct routes names + void GetRouteNames( + std::vector & shortestSegments, + std::vector & alternativeSegments, + const DataFacadeT * facade, + RouteNames & routeNames + ) { Segment shortestSegment1, shortestSegment2; Segment alternativeSegment1, alternativeSegment2; @@ -301,11 +318,19 @@ public: if(alternativeSegment1.position > alternativeSegment2.position) std::swap(alternativeSegment1, alternativeSegment2); - routeNames.shortestPathName1 = sEngine.GetEscapedNameForNameID(shortestSegment1.nameID); - routeNames.shortestPathName2 = sEngine.GetEscapedNameForNameID(shortestSegment2.nameID); + routeNames.shortestPathName1 = facade->GetEscapedNameForNameID( + shortestSegment1.nameID + ); + routeNames.shortestPathName2 = facade->GetEscapedNameForNameID( + shortestSegment2.nameID + ); - routeNames.alternativePathName1 = sEngine.GetEscapedNameForNameID(alternativeSegment1.nameID); - routeNames.alternativePathName2 = sEngine.GetEscapedNameForNameID(alternativeSegment2.nameID); + routeNames.alternativePathName1 = facade->GetEscapedNameForNameID( + alternativeSegment1.nameID + ); + routeNames.alternativePathName2 = facade->GetEscapedNameForNameID( + alternativeSegment2.nameID + ); } } @@ -315,7 +340,14 @@ public: "\"status\":"; } - inline void BuildTextualDescription(DescriptionFactory & descriptionFactory, http::Reply & reply, const int lengthOfRoute, const SearchEngine &sEngine, std::vector & segmentVector) { + //TODO: reorder parameters + inline void BuildTextualDescription( + DescriptionFactory & descriptionFactory, + http::Reply & reply, + const int lengthOfRoute, + const DataFacadeT * facade, + std::vector & segmentVector + ) { //Segment information has following format: //["instruction","streetname",length,position,time,"length","earth_direction",azimuth] //Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5] @@ -351,7 +383,7 @@ public: reply.content += "\",\""; - reply.content += sEngine.GetEscapedNameForNameID(segment.nameID); + reply.content += facade->GetEscapedNameForNameID(segment.nameID); reply.content += "\","; intToString(segment.length, tmpDist); reply.content += tmpDist;