migrate plugins directory to C++11
This commit is contained in:
parent
6c2c48a611
commit
946bfb9a26
@ -34,30 +34,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <osrm/Reply.h>
|
||||
#include <osrm/RouteParameters.h>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class BasePlugin {
|
||||
public:
|
||||
BasePlugin() { }
|
||||
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||
virtual ~BasePlugin() { }
|
||||
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;
|
||||
}
|
||||
class BasePlugin
|
||||
{
|
||||
public:
|
||||
BasePlugin() {}
|
||||
// Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||
virtual ~BasePlugin() {}
|
||||
virtual const std::string GetDescriptor() const = 0;
|
||||
virtual void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply) = 0;
|
||||
};
|
||||
|
||||
#endif /* BASEPLUGIN_H_ */
|
||||
|
@ -33,18 +33,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <string>
|
||||
|
||||
class HelloWorldPlugin : public BasePlugin {
|
||||
private:
|
||||
std::string temp_string;
|
||||
public:
|
||||
HelloWorldPlugin() : descriptor_string("hello"){}
|
||||
virtual ~HelloWorldPlugin() { }
|
||||
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||
class HelloWorldPlugin : public BasePlugin
|
||||
{
|
||||
private:
|
||||
std::string temp_string;
|
||||
|
||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
||||
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("<pre>");
|
||||
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.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("zoom level: ");
|
||||
intToString(routeParameters.zoomLevel, temp_string);
|
||||
reply.content.push_back(temp_string);
|
||||
@ -68,33 +72,43 @@ public:
|
||||
intToString(routeParameters.coordinates.size(), temp_string);
|
||||
reply.content.push_back(temp_string);
|
||||
reply.content.push_back("\n");
|
||||
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) {
|
||||
reply.content.push_back( " [");
|
||||
intToString(i, temp_string);
|
||||
|
||||
unsigned counter = 0;
|
||||
for (const FixedPointCoordinate &coordinate : routeParameters.coordinates)
|
||||
{
|
||||
reply.content.push_back(" [");
|
||||
intToString(counter, temp_string);
|
||||
reply.content.push_back(temp_string);
|
||||
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(",");
|
||||
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("\n");
|
||||
++counter;
|
||||
}
|
||||
reply.content.push_back( "Number of hints: ");
|
||||
|
||||
reply.content.push_back("Number of hints: ");
|
||||
intToString(routeParameters.hints.size(), temp_string);
|
||||
reply.content.push_back(temp_string);
|
||||
reply.content.push_back("\n");
|
||||
for(unsigned i = 0; i < routeParameters.hints.size(); ++i) {
|
||||
reply.content.push_back( " [");
|
||||
intToString(i, temp_string);
|
||||
|
||||
counter = 0;
|
||||
for (const std::string ¤t_string : routeParameters.hints)
|
||||
{
|
||||
reply.content.push_back(" [");
|
||||
intToString(counter, temp_string);
|
||||
reply.content.push_back(temp_string);
|
||||
reply.content.push_back("] ");
|
||||
reply.content.push_back(routeParameters.hints[i]);
|
||||
reply.content.push_back(current_string);
|
||||
reply.content.push_back("\n");
|
||||
++counter;
|
||||
}
|
||||
reply.content.push_back( "</pre></body></html>");
|
||||
}
|
||||
private:
|
||||
reply.content.push_back("</pre></body></html>");
|
||||
}
|
||||
|
||||
private:
|
||||
std::string descriptor_string;
|
||||
};
|
||||
|
||||
|
@ -25,62 +25,52 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef LOCATEPLUGIN_H_
|
||||
#define LOCATEPLUGIN_H_
|
||||
#ifndef LOCATE_PLUGIN_H
|
||||
#define LOCATE_PLUGIN_H
|
||||
|
||||
#include "BasePlugin.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>
|
||||
class LocatePlugin : public BasePlugin {
|
||||
public:
|
||||
explicit LocatePlugin(DataFacadeT * facade)
|
||||
:
|
||||
descriptor_string("locate"),
|
||||
facade(facade)
|
||||
{ }
|
||||
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||
template <class DataFacadeT> class LocatePlugin : public BasePlugin
|
||||
{
|
||||
public:
|
||||
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
|
||||
) {
|
||||
//check number of parameters
|
||||
if(!routeParameters.coordinates.size()) {
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
if(false == checkCoord(routeParameters.coordinates[0])) {
|
||||
void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
|
||||
{
|
||||
// check number of parameters
|
||||
if (routeParameters.coordinates.empty() || !routeParameters.coordinates.front().isValid())
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
//query to helpdesk
|
||||
// query to helpdesk
|
||||
FixedPointCoordinate result;
|
||||
std::string tmp;
|
||||
//json
|
||||
// json
|
||||
|
||||
if(!routeParameters.jsonpParameter.empty()) {
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
{
|
||||
reply.content.push_back(routeParameters.jsonpParameter);
|
||||
reply.content.push_back("(");
|
||||
}
|
||||
reply.status = http::Reply::ok;
|
||||
reply.content.push_back ("{");
|
||||
if(
|
||||
!facade->LocateClosestEndPointForCoordinate(
|
||||
routeParameters.coordinates[0],
|
||||
result
|
||||
)
|
||||
) {
|
||||
reply.content.push_back ("\"status\":207,");
|
||||
reply.content.push_back ("\"mapped_coordinate\":[]");
|
||||
} else {
|
||||
//Write coordinate to stream
|
||||
reply.content.push_back("{");
|
||||
if (!facade->LocateClosestEndPointForCoordinate(routeParameters.coordinates.front(), result))
|
||||
{
|
||||
reply.content.push_back("\"status\":207,");
|
||||
reply.content.push_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.push_back("\"status\":0,");
|
||||
reply.content.push_back("\"mapped_coordinate\":");
|
||||
FixedPointCoordinate::convertInternalLatLonToString(result.lat, tmp);
|
||||
reply.content.push_back("[");
|
||||
reply.content.push_back(tmp);
|
||||
@ -91,13 +81,16 @@ public:
|
||||
}
|
||||
reply.content.push_back("}");
|
||||
reply.headers.resize(3);
|
||||
if(!routeParameters.jsonpParameter.empty()) {
|
||||
reply.content.push_back( ")");
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
{
|
||||
reply.content.push_back(")");
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "text/javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
reply.headers[2].value = "attachment; filename=\"location.js\"";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "application/x-javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
@ -105,7 +98,8 @@ public:
|
||||
}
|
||||
reply.headers[0].name = "Content-Length";
|
||||
unsigned content_length = 0;
|
||||
BOOST_FOREACH(const std::string & snippet, reply.content) {
|
||||
for (const std::string &snippet : reply.content)
|
||||
{
|
||||
content_length += snippet.length();
|
||||
}
|
||||
intToString(content_length, tmp);
|
||||
@ -113,9 +107,9 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string descriptor_string;
|
||||
DataFacadeT * facade;
|
||||
DataFacadeT *facade;
|
||||
};
|
||||
|
||||
#endif /* LOCATEPLUGIN_H_ */
|
||||
#endif /* LOCATE_PLUGIN_H */
|
||||
|
@ -32,62 +32,64 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "../DataStructures/PhantomNodes.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.
|
||||
*/
|
||||
|
||||
template<class DataFacadeT>
|
||||
class NearestPlugin : public BasePlugin {
|
||||
public:
|
||||
explicit NearestPlugin(DataFacadeT * facade )
|
||||
:
|
||||
facade(facade),
|
||||
descriptor_string("nearest")
|
||||
template <class DataFacadeT> class NearestPlugin : public BasePlugin
|
||||
{
|
||||
public:
|
||||
explicit NearestPlugin(DataFacadeT *facade) : facade(facade), descriptor_string("nearest")
|
||||
{
|
||||
descriptorTable.emplace("", 0); //default descriptor
|
||||
descriptorTable.emplace("json", 1);
|
||||
descriptor_table.emplace("", 0); // default descriptor
|
||||
descriptor_table.emplace("json", 1);
|
||||
}
|
||||
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||
void HandleRequest(
|
||||
const RouteParameters & routeParameters,
|
||||
http::Reply & reply
|
||||
) {
|
||||
//check number of parameters
|
||||
if(!routeParameters.coordinates.size()) {
|
||||
|
||||
const std::string GetDescriptor() const { return descriptor_string; }
|
||||
|
||||
void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
|
||||
{
|
||||
// check number of parameters
|
||||
if (routeParameters.coordinates.empty())
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
if( !checkCoord(routeParameters.coordinates[0]) ) {
|
||||
if (!routeParameters.coordinates.front().isValid())
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
PhantomNode result;
|
||||
facade->FindPhantomNodeForCoordinate(
|
||||
routeParameters.coordinates[0],
|
||||
result,
|
||||
routeParameters.zoomLevel
|
||||
);
|
||||
routeParameters.coordinates.front(), 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("(");
|
||||
}
|
||||
|
||||
reply.status = http::Reply::ok;
|
||||
reply.content.push_back("{\"status\":");
|
||||
if(UINT_MAX != result.forward_node_id) {
|
||||
if (SPECIAL_NODEID != result.forward_node_id)
|
||||
{
|
||||
reply.content.push_back("0,");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reply.content.push_back("207,");
|
||||
}
|
||||
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);
|
||||
reply.content.push_back(temp_string);
|
||||
FixedPointCoordinate::convertInternalLatLonToString(result.location.lon, temp_string);
|
||||
@ -95,19 +97,23 @@ public:
|
||||
reply.content.push_back(temp_string);
|
||||
}
|
||||
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);
|
||||
reply.content.push_back(temp_string);
|
||||
}
|
||||
reply.content.push_back("\"}");
|
||||
reply.headers.resize(3);
|
||||
if( !routeParameters.jsonpParameter.empty() ) {
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
{
|
||||
reply.content.push_back(")");
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "text/javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
reply.headers[2].value = "attachment; filename=\"location.js\"";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "application/x-javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
@ -115,16 +121,17 @@ public:
|
||||
}
|
||||
reply.headers[0].name = "Content-Length";
|
||||
unsigned content_length = 0;
|
||||
BOOST_FOREACH(const std::string & snippet, reply.content) {
|
||||
for (const std::string &snippet : reply.content)
|
||||
{
|
||||
content_length += snippet.length();
|
||||
}
|
||||
intToString(content_length, temp_string);
|
||||
reply.headers[0].value = temp_string;
|
||||
}
|
||||
|
||||
private:
|
||||
DataFacadeT * facade;
|
||||
boost::unordered_map<std::string, unsigned> descriptorTable;
|
||||
private:
|
||||
DataFacadeT *facade;
|
||||
std::unordered_map<std::string, unsigned> descriptor_table;
|
||||
std::string descriptor_string;
|
||||
};
|
||||
|
||||
|
@ -25,23 +25,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TIMESTAMPPLUGIN_H_
|
||||
#define TIMESTAMPPLUGIN_H_
|
||||
#ifndef TIMESTAMP_PLUGIN_H
|
||||
#define TIMESTAMP_PLUGIN_H
|
||||
|
||||
#include "BasePlugin.h"
|
||||
|
||||
template<class DataFacadeT>
|
||||
class TimestampPlugin : public BasePlugin {
|
||||
public:
|
||||
explicit TimestampPlugin(const DataFacadeT * facade)
|
||||
: facade(facade), descriptor_string("timestamp")
|
||||
{ }
|
||||
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
||||
template <class DataFacadeT> class TimestampPlugin : public BasePlugin
|
||||
{
|
||||
public:
|
||||
explicit TimestampPlugin(const DataFacadeT *facade)
|
||||
: facade(facade), descriptor_string("timestamp")
|
||||
{
|
||||
}
|
||||
const std::string GetDescriptor() const { return descriptor_string; }
|
||||
void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
|
||||
{
|
||||
std::string tmp;
|
||||
|
||||
//json
|
||||
if("" != routeParameters.jsonpParameter) {
|
||||
// json
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
{
|
||||
reply.content.push_back(routeParameters.jsonpParameter);
|
||||
reply.content.push_back("(");
|
||||
}
|
||||
@ -49,34 +52,39 @@ public:
|
||||
reply.status = http::Reply::ok;
|
||||
reply.content.push_back("{");
|
||||
reply.content.push_back("\"status\":");
|
||||
reply.content.push_back("0,");
|
||||
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.headers.resize(3);
|
||||
if("" != routeParameters.jsonpParameter) {
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
{
|
||||
reply.content.push_back(")");
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "text/javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
reply.headers[2].value = "attachment; filename=\"timestamp.js\"";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "application/x-javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
reply.headers[2].value = "attachment; filename=\"timestamp.json\"";
|
||||
}
|
||||
unsigned content_length = 0;
|
||||
BOOST_FOREACH(const std::string & snippet, reply.content) {
|
||||
for (const std::string &snippet : reply.content)
|
||||
{
|
||||
content_length += snippet.length();
|
||||
}
|
||||
intToString(content_length, tmp);
|
||||
reply.headers[0].value = tmp;
|
||||
}
|
||||
private:
|
||||
const DataFacadeT * facade;
|
||||
|
||||
private:
|
||||
const DataFacadeT *facade;
|
||||
std::string descriptor_string;
|
||||
};
|
||||
|
||||
#endif /* TIMESTAMPPLUGIN_H_ */
|
||||
#endif /* TIMESTAMP_PLUGIN_H */
|
||||
|
@ -39,91 +39,96 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
template<class DataFacadeT>
|
||||
class ViaRoutePlugin : public BasePlugin {
|
||||
private:
|
||||
boost::unordered_map<std::string, unsigned> descriptorTable;
|
||||
boost::shared_ptr<SearchEngine<DataFacadeT> > search_engine_ptr;
|
||||
public:
|
||||
template <class DataFacadeT> class ViaRoutePlugin : public BasePlugin
|
||||
{
|
||||
private:
|
||||
std::unordered_map<std::string, unsigned> descriptorTable;
|
||||
std::shared_ptr<SearchEngine<DataFacadeT>> search_engine_ptr;
|
||||
|
||||
explicit ViaRoutePlugin(DataFacadeT * facade)
|
||||
:
|
||||
descriptor_string("viaroute"),
|
||||
facade(facade)
|
||||
public:
|
||||
explicit ViaRoutePlugin(DataFacadeT *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("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(
|
||||
const RouteParameters & routeParameters,
|
||||
http::Reply& reply
|
||||
) {
|
||||
//check number of parameters
|
||||
if( 2 > routeParameters.coordinates.size() ) {
|
||||
void HandleRequest(const RouteParameters &routeParameters, http::Reply &reply)
|
||||
{
|
||||
// check number of parameters
|
||||
if (2 > routeParameters.coordinates.size())
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
RawRouteData raw_route;
|
||||
raw_route.checkSum = facade->GetCheckSum();
|
||||
const bool checksumOK = (routeParameters.checkSum == raw_route.checkSum);
|
||||
std::vector<std::string> textCoord;
|
||||
for(unsigned i = 0; i < routeParameters.coordinates.size(); ++i) {
|
||||
if( !checkCoord(routeParameters.coordinates[i]) ) {
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
raw_route.rawViaNodeCoordinates.push_back(routeParameters.coordinates[i]);
|
||||
|
||||
if (std::any_of(begin(routeParameters.coordinates),
|
||||
end(routeParameters.coordinates),
|
||||
[&](FixedPointCoordinate coordinate)
|
||||
{ return !coordinate.isValid(); }))
|
||||
{
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
std::vector<PhantomNode> phantomNodeVector(raw_route.rawViaNodeCoordinates.size());
|
||||
for(unsigned i = 0; i < raw_route.rawViaNodeCoordinates.size(); ++i) {
|
||||
if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) {
|
||||
DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]);
|
||||
if(phantomNodeVector[i].isValid(facade->GetNumberOfNodes())) {
|
||||
|
||||
for (const FixedPointCoordinate &coordinate : routeParameters.coordinates)
|
||||
{
|
||||
raw_route.rawViaNodeCoordinates.emplace_back(coordinate);
|
||||
}
|
||||
|
||||
std::vector<PhantomNode> phantom_node_vector(raw_route.rawViaNodeCoordinates.size());
|
||||
const bool checksum_OK = (routeParameters.checkSum == raw_route.checkSum);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
facade->FindPhantomNodeForCoordinate(
|
||||
raw_route.rawViaNodeCoordinates[i],
|
||||
phantomNodeVector[i],
|
||||
routeParameters.zoomLevel
|
||||
);
|
||||
facade->FindPhantomNodeForCoordinate(raw_route.rawViaNodeCoordinates[i],
|
||||
phantom_node_vector[i],
|
||||
routeParameters.zoomLevel);
|
||||
}
|
||||
|
||||
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.target_phantom = phantomNodeVector[i+1];
|
||||
raw_route.segmentEndCoordinates.push_back(current_phantom_node_pair);
|
||||
current_phantom_node_pair.source_phantom = phantom_node_vector[i];
|
||||
current_phantom_node_pair.target_phantom = phantom_node_vector[i + 1];
|
||||
raw_route.segmentEndCoordinates.emplace_back(current_phantom_node_pair);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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";
|
||||
}
|
||||
@ -137,33 +142,32 @@ public:
|
||||
|
||||
DescriptorConfig descriptor_config;
|
||||
|
||||
unsigned descriptor_type = 0;
|
||||
if(descriptorTable.find(routeParameters.outputFormat) != descriptorTable.end() ) {
|
||||
descriptor_type = descriptorTable.find(routeParameters.outputFormat)->second;
|
||||
}
|
||||
auto iter = descriptorTable.find(routeParameters.outputFormat);
|
||||
unsigned descriptor_type = (iter != descriptorTable.end() ? iter->second : 0);
|
||||
|
||||
descriptor_config.zoom_level = routeParameters.zoomLevel;
|
||||
descriptor_config.instructions = routeParameters.printInstructions;
|
||||
descriptor_config.geometry = routeParameters.geometry;
|
||||
descriptor_config.encode_geometry = routeParameters.compression;
|
||||
|
||||
boost::shared_ptr<BaseDescriptor<DataFacadeT> > descriptor;
|
||||
switch(descriptor_type){
|
||||
case 0:
|
||||
descriptor = boost::make_shared<JSONDescriptor<DataFacadeT> >();
|
||||
break;
|
||||
std::shared_ptr<BaseDescriptor<DataFacadeT>> descriptor;
|
||||
switch (descriptor_type)
|
||||
{
|
||||
// case 0:
|
||||
// descriptor = std::make_shared<JSONDescriptor<DataFacadeT>>();
|
||||
// break;
|
||||
case 1:
|
||||
descriptor = boost::make_shared<GPXDescriptor<DataFacadeT> >();
|
||||
descriptor = std::make_shared<GPXDescriptor<DataFacadeT>>();
|
||||
break;
|
||||
default:
|
||||
descriptor = boost::make_shared<JSONDescriptor<DataFacadeT> >();
|
||||
descriptor = std::make_shared<JSONDescriptor<DataFacadeT>>();
|
||||
break;
|
||||
}
|
||||
|
||||
PhantomNodes phantom_nodes;
|
||||
phantom_nodes.source_phantom = raw_route.segmentEndCoordinates[0].source_phantom;
|
||||
phantom_nodes.target_phantom = raw_route.segmentEndCoordinates[raw_route.segmentEndCoordinates.size()-1].target_phantom;
|
||||
phantom_nodes.source_phantom = raw_route.segmentEndCoordinates.front().source_phantom;
|
||||
phantom_nodes.target_phantom = raw_route.segmentEndCoordinates.back().target_phantom;
|
||||
descriptor->SetConfig(descriptor_config);
|
||||
|
||||
descriptor->Run(raw_route, phantom_nodes, facade, reply);
|
||||
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
@ -172,21 +176,28 @@ public:
|
||||
}
|
||||
reply.headers.resize(3);
|
||||
reply.headers[0].name = "Content-Length";
|
||||
|
||||
unsigned content_length = 0;
|
||||
BOOST_FOREACH(const std::string & snippet, reply.content) {
|
||||
for (const std::string &snippet : reply.content)
|
||||
{
|
||||
content_length += snippet.length();
|
||||
}
|
||||
std::string tmp_string;
|
||||
intToString(content_length, tmp_string);
|
||||
reply.headers[0].value = tmp_string;
|
||||
switch(descriptor_type){
|
||||
|
||||
switch (descriptor_type)
|
||||
{
|
||||
case 0:
|
||||
if( !routeParameters.jsonpParameter.empty() ){
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
{
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "text/javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
reply.headers[2].value = "attachment; filename=\"route.js\"";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "application/x-javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
@ -202,12 +213,15 @@ public:
|
||||
|
||||
break;
|
||||
default:
|
||||
if( !routeParameters.jsonpParameter.empty() ){
|
||||
if (!routeParameters.jsonpParameter.empty())
|
||||
{
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "text/javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
reply.headers[2].value = "attachment; filename=\"route.js\"";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
reply.headers[1].name = "Content-Type";
|
||||
reply.headers[1].value = "application/x-javascript";
|
||||
reply.headers[2].name = "Content-Disposition";
|
||||
@ -217,10 +231,10 @@ public:
|
||||
}
|
||||
return;
|
||||
}
|
||||
private:
|
||||
|
||||
private:
|
||||
std::string descriptor_string;
|
||||
DataFacadeT * facade;
|
||||
DataFacadeT *facade;
|
||||
};
|
||||
|
||||
|
||||
#endif /* VIAROUTEPLUGIN_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user