migrate plugins directory to C++11

This commit is contained in:
Dennis Luxen 2014-05-02 18:06:31 +02:00
parent 6c2c48a611
commit 946bfb9a26
6 changed files with 239 additions and 215 deletions

View File

@ -34,30 +34,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/Reply.h> #include <osrm/Reply.h>
#include <osrm/RouteParameters.h> #include <osrm/RouteParameters.h>
#include <boost/foreach.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
class BasePlugin { class BasePlugin
public: {
BasePlugin() { } public:
//Maybe someone can explain the pure virtual destructor thing to me (dennis) BasePlugin() {}
virtual ~BasePlugin() { } // Maybe someone can explain the pure virtual destructor thing to me (dennis)
virtual const std::string & GetDescriptor() const = 0; virtual ~BasePlugin() {}
virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0; virtual const std::string GetDescriptor() const = 0;
virtual void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply) = 0;
inline bool checkCoord(const FixedPointCoordinate & c) {
if(
c.lat > 90*COORDINATE_PRECISION ||
c.lat < -90*COORDINATE_PRECISION ||
c.lon > 180*COORDINATE_PRECISION ||
c.lon < -180*COORDINATE_PRECISION
) {
return false;
}
return true;
}
}; };
#endif /* BASEPLUGIN_H_ */ #endif /* BASEPLUGIN_H_ */

View File

@ -33,17 +33,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
class HelloWorldPlugin : public BasePlugin { class HelloWorldPlugin : public BasePlugin
{
private: private:
std::string temp_string; std::string temp_string;
public:
HelloWorldPlugin() : descriptor_string("hello"){}
virtual ~HelloWorldPlugin() { }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { public:
HelloWorldPlugin() : descriptor_string("hello") {}
virtual ~HelloWorldPlugin() {}
const std::string GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
{
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
reply.content.push_back("<html><head><title>Hello World Demonstration Document</title></head><body><h1>Hello, World!</h1>"); reply.content.push_back("<html><head><title>Hello World Demonstration "
"Document</title></head><body><h1>Hello, World!</h1>");
reply.content.push_back("<pre>"); reply.content.push_back("<pre>");
reply.content.push_back("zoom level: "); reply.content.push_back("zoom level: ");
intToString(routeParameters.zoomLevel, temp_string); intToString(routeParameters.zoomLevel, temp_string);
@ -68,33 +72,43 @@ public:
intToString(routeParameters.coordinates.size(), temp_string); intToString(routeParameters.coordinates.size(), temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
reply.content.push_back("\n"); reply.content.push_back("\n");
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) {
reply.content.push_back( " ["); unsigned counter = 0;
intToString(i, temp_string); for (const FixedPointCoordinate &coordinate : routeParameters.coordinates)
{
reply.content.push_back(" [");
intToString(counter, temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
reply.content.push_back("] "); reply.content.push_back("] ");
doubleToString(routeParameters.coordinates[i].lat/COORDINATE_PRECISION, temp_string); doubleToString(coordinate.lat / COORDINATE_PRECISION, temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
reply.content.push_back(","); reply.content.push_back(",");
doubleToString(routeParameters.coordinates[i].lon/COORDINATE_PRECISION, temp_string); doubleToString(coordinate.lon / COORDINATE_PRECISION, temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
reply.content.push_back("\n"); reply.content.push_back("\n");
++counter;
} }
reply.content.push_back( "Number of hints: ");
reply.content.push_back("Number of hints: ");
intToString(routeParameters.hints.size(), temp_string); intToString(routeParameters.hints.size(), temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
reply.content.push_back("\n"); reply.content.push_back("\n");
for(unsigned i = 0; i < routeParameters.hints.size(); ++i) {
reply.content.push_back( " ["); counter = 0;
intToString(i, temp_string); for (const std::string &current_string : routeParameters.hints)
{
reply.content.push_back(" [");
intToString(counter, temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
reply.content.push_back("] "); reply.content.push_back("] ");
reply.content.push_back(routeParameters.hints[i]); reply.content.push_back(current_string);
reply.content.push_back("\n"); reply.content.push_back("\n");
++counter;
} }
reply.content.push_back( "</pre></body></html>"); reply.content.push_back("</pre></body></html>");
} }
private:
private:
std::string descriptor_string; std::string descriptor_string;
}; };

View File

@ -25,62 +25,52 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef LOCATEPLUGIN_H_ #ifndef LOCATE_PLUGIN_H
#define LOCATEPLUGIN_H_ #define LOCATE_PLUGIN_H
#include "BasePlugin.h" #include "BasePlugin.h"
#include "../Util/StringUtil.h" #include "../Util/StringUtil.h"
//locates the nearest node in the road network for a given coordinate. // locates the nearest node in the road network for a given coordinate.
template<class DataFacadeT> template <class DataFacadeT> class LocatePlugin : public BasePlugin
class LocatePlugin : public BasePlugin { {
public: public:
explicit LocatePlugin(DataFacadeT * facade) explicit LocatePlugin(DataFacadeT *facade) : descriptor_string("locate"), facade(facade) {}
: const std::string GetDescriptor() const { return descriptor_string; }
descriptor_string("locate"),
facade(facade)
{ }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest( void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
const RouteParameters & routeParameters, {
http::Reply& reply // check number of parameters
) { if (routeParameters.coordinates.empty() || !routeParameters.coordinates.front().isValid())
//check number of parameters {
if(!routeParameters.coordinates.size()) {
reply = http::Reply::StockReply(http::Reply::badRequest);
return;
}
if(false == checkCoord(routeParameters.coordinates[0])) {
reply = http::Reply::StockReply(http::Reply::badRequest); reply = http::Reply::StockReply(http::Reply::badRequest);
return; return;
} }
//query to helpdesk // query to helpdesk
FixedPointCoordinate result; FixedPointCoordinate result;
std::string tmp; std::string tmp;
//json // json
if(!routeParameters.jsonpParameter.empty()) { if (!routeParameters.jsonpParameter.empty())
{
reply.content.push_back(routeParameters.jsonpParameter); reply.content.push_back(routeParameters.jsonpParameter);
reply.content.push_back("("); reply.content.push_back("(");
} }
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
reply.content.push_back ("{"); reply.content.push_back("{");
if( if (!facade->LocateClosestEndPointForCoordinate(routeParameters.coordinates.front(), result))
!facade->LocateClosestEndPointForCoordinate( {
routeParameters.coordinates[0], reply.content.push_back("\"status\":207,");
result reply.content.push_back("\"mapped_coordinate\":[]");
) }
) { else
reply.content.push_back ("\"status\":207,"); {
reply.content.push_back ("\"mapped_coordinate\":[]"); // Write coordinate to stream
} else {
//Write coordinate to stream
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
reply.content.push_back ("\"status\":0,"); reply.content.push_back("\"status\":0,");
reply.content.push_back ("\"mapped_coordinate\":"); reply.content.push_back("\"mapped_coordinate\":");
FixedPointCoordinate::convertInternalLatLonToString(result.lat, tmp); FixedPointCoordinate::convertInternalLatLonToString(result.lat, tmp);
reply.content.push_back("["); reply.content.push_back("[");
reply.content.push_back(tmp); reply.content.push_back(tmp);
@ -91,13 +81,16 @@ public:
} }
reply.content.push_back("}"); reply.content.push_back("}");
reply.headers.resize(3); reply.headers.resize(3);
if(!routeParameters.jsonpParameter.empty()) { if (!routeParameters.jsonpParameter.empty())
reply.content.push_back( ")"); {
reply.content.push_back(")");
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "text/javascript"; reply.headers[1].value = "text/javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"location.js\""; reply.headers[2].value = "attachment; filename=\"location.js\"";
} else { }
else
{
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "application/x-javascript"; reply.headers[1].value = "application/x-javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
@ -105,7 +98,8 @@ public:
} }
reply.headers[0].name = "Content-Length"; reply.headers[0].name = "Content-Length";
unsigned content_length = 0; unsigned content_length = 0;
BOOST_FOREACH(const std::string & snippet, reply.content) { for (const std::string &snippet : reply.content)
{
content_length += snippet.length(); content_length += snippet.length();
} }
intToString(content_length, tmp); intToString(content_length, tmp);
@ -113,9 +107,9 @@ public:
return; return;
} }
private: private:
std::string descriptor_string; std::string descriptor_string;
DataFacadeT * facade; DataFacadeT *facade;
}; };
#endif /* LOCATEPLUGIN_H_ */ #endif /* LOCATE_PLUGIN_H */

View File

@ -32,62 +32,64 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../DataStructures/PhantomNodes.h" #include "../DataStructures/PhantomNodes.h"
#include "../Util/StringUtil.h" #include "../Util/StringUtil.h"
#include <boost/unordered_map.hpp> #include <unordered_map>
/* /*
* This Plugin locates the nearest point on a street in the road network for a given coordinate. * This Plugin locates the nearest point on a street in the road network for a given coordinate.
*/ */
template<class DataFacadeT> template <class DataFacadeT> class NearestPlugin : public BasePlugin
class NearestPlugin : public BasePlugin { {
public: public:
explicit NearestPlugin(DataFacadeT * facade ) explicit NearestPlugin(DataFacadeT *facade) : facade(facade), descriptor_string("nearest")
:
facade(facade),
descriptor_string("nearest")
{ {
descriptorTable.emplace("", 0); //default descriptor descriptor_table.emplace("", 0); // default descriptor
descriptorTable.emplace("json", 1); descriptor_table.emplace("json", 1);
} }
const std::string & GetDescriptor() const { return descriptor_string; }
void HandleRequest( const std::string GetDescriptor() const { return descriptor_string; }
const RouteParameters & routeParameters,
http::Reply & reply void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
) { {
//check number of parameters // check number of parameters
if(!routeParameters.coordinates.size()) { if (routeParameters.coordinates.empty())
{
reply = http::Reply::StockReply(http::Reply::badRequest); reply = http::Reply::StockReply(http::Reply::badRequest);
return; return;
} }
if( !checkCoord(routeParameters.coordinates[0]) ) { if (!routeParameters.coordinates.front().isValid())
{
reply = http::Reply::StockReply(http::Reply::badRequest); reply = http::Reply::StockReply(http::Reply::badRequest);
return; return;
} }
PhantomNode result; PhantomNode result;
facade->FindPhantomNodeForCoordinate( facade->FindPhantomNodeForCoordinate(
routeParameters.coordinates[0], routeParameters.coordinates.front(), result, routeParameters.zoomLevel);
result,
routeParameters.zoomLevel
);
std::string temp_string; // json
//json
if("" != routeParameters.jsonpParameter) { if (!routeParameters.jsonpParameter.empty())
{
reply.content.push_back(routeParameters.jsonpParameter); reply.content.push_back(routeParameters.jsonpParameter);
reply.content.push_back("("); reply.content.push_back("(");
} }
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
reply.content.push_back("{\"status\":"); reply.content.push_back("{\"status\":");
if(UINT_MAX != result.forward_node_id) { if (SPECIAL_NODEID != result.forward_node_id)
{
reply.content.push_back("0,"); reply.content.push_back("0,");
} else { }
else
{
reply.content.push_back("207,"); reply.content.push_back("207,");
} }
reply.content.push_back("\"mapped_coordinate\":["); reply.content.push_back("\"mapped_coordinate\":[");
if(UINT_MAX != result.forward_node_id) { std::string temp_string;
if (SPECIAL_NODEID != result.forward_node_id)
{
FixedPointCoordinate::convertInternalLatLonToString(result.location.lat, temp_string); FixedPointCoordinate::convertInternalLatLonToString(result.location.lat, temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
FixedPointCoordinate::convertInternalLatLonToString(result.location.lon, temp_string); FixedPointCoordinate::convertInternalLatLonToString(result.location.lon, temp_string);
@ -95,19 +97,23 @@ public:
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
} }
reply.content.push_back("],\"name\":\""); reply.content.push_back("],\"name\":\"");
if(UINT_MAX != result.forward_node_id) { if (SPECIAL_NODEID != result.forward_node_id)
{
facade->GetName(result.name_id, temp_string); facade->GetName(result.name_id, temp_string);
reply.content.push_back(temp_string); reply.content.push_back(temp_string);
} }
reply.content.push_back("\"}"); reply.content.push_back("\"}");
reply.headers.resize(3); reply.headers.resize(3);
if( !routeParameters.jsonpParameter.empty() ) { if (!routeParameters.jsonpParameter.empty())
{
reply.content.push_back(")"); reply.content.push_back(")");
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "text/javascript"; reply.headers[1].value = "text/javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"location.js\""; reply.headers[2].value = "attachment; filename=\"location.js\"";
} else { }
else
{
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "application/x-javascript"; reply.headers[1].value = "application/x-javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
@ -115,16 +121,17 @@ public:
} }
reply.headers[0].name = "Content-Length"; reply.headers[0].name = "Content-Length";
unsigned content_length = 0; unsigned content_length = 0;
BOOST_FOREACH(const std::string & snippet, reply.content) { for (const std::string &snippet : reply.content)
{
content_length += snippet.length(); content_length += snippet.length();
} }
intToString(content_length, temp_string); intToString(content_length, temp_string);
reply.headers[0].value = temp_string; reply.headers[0].value = temp_string;
} }
private: private:
DataFacadeT * facade; DataFacadeT *facade;
boost::unordered_map<std::string, unsigned> descriptorTable; std::unordered_map<std::string, unsigned> descriptor_table;
std::string descriptor_string; std::string descriptor_string;
}; };

View File

@ -25,23 +25,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef TIMESTAMPPLUGIN_H_ #ifndef TIMESTAMP_PLUGIN_H
#define TIMESTAMPPLUGIN_H_ #define TIMESTAMP_PLUGIN_H
#include "BasePlugin.h" #include "BasePlugin.h"
template<class DataFacadeT> template <class DataFacadeT> class TimestampPlugin : public BasePlugin
class TimestampPlugin : public BasePlugin { {
public: public:
explicit TimestampPlugin(const DataFacadeT * facade) explicit TimestampPlugin(const DataFacadeT *facade)
: facade(facade), descriptor_string("timestamp") : facade(facade), descriptor_string("timestamp")
{ } {
const std::string & GetDescriptor() const { return descriptor_string; } }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { const std::string GetDescriptor() const { return descriptor_string; }
void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
{
std::string tmp; std::string tmp;
//json // json
if("" != routeParameters.jsonpParameter) { if (!routeParameters.jsonpParameter.empty())
{
reply.content.push_back(routeParameters.jsonpParameter); reply.content.push_back(routeParameters.jsonpParameter);
reply.content.push_back("("); reply.content.push_back("(");
} }
@ -55,28 +58,33 @@ public:
reply.content.push_back("\""); reply.content.push_back("\"");
reply.content.push_back("}"); reply.content.push_back("}");
reply.headers.resize(3); reply.headers.resize(3);
if("" != routeParameters.jsonpParameter) { if (!routeParameters.jsonpParameter.empty())
{
reply.content.push_back(")"); reply.content.push_back(")");
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "text/javascript"; reply.headers[1].value = "text/javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"timestamp.js\""; reply.headers[2].value = "attachment; filename=\"timestamp.js\"";
} else { }
else
{
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "application/x-javascript"; reply.headers[1].value = "application/x-javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"timestamp.json\""; reply.headers[2].value = "attachment; filename=\"timestamp.json\"";
} }
unsigned content_length = 0; unsigned content_length = 0;
BOOST_FOREACH(const std::string & snippet, reply.content) { for (const std::string &snippet : reply.content)
{
content_length += snippet.length(); content_length += snippet.length();
} }
intToString(content_length, tmp); intToString(content_length, tmp);
reply.headers[0].value = tmp; reply.headers[0].value = tmp;
} }
private:
const DataFacadeT * facade; private:
const DataFacadeT *facade;
std::string descriptor_string; std::string descriptor_string;
}; };
#endif /* TIMESTAMPPLUGIN_H_ */ #endif /* TIMESTAMP_PLUGIN_H */

View File

@ -39,91 +39,96 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../Util/SimpleLogger.h" #include "../Util/SimpleLogger.h"
#include "../Util/StringUtil.h" #include "../Util/StringUtil.h"
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>
#include <cstdlib> #include <cstdlib>
#include <algorithm>
#include <memory>
#include <unordered_map>
#include <string> #include <string>
#include <vector> #include <vector>
template<class DataFacadeT> template <class DataFacadeT> class ViaRoutePlugin : public BasePlugin
class ViaRoutePlugin : public BasePlugin { {
private: private:
boost::unordered_map<std::string, unsigned> descriptorTable; std::unordered_map<std::string, unsigned> descriptorTable;
boost::shared_ptr<SearchEngine<DataFacadeT> > search_engine_ptr; std::shared_ptr<SearchEngine<DataFacadeT>> search_engine_ptr;
public:
explicit ViaRoutePlugin(DataFacadeT * facade) public:
: explicit ViaRoutePlugin(DataFacadeT *facade) : descriptor_string("viaroute"), facade(facade)
descriptor_string("viaroute"),
facade(facade)
{ {
search_engine_ptr = boost::make_shared<SearchEngine<DataFacadeT> >(facade); search_engine_ptr = std::make_shared<SearchEngine<DataFacadeT>>(facade);
descriptorTable.emplace("json", 0); descriptorTable.emplace("json", 0);
descriptorTable.emplace("gpx" , 1); descriptorTable.emplace("gpx", 1);
} }
virtual ~ViaRoutePlugin() { } virtual ~ViaRoutePlugin() {}
const std::string & GetDescriptor() const { return descriptor_string; } const std::string GetDescriptor() const { return descriptor_string; }
void HandleRequest( void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
const RouteParameters & routeParameters, {
http::Reply& reply // check number of parameters
) { if (2 > routeParameters.coordinates.size())
//check number of parameters {
if( 2 > routeParameters.coordinates.size() ) {
reply = http::Reply::StockReply(http::Reply::badRequest); reply = http::Reply::StockReply(http::Reply::badRequest);
return; return;
} }
RawRouteData raw_route; RawRouteData raw_route;
raw_route.checkSum = facade->GetCheckSum(); raw_route.checkSum = facade->GetCheckSum();
const bool checksumOK = (routeParameters.checkSum == raw_route.checkSum);
std::vector<std::string> textCoord; if (std::any_of(begin(routeParameters.coordinates),
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) { end(routeParameters.coordinates),
if( !checkCoord(routeParameters.coordinates[i]) ) { [&](FixedPointCoordinate coordinate)
{ return !coordinate.isValid(); }))
{
reply = http::Reply::StockReply(http::Reply::badRequest); reply = http::Reply::StockReply(http::Reply::badRequest);
return; return;
} }
raw_route.rawViaNodeCoordinates.push_back(routeParameters.coordinates[i]);
for (const FixedPointCoordinate &coordinate : routeParameters.coordinates)
{
raw_route.rawViaNodeCoordinates.emplace_back(coordinate);
} }
std::vector<PhantomNode> phantomNodeVector(raw_route.rawViaNodeCoordinates.size());
for(unsigned i = 0; i < raw_route.rawViaNodeCoordinates.size(); ++i) { std::vector<PhantomNode> phantom_node_vector(raw_route.rawViaNodeCoordinates.size());
if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) { const bool checksum_OK = (routeParameters.checkSum == raw_route.checkSum);
DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]);
if(phantomNodeVector[i].isValid(facade->GetNumberOfNodes())) { for (unsigned i = 0; i < raw_route.rawViaNodeCoordinates.size(); ++i)
{
if (checksum_OK && i < routeParameters.hints.size() &&
!routeParameters.hints[i].empty())
{
DecodeObjectFromBase64(routeParameters.hints[i], phantom_node_vector[i]);
if (phantom_node_vector[i].isValid(facade->GetNumberOfNodes()))
{
continue; continue;
} }
} }
facade->FindPhantomNodeForCoordinate( facade->FindPhantomNodeForCoordinate(raw_route.rawViaNodeCoordinates[i],
raw_route.rawViaNodeCoordinates[i], phantom_node_vector[i],
phantomNodeVector[i], routeParameters.zoomLevel);
routeParameters.zoomLevel
);
} }
PhantomNodes current_phantom_node_pair; PhantomNodes current_phantom_node_pair;
for (unsigned i = 0; i < phantomNodeVector.size()-1; ++i) for (unsigned i = 0; i < phantom_node_vector.size() - 1; ++i)
{ {
current_phantom_node_pair.source_phantom = phantomNodeVector[i]; current_phantom_node_pair.source_phantom = phantom_node_vector[i];
current_phantom_node_pair.target_phantom = phantomNodeVector[i+1]; current_phantom_node_pair.target_phantom = phantom_node_vector[i + 1];
raw_route.segmentEndCoordinates.push_back(current_phantom_node_pair); raw_route.segmentEndCoordinates.emplace_back(current_phantom_node_pair);
} }
if ((routeParameters.alternateRoute) && (1 == raw_route.segmentEndCoordinates.size())) if ((routeParameters.alternateRoute) && (1 == raw_route.segmentEndCoordinates.size()))
{ {
search_engine_ptr->alternative_path(raw_route.segmentEndCoordinates[0], raw_route); search_engine_ptr->alternative_path(raw_route.segmentEndCoordinates.front(), raw_route);
} }
else else
{ {
search_engine_ptr->shortest_path(raw_route.segmentEndCoordinates, raw_route); search_engine_ptr->shortest_path(raw_route.segmentEndCoordinates, raw_route);
} }
if (INT_MAX == raw_route.lengthOfShortestPath) if (INVALID_EDGE_WEIGHT == raw_route.lengthOfShortestPath)
{ {
SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found"; SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found";
} }
@ -137,33 +142,32 @@ public:
DescriptorConfig descriptor_config; DescriptorConfig descriptor_config;
unsigned descriptor_type = 0; auto iter = descriptorTable.find(routeParameters.outputFormat);
if(descriptorTable.find(routeParameters.outputFormat) != descriptorTable.end() ) { unsigned descriptor_type = (iter != descriptorTable.end() ? iter->second : 0);
descriptor_type = descriptorTable.find(routeParameters.outputFormat)->second;
}
descriptor_config.zoom_level = routeParameters.zoomLevel; descriptor_config.zoom_level = routeParameters.zoomLevel;
descriptor_config.instructions = routeParameters.printInstructions; descriptor_config.instructions = routeParameters.printInstructions;
descriptor_config.geometry = routeParameters.geometry; descriptor_config.geometry = routeParameters.geometry;
descriptor_config.encode_geometry = routeParameters.compression; descriptor_config.encode_geometry = routeParameters.compression;
boost::shared_ptr<BaseDescriptor<DataFacadeT> > descriptor; std::shared_ptr<BaseDescriptor<DataFacadeT>> descriptor;
switch(descriptor_type){ switch (descriptor_type)
case 0: {
descriptor = boost::make_shared<JSONDescriptor<DataFacadeT> >(); // case 0:
break; // descriptor = std::make_shared<JSONDescriptor<DataFacadeT>>();
// break;
case 1: case 1:
descriptor = boost::make_shared<GPXDescriptor<DataFacadeT> >(); descriptor = std::make_shared<GPXDescriptor<DataFacadeT>>();
break; break;
default: default:
descriptor = boost::make_shared<JSONDescriptor<DataFacadeT> >(); descriptor = std::make_shared<JSONDescriptor<DataFacadeT>>();
break; break;
} }
PhantomNodes phantom_nodes; PhantomNodes phantom_nodes;
phantom_nodes.source_phantom = raw_route.segmentEndCoordinates[0].source_phantom; phantom_nodes.source_phantom = raw_route.segmentEndCoordinates.front().source_phantom;
phantom_nodes.target_phantom = raw_route.segmentEndCoordinates[raw_route.segmentEndCoordinates.size()-1].target_phantom; phantom_nodes.target_phantom = raw_route.segmentEndCoordinates.back().target_phantom;
descriptor->SetConfig(descriptor_config); descriptor->SetConfig(descriptor_config);
descriptor->Run(raw_route, phantom_nodes, facade, reply); descriptor->Run(raw_route, phantom_nodes, facade, reply);
if (!routeParameters.jsonpParameter.empty()) if (!routeParameters.jsonpParameter.empty())
@ -172,21 +176,28 @@ public:
} }
reply.headers.resize(3); reply.headers.resize(3);
reply.headers[0].name = "Content-Length"; reply.headers[0].name = "Content-Length";
unsigned content_length = 0; unsigned content_length = 0;
BOOST_FOREACH(const std::string & snippet, reply.content) { for (const std::string &snippet : reply.content)
{
content_length += snippet.length(); content_length += snippet.length();
} }
std::string tmp_string; std::string tmp_string;
intToString(content_length, tmp_string); intToString(content_length, tmp_string);
reply.headers[0].value = tmp_string; reply.headers[0].value = tmp_string;
switch(descriptor_type){
switch (descriptor_type)
{
case 0: case 0:
if( !routeParameters.jsonpParameter.empty() ){ if (!routeParameters.jsonpParameter.empty())
{
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "text/javascript"; reply.headers[1].value = "text/javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"route.js\""; reply.headers[2].value = "attachment; filename=\"route.js\"";
} else { }
else
{
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "application/x-javascript"; reply.headers[1].value = "application/x-javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
@ -202,12 +213,15 @@ public:
break; break;
default: default:
if( !routeParameters.jsonpParameter.empty() ){ if (!routeParameters.jsonpParameter.empty())
{
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "text/javascript"; reply.headers[1].value = "text/javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"route.js\""; reply.headers[2].value = "attachment; filename=\"route.js\"";
} else { }
else
{
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "application/x-javascript"; reply.headers[1].value = "application/x-javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
@ -217,10 +231,10 @@ public:
} }
return; return;
} }
private:
private:
std::string descriptor_string; std::string descriptor_string;
DataFacadeT * facade; DataFacadeT *facade;
}; };
#endif /* VIAROUTEPLUGIN_H_ */ #endif /* VIAROUTEPLUGIN_H_ */