From 9587923e5506097c67bee1cea063c3ffac1506cb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 8 May 2014 11:15:19 +0200 Subject: [PATCH] make variable names consistent, migrate Plugins --- DataStructures/RouteParameters.cpp | 38 +++++++------- Include/osrm/RouteParameters.h | 34 ++++++------- Plugins/HelloWorldPlugin.h | 80 +++++++++++++++--------------- Plugins/LocatePlugin.h | 39 ++++++++------- Plugins/NearestPlugin.h | 38 +++++++------- Plugins/TimestampPlugin.h | 26 +++++----- Plugins/ViaRoutePlugin.h | 27 +++++----- Tools/simpleclient.cpp | 10 ++-- 8 files changed, 147 insertions(+), 145 deletions(-) diff --git a/DataStructures/RouteParameters.cpp b/DataStructures/RouteParameters.cpp index 2a4baa57d..406b227c0 100644 --- a/DataStructures/RouteParameters.cpp +++ b/DataStructures/RouteParameters.cpp @@ -32,51 +32,51 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include RouteParameters::RouteParameters() - : zoomLevel(18), printInstructions(false), alternateRoute(true), geometry(true), + : zoom_level(18), print_instructions(false), alternate_route(true), geometry(true), compression(true), deprecatedAPI(false), check_sum(-1) { } -void RouteParameters::setZoomLevel(const short i) +void RouteParameters::setZoomLevel(const short level) { - if (18 >= i && 0 <= i) + if (18 >= level && 0 <= level) { - zoomLevel = i; + zoom_level = level; } } -void RouteParameters::setAlternateRouteFlag(const bool b) { alternateRoute = b; } +void RouteParameters::setAlternateRouteFlag(const bool flag) { alternate_route = flag; } void RouteParameters::setDeprecatedAPIFlag(const std::string &) { deprecatedAPI = true; } -void RouteParameters::setChecksum(const unsigned c) { check_sum = c; } +void RouteParameters::setChecksum(const unsigned sum) { check_sum = sum; } -void RouteParameters::setInstructionFlag(const bool b) { printInstructions = b; } +void RouteParameters::setInstructionFlag(const bool flag) { print_instructions = flag; } -void RouteParameters::setService(const std::string &s) { service = s; } +void RouteParameters::setService(const std::string &service_string) { service = service_string; } -void RouteParameters::setOutputFormat(const std::string &s) { outputFormat = s; } +void RouteParameters::setOutputFormat(const std::string &format) { output_format = format; } -void RouteParameters::setJSONpParameter(const std::string &s) { jsonpParameter = s; } +void RouteParameters::setJSONpParameter(const std::string ¶meter) { jsonp_parameter = parameter; } -void RouteParameters::addHint(const std::string &s) +void RouteParameters::addHint(const std::string &hint) { hints.resize(coordinates.size()); if (!hints.empty()) { - hints.back() = s; + hints.back() = hint; } } -void RouteParameters::setLanguage(const std::string &s) { language = s; } +void RouteParameters::setLanguage(const std::string &language_string) { language = language_string; } -void RouteParameters::setGeometryFlag(const bool b) { geometry = b; } +void RouteParameters::setGeometryFlag(const bool flag) { geometry = flag; } -void RouteParameters::setCompressionFlag(const bool b) { compression = b; } +void RouteParameters::setCompressionFlag(const bool flag) { compression = flag; } -void RouteParameters::addCoordinate(const boost::fusion::vector &arg_) +void RouteParameters::addCoordinate(const boost::fusion::vector &transmitted_coordinates) { - int lat = COORDINATE_PRECISION * boost::fusion::at_c<0>(arg_); - int lon = COORDINATE_PRECISION * boost::fusion::at_c<1>(arg_); - coordinates.push_back(FixedPointCoordinate(lat, lon)); + int lat = COORDINATE_PRECISION * boost::fusion::at_c<0>(transmitted_coordinates); + int lon = COORDINATE_PRECISION * boost::fusion::at_c<1>(transmitted_coordinates); + coordinates.emplace_back(lat, lon); } diff --git a/Include/osrm/RouteParameters.h b/Include/osrm/RouteParameters.h index a5792d238..89a177405 100644 --- a/Include/osrm/RouteParameters.h +++ b/Include/osrm/RouteParameters.h @@ -39,42 +39,42 @@ struct RouteParameters { RouteParameters(); - void setZoomLevel(const short i); + void setZoomLevel(const short level); - void setAlternateRouteFlag(const bool b); + void setAlternateRouteFlag(const bool flag); void setDeprecatedAPIFlag(const std::string &); - void setChecksum(const unsigned c); + void setChecksum(const unsigned check_sum); - void setInstructionFlag(const bool b); + void setInstructionFlag(const bool flag); - void setService(const std::string &s); + void setService(const std::string &service); - void setOutputFormat(const std::string &s); + void setOutputFormat(const std::string &format); - void setJSONpParameter(const std::string &s); + void setJSONpParameter(const std::string ¶meter); - void addHint(const std::string &s); + void addHint(const std::string &hint); - void setLanguage(const std::string &s); + void setLanguage(const std::string &language); - void setGeometryFlag(const bool b); + void setGeometryFlag(const bool flag); - void setCompressionFlag(const bool b); + void setCompressionFlag(const bool flag); - void addCoordinate(const boost::fusion::vector &arg_); + void addCoordinate(const boost::fusion::vector &coordinates); - short zoomLevel; - bool printInstructions; - bool alternateRoute; + short zoom_level; + bool print_instructions; + bool alternate_route; bool geometry; bool compression; bool deprecatedAPI; unsigned check_sum; std::string service; - std::string outputFormat; - std::string jsonpParameter; + std::string output_format; + std::string jsonp_parameter; std::string language; std::vector hints; std::vector coordinates; diff --git a/Plugins/HelloWorldPlugin.h b/Plugins/HelloWorldPlugin.h index 0a490c4da..448bd272f 100644 --- a/Plugins/HelloWorldPlugin.h +++ b/Plugins/HelloWorldPlugin.h @@ -46,66 +46,66 @@ class HelloWorldPlugin : public BasePlugin void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply) { reply.status = http::Reply::ok; - reply.content.push_back("Hello World Demonstration " - "Document

Hello, World!

"); - reply.content.push_back("
");
-        reply.content.push_back("zoom level: ");
-        intToString(routeParameters.zoomLevel, temp_string);
-        reply.content.push_back(temp_string);
-        reply.content.push_back("\nchecksum: ");
+        reply.content.emplace_back("Hello World Demonstration "
+                                   "Document

Hello, World!

"); + reply.content.emplace_back("
");
+        reply.content.emplace_back("zoom level: ");
+        intToString(routeParameters.zoom_level, temp_string);
+        reply.content.emplace_back(temp_string);
+        reply.content.emplace_back("\nchecksum: ");
         intToString(routeParameters.check_sum, temp_string);
-        reply.content.push_back(temp_string);
-        reply.content.push_back("\ninstructions: ");
-        reply.content.push_back((routeParameters.printInstructions ? "yes" : "no"));
-        reply.content.push_back(temp_string);
-        reply.content.push_back("\ngeometry: ");
-        reply.content.push_back((routeParameters.geometry ? "yes" : "no"));
-        reply.content.push_back("\ncompression: ");
-        reply.content.push_back((routeParameters.compression ? "yes" : "no"));
-        reply.content.push_back("\noutput format: ");
-        reply.content.push_back(routeParameters.outputFormat);
-        reply.content.push_back("\njson parameter: ");
-        reply.content.push_back(routeParameters.jsonpParameter);
-        reply.content.push_back("\nlanguage: ");
-        reply.content.push_back(routeParameters.language);
-        reply.content.push_back("\nNumber of locations: ");
+        reply.content.emplace_back(temp_string);
+        reply.content.emplace_back("\ninstructions: ");
+        reply.content.emplace_back((routeParameters.print_instructions ? "yes" : "no"));
+        reply.content.emplace_back(temp_string);
+        reply.content.emplace_back("\ngeometry: ");
+        reply.content.emplace_back((routeParameters.geometry ? "yes" : "no"));
+        reply.content.emplace_back("\ncompression: ");
+        reply.content.emplace_back((routeParameters.compression ? "yes" : "no"));
+        reply.content.emplace_back("\noutput format: ");
+        reply.content.emplace_back(routeParameters.output_format);
+        reply.content.emplace_back("\njson parameter: ");
+        reply.content.emplace_back(routeParameters.jsonp_parameter);
+        reply.content.emplace_back("\nlanguage: ");
+        reply.content.emplace_back(routeParameters.language);
+        reply.content.emplace_back("\nNumber of locations: ");
         intToString(routeParameters.coordinates.size(), temp_string);
-        reply.content.push_back(temp_string);
-        reply.content.push_back("\n");
+        reply.content.emplace_back(temp_string);
+        reply.content.emplace_back("\n");
 
         unsigned counter = 0;
         for (const FixedPointCoordinate &coordinate : routeParameters.coordinates)
         {
-            reply.content.push_back("  [");
+            reply.content.emplace_back("  [");
             intToString(counter, temp_string);
-            reply.content.push_back(temp_string);
-            reply.content.push_back("] ");
+            reply.content.emplace_back(temp_string);
+            reply.content.emplace_back("] ");
             doubleToString(coordinate.lat / COORDINATE_PRECISION, temp_string);
-            reply.content.push_back(temp_string);
-            reply.content.push_back(",");
+            reply.content.emplace_back(temp_string);
+            reply.content.emplace_back(",");
             doubleToString(coordinate.lon / COORDINATE_PRECISION, temp_string);
-            reply.content.push_back(temp_string);
-            reply.content.push_back("\n");
+            reply.content.emplace_back(temp_string);
+            reply.content.emplace_back("\n");
             ++counter;
         }
 
-        reply.content.push_back("Number of hints: ");
+        reply.content.emplace_back("Number of hints: ");
         intToString(routeParameters.hints.size(), temp_string);
-        reply.content.push_back(temp_string);
-        reply.content.push_back("\n");
+        reply.content.emplace_back(temp_string);
+        reply.content.emplace_back("\n");
 
         counter = 0;
         for (const std::string ¤t_string : routeParameters.hints)
         {
-            reply.content.push_back("  [");
+            reply.content.emplace_back("  [");
             intToString(counter, temp_string);
-            reply.content.push_back(temp_string);
-            reply.content.push_back("] ");
-            reply.content.push_back(current_string);
-            reply.content.push_back("\n");
+            reply.content.emplace_back(temp_string);
+            reply.content.emplace_back("] ");
+            reply.content.emplace_back(current_string);
+            reply.content.emplace_back("\n");
             ++counter;
         }
-        reply.content.push_back("
"); + reply.content.emplace_back("
"); } private: diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 2e2bef0d4..8ff2a459d 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -39,10 +39,10 @@ template class LocatePlugin : public BasePlugin explicit LocatePlugin(DataFacadeT *facade) : descriptor_string("locate"), facade(facade) {} const std::string GetDescriptor() const { return descriptor_string; } - void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply) + void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply) { // check number of parameters - if (routeParameters.coordinates.empty() || !routeParameters.coordinates.front().isValid()) + if (route_parameters.coordinates.empty() || !route_parameters.coordinates.front().isValid()) { reply = http::Reply::StockReply(http::Reply::badRequest); return; @@ -53,37 +53,38 @@ template class LocatePlugin : public BasePlugin std::string tmp; // json - if (!routeParameters.jsonpParameter.empty()) + if (!route_parameters.jsonp_parameter.empty()) { - reply.content.push_back(routeParameters.jsonpParameter); - reply.content.push_back("("); + reply.content.emplace_back(route_parameters.jsonp_parameter); + reply.content.emplace_back("("); } reply.status = http::Reply::ok; - reply.content.push_back("{"); - if (!facade->LocateClosestEndPointForCoordinate(routeParameters.coordinates.front(), result)) + reply.content.emplace_back("{"); + if (!facade->LocateClosestEndPointForCoordinate(route_parameters.coordinates.front(), + result)) { - reply.content.push_back("\"status\":207,"); - reply.content.push_back("\"mapped_coordinate\":[]"); + reply.content.emplace_back("\"status\":207,"); + reply.content.emplace_back("\"mapped_coordinate\":[]"); } else { // Write coordinate to stream reply.status = http::Reply::ok; - reply.content.push_back("\"status\":0,"); - reply.content.push_back("\"mapped_coordinate\":"); + reply.content.emplace_back("\"status\":0,"); + reply.content.emplace_back("\"mapped_coordinate\":"); FixedPointCoordinate::convertInternalLatLonToString(result.lat, tmp); - reply.content.push_back("["); - reply.content.push_back(tmp); + reply.content.emplace_back("["); + reply.content.emplace_back(tmp); FixedPointCoordinate::convertInternalLatLonToString(result.lon, tmp); - reply.content.push_back(","); - reply.content.push_back(tmp); - reply.content.push_back("]"); + reply.content.emplace_back(","); + reply.content.emplace_back(tmp); + reply.content.emplace_back("]"); } - reply.content.push_back("}"); + reply.content.emplace_back("}"); reply.headers.resize(3); - if (!routeParameters.jsonpParameter.empty()) + if (!route_parameters.jsonp_parameter.empty()) { - reply.content.push_back(")"); + reply.content.emplace_back(")"); reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; reply.headers[2].name = "Content-Disposition"; diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index ad827c359..82ded9c2f 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -49,15 +49,15 @@ template class NearestPlugin : public BasePlugin const std::string GetDescriptor() const { return descriptor_string; } - void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply) + void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply) { // check number of parameters - if (routeParameters.coordinates.empty()) + if (route_parameters.coordinates.empty()) { reply = http::Reply::StockReply(http::Reply::badRequest); return; } - if (!routeParameters.coordinates.front().isValid()) + if (!route_parameters.coordinates.front().isValid()) { reply = http::Reply::StockReply(http::Reply::badRequest); return; @@ -65,48 +65,48 @@ template class NearestPlugin : public BasePlugin PhantomNode result; facade->FindPhantomNodeForCoordinate( - routeParameters.coordinates.front(), result, routeParameters.zoomLevel); + route_parameters.coordinates.front(), result, route_parameters.zoom_level); // json - if (!routeParameters.jsonpParameter.empty()) + if (!route_parameters.jsonp_parameter.empty()) { - reply.content.push_back(routeParameters.jsonpParameter); - reply.content.push_back("("); + reply.content.emplace_back(route_parameters.jsonp_parameter); + reply.content.emplace_back("("); } reply.status = http::Reply::ok; - reply.content.push_back("{\"status\":"); + reply.content.emplace_back("{\"status\":"); if (SPECIAL_NODEID != result.forward_node_id) { - reply.content.push_back("0,"); + reply.content.emplace_back("0,"); } else { - reply.content.push_back("207,"); + reply.content.emplace_back("207,"); } - reply.content.push_back("\"mapped_coordinate\":["); + reply.content.emplace_back("\"mapped_coordinate\":["); std::string temp_string; if (SPECIAL_NODEID != result.forward_node_id) { FixedPointCoordinate::convertInternalLatLonToString(result.location.lat, temp_string); - reply.content.push_back(temp_string); + reply.content.emplace_back(temp_string); FixedPointCoordinate::convertInternalLatLonToString(result.location.lon, temp_string); - reply.content.push_back(","); - reply.content.push_back(temp_string); + reply.content.emplace_back(","); + reply.content.emplace_back(temp_string); } - reply.content.push_back("],\"name\":\""); + reply.content.emplace_back("],\"name\":\""); if (SPECIAL_NODEID != result.forward_node_id) { facade->GetName(result.name_id, temp_string); - reply.content.push_back(temp_string); + reply.content.emplace_back(temp_string); } - reply.content.push_back("\"}"); + reply.content.emplace_back("\"}"); reply.headers.resize(3); - if (!routeParameters.jsonpParameter.empty()) + if (!route_parameters.jsonp_parameter.empty()) { - reply.content.push_back(")"); + reply.content.emplace_back(")"); reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; reply.headers[2].name = "Content-Disposition"; diff --git a/Plugins/TimestampPlugin.h b/Plugins/TimestampPlugin.h index 62ff81637..3fb290ee0 100644 --- a/Plugins/TimestampPlugin.h +++ b/Plugins/TimestampPlugin.h @@ -38,29 +38,29 @@ template class TimestampPlugin : public BasePlugin { } const std::string GetDescriptor() const { return descriptor_string; } - void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply) + void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply) { std::string tmp; // json - if (!routeParameters.jsonpParameter.empty()) + if (!route_parameters.jsonp_parameter.empty()) { - reply.content.push_back(routeParameters.jsonpParameter); - reply.content.push_back("("); + reply.content.emplace_back(route_parameters.jsonp_parameter); + reply.content.emplace_back("("); } reply.status = http::Reply::ok; - reply.content.push_back("{"); - reply.content.push_back("\"status\":"); - reply.content.push_back("0,"); - reply.content.push_back("\"timestamp\":\""); - reply.content.push_back(facade->GetTimestamp()); - reply.content.push_back("\""); - reply.content.push_back("}"); + reply.content.emplace_back("{"); + reply.content.emplace_back("\"status\":"); + reply.content.emplace_back("0,"); + reply.content.emplace_back("\"timestamp\":\""); + reply.content.emplace_back(facade->GetTimestamp()); + reply.content.emplace_back("\""); + reply.content.emplace_back("}"); reply.headers.resize(3); - if (!routeParameters.jsonpParameter.empty()) + if (!route_parameters.jsonp_parameter.empty()) { - reply.content.push_back(")"); + reply.content.emplace_back(")"); reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; reply.headers[2].name = "Content-Disposition"; diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index c954724eb..a4fb38141 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -108,7 +108,7 @@ template class ViaRoutePlugin : public BasePlugin } facade->FindPhantomNodeForCoordinate(raw_route.raw_via_node_coordinates[i], phantom_node_vector[i], - routeParameters.zoomLevel); + routeParameters.zoom_level); } PhantomNodes current_phantom_node_pair; @@ -119,9 +119,10 @@ template class ViaRoutePlugin : public BasePlugin raw_route.segment_end_coordinates.emplace_back(current_phantom_node_pair); } - if ((routeParameters.alternateRoute) && (1 == raw_route.segment_end_coordinates.size())) + if ((routeParameters.alternate_route) && (1 == raw_route.segment_end_coordinates.size())) { - search_engine_ptr->alternative_path(raw_route.segment_end_coordinates.front(), raw_route); + search_engine_ptr->alternative_path(raw_route.segment_end_coordinates.front(), + raw_route); } else { @@ -134,19 +135,19 @@ template class ViaRoutePlugin : public BasePlugin } reply.status = http::Reply::ok; - if (!routeParameters.jsonpParameter.empty()) + if (!routeParameters.jsonp_parameter.empty()) { - reply.content.push_back(routeParameters.jsonpParameter); - reply.content.push_back("("); + reply.content.emplace_back(routeParameters.jsonp_parameter); + reply.content.emplace_back("("); } DescriptorConfig descriptor_config; - auto iter = descriptorTable.find(routeParameters.outputFormat); + auto iter = descriptorTable.find(routeParameters.output_format); unsigned descriptor_type = (iter != descriptorTable.end() ? iter->second : 0); - descriptor_config.zoom_level = routeParameters.zoomLevel; - descriptor_config.instructions = routeParameters.printInstructions; + descriptor_config.zoom_level = routeParameters.zoom_level; + descriptor_config.instructions = routeParameters.print_instructions; descriptor_config.geometry = routeParameters.geometry; descriptor_config.encode_geometry = routeParameters.compression; @@ -170,9 +171,9 @@ template class ViaRoutePlugin : public BasePlugin descriptor->SetConfig(descriptor_config); descriptor->Run(raw_route, phantom_nodes, facade, reply); - if (!routeParameters.jsonpParameter.empty()) + if (!routeParameters.jsonp_parameter.empty()) { - reply.content.push_back(")\n"); + reply.content.emplace_back(")\n"); } reply.headers.resize(3); reply.headers[0].name = "Content-Length"; @@ -189,7 +190,7 @@ template class ViaRoutePlugin : public BasePlugin switch (descriptor_type) { case 0: - if (!routeParameters.jsonpParameter.empty()) + if (!routeParameters.jsonp_parameter.empty()) { reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; @@ -213,7 +214,7 @@ template class ViaRoutePlugin : public BasePlugin break; default: - if (!routeParameters.jsonpParameter.empty()) + if (!routeParameters.jsonp_parameter.empty()) { reply.headers[1].name = "Content-Type"; reply.headers[1].value = "text/javascript"; diff --git a/Tools/simpleclient.cpp b/Tools/simpleclient.cpp index e50baf758..cab5a3bbd 100644 --- a/Tools/simpleclient.cpp +++ b/Tools/simpleclient.cpp @@ -86,15 +86,15 @@ int main (int argc, const char * argv[]) { OSRM routing_machine( server_paths, use_shared_memory ); RouteParameters route_parameters; - route_parameters.zoomLevel = 18; //no generalization - route_parameters.printInstructions = true; //turn by turn instructions - route_parameters.alternateRoute = true; //get an alternate route, too + route_parameters.zoom_level = 18; //no generalization + route_parameters.print_instructions = true; //turn by turn instructions + route_parameters.alternate_route = true; //get an alternate route, too route_parameters.geometry = true; //retrieve geometry of route route_parameters.compression = true; //polyline encoding route_parameters.check_sum = UINT_MAX; //see wiki route_parameters.service = "viaroute"; //that's routing - route_parameters.outputFormat = "json"; - route_parameters.jsonpParameter = ""; //set for jsonp wrapping + route_parameters.output_format = "json"; + route_parameters.jsonp_parameter = ""; //set for jsonp wrapping route_parameters.language = ""; //unused atm //route_parameters.hints.push_back(); // see wiki, saves I/O if done properly