Refactoring of Plugins
This commit is contained in:
parent
124e555ed0
commit
c50b4c72d7
@ -33,8 +33,7 @@ public:
|
|||||||
BasePlugin() { }
|
BasePlugin() { }
|
||||||
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||||
virtual ~BasePlugin() { }
|
virtual ~BasePlugin() { }
|
||||||
virtual std::string GetDescriptor() const = 0;
|
virtual const std::string & GetDescriptor() const = 0;
|
||||||
virtual std::string GetVersionString() const = 0 ;
|
|
||||||
virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0;
|
virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0;
|
||||||
|
|
||||||
inline bool checkCoord(const _Coordinate & c) {
|
inline bool checkCoord(const _Coordinate & c) {
|
||||||
@ -48,7 +47,6 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BASEPLUGIN_H_ */
|
#endif /* BASEPLUGIN_H_ */
|
||||||
|
@ -1,8 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
* LocatePlugin.h
|
open source routing machine
|
||||||
*
|
Copyright (C) Dennis Luxen, 2010
|
||||||
* Created on: 01.01.2011
|
|
||||||
* Author: dennis
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU AFFERO General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HELLOWORLDPLUGIN_H_
|
#ifndef HELLOWORLDPLUGIN_H_
|
||||||
@ -15,10 +28,9 @@
|
|||||||
|
|
||||||
class HelloWorldPlugin : public BasePlugin {
|
class HelloWorldPlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
HelloWorldPlugin() {}
|
HelloWorldPlugin() : descriptor_string("hello"){}
|
||||||
virtual ~HelloWorldPlugin() { }
|
virtual ~HelloWorldPlugin() { }
|
||||||
std::string GetDescriptor() const { return std::string("hello"); }
|
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||||
std::string GetVersionString() const { return std::string("0.1a"); }
|
|
||||||
|
|
||||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
||||||
reply.status = http::Reply::ok;
|
reply.status = http::Reply::ok;
|
||||||
@ -45,6 +57,8 @@ public:
|
|||||||
reply.content.append(content.str());
|
reply.content.append(content.str());
|
||||||
reply.content.append("</body></html>");
|
reply.content.append("</body></html>");
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
std::string descriptor_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HELLOWORLDPLUGIN_H_ */
|
#endif /* HELLOWORLDPLUGIN_H_ */
|
||||||
|
@ -27,18 +27,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This Plugin locates the nearest node in the road network for a given coordinate.
|
* This Plugin locates the nearest node in the road network for a given coordinate.
|
||||||
*/
|
*/
|
||||||
class LocatePlugin : public BasePlugin {
|
class LocatePlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
LocatePlugin(QueryObjectsStorage * objects) {
|
LocatePlugin(QueryObjectsStorage * objects) : descriptor_string("locate") {
|
||||||
nodeHelpDesk = objects->nodeHelpDesk;
|
nodeHelpDesk = objects->nodeHelpDesk;
|
||||||
}
|
}
|
||||||
std::string GetDescriptor() const { return std::string("locate"); }
|
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||||
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
|
|
||||||
void HandleRequest(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.size()) {
|
||||||
@ -102,6 +99,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
NodeInformationHelpDesk * nodeHelpDesk;
|
NodeInformationHelpDesk * nodeHelpDesk;
|
||||||
|
std::string descriptor_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LOCATEPLUGIN_H_ */
|
#endif /* LOCATEPLUGIN_H_ */
|
||||||
|
@ -28,21 +28,22 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
#include "../Server/DataStructures/QueryObjectsStorage.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
class NearestPlugin : public BasePlugin {
|
class NearestPlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
NearestPlugin(QueryObjectsStorage * objects) : names(objects->names) {
|
NearestPlugin(QueryObjectsStorage * objects )
|
||||||
|
:
|
||||||
|
names(objects->names),
|
||||||
|
descriptor_string("nearest")
|
||||||
|
{
|
||||||
nodeHelpDesk = objects->nodeHelpDesk;
|
nodeHelpDesk = objects->nodeHelpDesk;
|
||||||
|
|
||||||
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
|
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
|
||||||
descriptorTable.insert(std::make_pair("json", 1));
|
descriptorTable.insert(std::make_pair("json", 1));
|
||||||
}
|
}
|
||||||
std::string GetDescriptor() const { return std::string("nearest"); }
|
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||||
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
|
|
||||||
void HandleRequest(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.size()) {
|
||||||
@ -112,6 +113,7 @@ private:
|
|||||||
NodeInformationHelpDesk * nodeHelpDesk;
|
NodeInformationHelpDesk * nodeHelpDesk;
|
||||||
HashTable<std::string, unsigned> descriptorTable;
|
HashTable<std::string, unsigned> descriptorTable;
|
||||||
std::vector<std::string> & names;
|
std::vector<std::string> & names;
|
||||||
|
std::string descriptor_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* NearestPlugin_H_ */
|
#endif /* NearestPlugin_H_ */
|
||||||
|
@ -24,14 +24,12 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
#include "RouteParameters.h"
|
#include "RouteParameters.h"
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
class TimestampPlugin : public BasePlugin {
|
class TimestampPlugin : public BasePlugin {
|
||||||
public:
|
public:
|
||||||
TimestampPlugin(QueryObjectsStorage * o) : objects(o) {
|
TimestampPlugin(QueryObjectsStorage * o)
|
||||||
}
|
: objects(o), descriptor_string("timestamp")
|
||||||
std::string GetDescriptor() const { return std::string("timestamp"); }
|
{ }
|
||||||
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
|
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
|
|
||||||
@ -70,6 +68,7 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
QueryObjectsStorage * objects;
|
QueryObjectsStorage * objects;
|
||||||
|
std::string descriptor_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TIMESTAMPPLUGIN_H_ */
|
#endif /* TIMESTAMPPLUGIN_H_ */
|
||||||
|
@ -38,8 +38,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -49,17 +47,20 @@ private:
|
|||||||
std::vector<std::string> & names;
|
std::vector<std::string> & names;
|
||||||
StaticGraph<QueryEdge::EdgeData> * graph;
|
StaticGraph<QueryEdge::EdgeData> * graph;
|
||||||
HashTable<std::string, unsigned> descriptorTable;
|
HashTable<std::string, unsigned> descriptorTable;
|
||||||
std::string pluginDescriptorString;
|
|
||||||
SearchEngine * searchEnginePtr;
|
SearchEngine * searchEnginePtr;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ViaRoutePlugin(QueryObjectsStorage * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) {
|
ViaRoutePlugin(QueryObjectsStorage * objects)
|
||||||
|
:
|
||||||
|
names(objects->names),
|
||||||
|
descriptor_string("viaroute")
|
||||||
|
{
|
||||||
nodeHelpDesk = objects->nodeHelpDesk;
|
nodeHelpDesk = objects->nodeHelpDesk;
|
||||||
graph = objects->graph;
|
graph = objects->graph;
|
||||||
|
|
||||||
searchEnginePtr = new SearchEngine(graph, nodeHelpDesk, names);
|
searchEnginePtr = new SearchEngine(graph, nodeHelpDesk, names);
|
||||||
|
|
||||||
descriptorTable.insert(std::make_pair("" , 0)); //default descriptor
|
descriptorTable.insert(std::make_pair("" , 0));
|
||||||
descriptorTable.insert(std::make_pair("json", 0));
|
descriptorTable.insert(std::make_pair("json", 0));
|
||||||
descriptorTable.insert(std::make_pair("gpx" , 1));
|
descriptorTable.insert(std::make_pair("gpx" , 1));
|
||||||
}
|
}
|
||||||
@ -68,8 +69,8 @@ public:
|
|||||||
delete searchEnginePtr;
|
delete searchEnginePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetDescriptor() const { return pluginDescriptorString; }
|
const std::string & GetDescriptor() const { return descriptor_string; }
|
||||||
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
|
|
||||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
||||||
//check number of parameters
|
//check number of parameters
|
||||||
if( 2 > routeParameters.coordinates.size() ) {
|
if( 2 > routeParameters.coordinates.size() ) {
|
||||||
@ -209,17 +210,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
inline bool checkCoord(const _Coordinate & c) {
|
std::string descriptor_string;
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user