From 1fdfac4aafb4f0d3bcf4a461b6038701003a4cbb Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 27 Aug 2012 17:40:59 +0200 Subject: [PATCH] Refactoring extraction stuff --- Algorithms/DouglasPeucker.h | 3 +- Algorithms/PolylineCompressor.h | 2 +- Contractor/Contractor.h | 2 +- Contractor/EdgeBasedGraphFactory.cpp | 2 +- Contractor/EdgeBasedGraphFactory.h | 2 +- DataStructures/Coordinate.h | 76 +++++++++ DataStructures/GridEdge.h | 2 + DataStructures/ImportNode.h | 44 ++++++ DataStructures/NNGrid.h | 2 +- DataStructures/NodeInformationHelpDesk.h | 1 + DataStructures/PhantomNodes.h | 2 +- DataStructures/Restriction.h | 97 ++++++++++++ Descriptors/BaseDescriptor.h | 2 +- Descriptors/DescriptionFactory.h | 2 +- {DataStructures => Extractor}/BaseParser.h | 0 .../ExtractorCallBacks.h | 0 .../ExtractorStructs.h | 147 +----------------- {DataStructures => Extractor}/PBFParser.h | 4 +- Extractor/V8Helper.h | 105 +++++++++++++ {DataStructures => Extractor}/XMLParser.h | 4 +- Plugins/RawRouteData.h | 10 ++ Server/ServerFactory.h | 2 +- Util/GraphLoader.h | 3 +- Util/OpenMPWrapper.h | 34 ++++ Util/StringUtil.h | 3 +- createHierarchy.cpp | 5 +- extractor.cpp | 8 +- routed.cpp | 2 +- 28 files changed, 399 insertions(+), 167 deletions(-) create mode 100644 DataStructures/Coordinate.h create mode 100644 DataStructures/ImportNode.h create mode 100644 DataStructures/Restriction.h rename {DataStructures => Extractor}/BaseParser.h (100%) rename {DataStructures => Extractor}/ExtractorCallBacks.h (100%) rename {DataStructures => Extractor}/ExtractorStructs.h (61%) rename {DataStructures => Extractor}/PBFParser.h (99%) create mode 100644 Extractor/V8Helper.h rename {DataStructures => Extractor}/XMLParser.h (99%) create mode 100644 Util/OpenMPWrapper.h diff --git a/Algorithms/DouglasPeucker.h b/Algorithms/DouglasPeucker.h index 63388db1e..724b479f8 100644 --- a/Algorithms/DouglasPeucker.h +++ b/Algorithms/DouglasPeucker.h @@ -21,10 +21,11 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef DOUGLASPEUCKER_H_ #define DOUGLASPEUCKER_H_ +#include #include #include -#include "../DataStructures/ExtractorStructs.h" +#include "../DataStructures/Coordinate.h" /*This class object computes the bitvector of indicating generalized input points * according to the (Ramer-)Douglas-Peucker algorithm. diff --git a/Algorithms/PolylineCompressor.h b/Algorithms/PolylineCompressor.h index 836fdb868..de61c97b6 100644 --- a/Algorithms/PolylineCompressor.h +++ b/Algorithms/PolylineCompressor.h @@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#include "../DataStructures/ExtractorStructs.h" +//#include "../DataStructures/ExtractorStructs.h" #include "../DataStructures/SegmentInformation.h" #include "../Util/StringUtil.h" diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 4c048fdee..badc4afb8 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -39,7 +39,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/Percent.h" #include "../DataStructures/XORFastHash.h" #include "../DataStructures/XORFastHashStorage.h" -#include "../Util/OpenMPReplacement.h" +#include "../Util/OpenMPWrapper.h" #include "../Util/StringUtil.h" class Contractor { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 7ade03f47..da26d5fba 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -25,7 +25,7 @@ #include #include -#include "../Util/OpenMPReplacement.h" +#include "../Util/OpenMPWrapper.h" #include "../DataStructures/Percent.h" #include "EdgeBasedGraphFactory.h" diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 4eeaa4edb..d4acb25ba 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -36,7 +36,7 @@ #include "../typedefs.h" #include "../DataStructures/DeallocatingVector.h" #include "../DataStructures/DynamicGraph.h" -#include "../DataStructures/ExtractorStructs.h" +#include "../Extractor/ExtractorStructs.h" #include "../DataStructures/HashTable.h" #include "../DataStructures/ImportEdge.h" #include "../DataStructures/QueryEdge.h" diff --git a/DataStructures/Coordinate.h b/DataStructures/Coordinate.h new file mode 100644 index 000000000..21b43ed8f --- /dev/null +++ b/DataStructures/Coordinate.h @@ -0,0 +1,76 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +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 COORDINATE_H_ +#define COORDINATE_H_ + +#include +#include + +struct _Coordinate { + int lat; + int lon; + _Coordinate () : lat(INT_MIN), lon(INT_MIN) {} + _Coordinate (int t, int n) : lat(t) , lon(n) {} + void Reset() { + lat = INT_MIN; + lon = INT_MIN; + } + bool isSet() const { + return (INT_MIN != lat) && (INT_MIN != lon); + } + inline bool isValid() const { + if(lat > 90*100000 || lat < -90*100000 || lon > 180*100000 || lon <-180*100000) { + return false; + } + return true; + } + +}; + +inline std::ostream & operator<<(std::ostream & out, const _Coordinate & c){ + out << "(" << c.lat << "," << c.lon << ")"; + return out; +} + +inline double ApproximateDistance( const int lat1, const int lon1, const int lat2, const int lon2 ) { + assert(lat1 != INT_MIN); + assert(lon1 != INT_MIN); + assert(lat2 != INT_MIN); + assert(lon2 != INT_MIN); + static const double DEG_TO_RAD = 0.017453292519943295769236907684886; + //Earth's quatratic mean radius for WGS-84 + static const double EARTH_RADIUS_IN_METERS = 6372797.560856; + double latitudeArc = ( lat1/100000. - lat2/100000. ) * DEG_TO_RAD; + double longitudeArc = ( lon1/100000. - lon2/100000. ) * DEG_TO_RAD; + double latitudeH = sin( latitudeArc * 0.5 ); + latitudeH *= latitudeH; + double lontitudeH = sin( longitudeArc * 0.5 ); + lontitudeH *= lontitudeH; + double tmp = cos( lat1/100000. * DEG_TO_RAD ) * cos( lat2/100000. * DEG_TO_RAD ); + double distanceArc = 2.0 * asin( sqrt( latitudeH + tmp * lontitudeH ) ); + return EARTH_RADIUS_IN_METERS * distanceArc; +} + +inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) { + return ApproximateDistance( c1.lat, c1.lon, c2.lat, c2.lon ); +} + +#endif /* COORDINATE_H_ */ diff --git a/DataStructures/GridEdge.h b/DataStructures/GridEdge.h index c01a27cbf..7b2dd7825 100644 --- a/DataStructures/GridEdge.h +++ b/DataStructures/GridEdge.h @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef GRIDEDGE_H_ #define GRIDEDGE_H_ +#include "Coordinate.h" + struct _GridEdge { _GridEdge(NodeID n, NodeID na, int w, _Coordinate sc, _Coordinate tc, bool bttc) : edgeBasedNode(n), nameID(na), weight(w), startCoord(sc), targetCoord(tc), belongsToTinyComponent(bttc) {} _GridEdge() : edgeBasedNode(UINT_MAX), nameID(UINT_MAX), weight(INT_MAX), belongsToTinyComponent(false) {} diff --git a/DataStructures/ImportNode.h b/DataStructures/ImportNode.h new file mode 100644 index 000000000..5f34d691c --- /dev/null +++ b/DataStructures/ImportNode.h @@ -0,0 +1,44 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +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 IMPORTNODE_H_ +#define IMPORTNODE_H_ + +#include "NodeCoords.h" + +struct _Node : NodeInfo{ + _Node(int _lat, int _lon, unsigned int _id, bool _bollard, bool _trafficLight) : NodeInfo(_lat, _lon, _id), bollard(_bollard), trafficLight(_trafficLight) {} + _Node() : bollard(false), trafficLight(false) {} + + static _Node min_value() { + return _Node(0,0,0, false, false); + } + static _Node max_value() { + return _Node((std::numeric_limits::max)(), (std::numeric_limits::max)(), (std::numeric_limits::max)(), false, false); + } + NodeID key() const { + return id; + } + bool bollard; + bool trafficLight; + +}; + +#endif /* IMPORTNODE_H_ */ diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 547c5f23e..5588b1dfd 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -41,7 +41,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include "DeallocatingVector.h" -#include "ExtractorStructs.h" +//#include "ExtractorStructs.h" #include "GridEdge.h" #include "Percent.h" #include "PhantomNodes.h" diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index a871c7e3b..cddfede98 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -29,6 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../DataStructures/QueryEdge.h" #include "NNGrid.h" #include "PhantomNodes.h" +#include "NodeCoords.h" class NodeInformationHelpDesk{ public: diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 537c749ef..461dfdf08 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef PHANTOMNODES_H_ #define PHANTOMNODES_H_ -#include "ExtractorStructs.h" +#include "Coordinate.h" struct PhantomNode { PhantomNode() : edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX), ratio(0.) {} diff --git a/DataStructures/Restriction.h b/DataStructures/Restriction.h new file mode 100644 index 000000000..3627c6ade --- /dev/null +++ b/DataStructures/Restriction.h @@ -0,0 +1,97 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +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 RESTRICTION_H_ +#define RESTRICTION_H_ + +#include + +struct _Restriction { + NodeID viaNode; + NodeID fromNode; + NodeID toNode; + struct Bits { //mostly unused + Bits() : isOnly(false), unused1(false), unused2(false), unused3(false), unused4(false), unused5(false), unused6(false), unused7(false) {} + char isOnly:1; + char unused1:1; + char unused2:1; + char unused3:1; + char unused4:1; + char unused5:1; + char unused6:1; + char unused7:1; + } flags; + + _Restriction(NodeID vn) : viaNode(vn), fromNode(UINT_MAX), toNode(UINT_MAX) { } + _Restriction(bool isOnly = false) : viaNode(UINT_MAX), fromNode(UINT_MAX), toNode(UINT_MAX) { + flags.isOnly = isOnly; + } +}; + +inline bool CmpRestrictionByFrom ( _Restriction a, _Restriction b) { return (a.fromNode < b.fromNode); } + +struct _RawRestrictionContainer { + _Restriction restriction; + EdgeID fromWay; + EdgeID toWay; + unsigned viaNode; + + _RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaNode(vw) { restriction.viaNode = vn;} + _RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;} + + static _RawRestrictionContainer min_value() { + return _RawRestrictionContainer(0, 0, 0, 0); + } + static _RawRestrictionContainer max_value() { + return _RawRestrictionContainer(UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX); + } +}; + +struct CmpRestrictionContainerByFrom: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { + typedef _RawRestrictionContainer value_type; + bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const { + return a.fromWay < b.fromWay; + } + value_type max_value() { + return _RawRestrictionContainer::max_value(); + } + value_type min_value() { + return _RawRestrictionContainer::min_value(); + } +}; + +struct CmpRestrictionContainerByTo: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { + typedef _RawRestrictionContainer value_type; + bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const { + return a.toWay < b.toWay; + } + value_type max_value() { + return _RawRestrictionContainer::max_value(); + } + value_type min_value() { + return _RawRestrictionContainer::min_value(); + } +}; + + + +#endif /* RESTRICTION_H_ */ diff --git a/Descriptors/BaseDescriptor.h b/Descriptors/BaseDescriptor.h index c0eefab7a..6a49bd81b 100644 --- a/Descriptors/BaseDescriptor.h +++ b/Descriptors/BaseDescriptor.h @@ -28,7 +28,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include "../typedefs.h" -#include "../DataStructures/ExtractorStructs.h" +#include "../DataStructures/PhantomNodes.h" #include "../DataStructures/HashTable.h" #include "../Util/StringUtil.h" diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index e16ce6b0e..fbd9e1215 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -26,7 +26,7 @@ #include "../typedefs.h" #include "../Algorithms/DouglasPeucker.h" #include "../Algorithms/PolylineCompressor.h" -#include "../DataStructures/ExtractorStructs.h" +#include "../DataStructures/Coordinate.h" #include "../DataStructures/QueryEdge.h" #include "../DataStructures/SearchEngine.h" #include "../DataStructures/SegmentInformation.h" diff --git a/DataStructures/BaseParser.h b/Extractor/BaseParser.h similarity index 100% rename from DataStructures/BaseParser.h rename to Extractor/BaseParser.h diff --git a/DataStructures/ExtractorCallBacks.h b/Extractor/ExtractorCallBacks.h similarity index 100% rename from DataStructures/ExtractorCallBacks.h rename to Extractor/ExtractorCallBacks.h diff --git a/DataStructures/ExtractorStructs.h b/Extractor/ExtractorStructs.h similarity index 61% rename from DataStructures/ExtractorStructs.h rename to Extractor/ExtractorStructs.h index f6665d2de..5578e6080 100644 --- a/DataStructures/ExtractorStructs.h +++ b/Extractor/ExtractorStructs.h @@ -24,66 +24,17 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include "../DataStructures/Coordinate.h" #include "../DataStructures/HashTable.h" +#include "../DataStructures/ImportNode.h" #include "../DataStructures/NodeCoords.h" +#include "../DataStructures/Restriction.h" +#include "../DataStructures/Util.h" #include "../typedefs.h" -#include "Util.h" - -struct _PathData { - _PathData(NodeID no, unsigned na, unsigned tu, unsigned dur) : node(no), nameID(na), durationOfSegment(dur), turnInstruction(tu) { } - NodeID node; - unsigned nameID; - unsigned durationOfSegment; - short turnInstruction; -}; typedef boost::unordered_map StringMap; typedef boost::unordered_map > StringToIntPairMap; -struct _Node : NodeInfo{ - _Node(int _lat, int _lon, unsigned int _id, bool _bollard, bool _trafficLight) : NodeInfo(_lat, _lon, _id), bollard(_bollard), trafficLight(_trafficLight) {} - _Node() : bollard(false), trafficLight(false) {} - - static _Node min_value() { - return _Node(0,0,0, false, false); - } - static _Node max_value() { - return _Node((std::numeric_limits::max)(), (std::numeric_limits::max)(), (std::numeric_limits::max)(), false, false); - } - NodeID key() const { - return id; - } - bool bollard; - bool trafficLight; - -}; - -struct _Coordinate { - int lat; - int lon; - _Coordinate () : lat(INT_MIN), lon(INT_MIN) {} - _Coordinate (int t, int n) : lat(t) , lon(n) {} - void Reset() { - lat = INT_MIN; - lon = INT_MIN; - } - bool isSet() const { - return (INT_MIN != lat) && (INT_MIN != lon); - } - inline bool isValid() const { - if(lat > 90*100000 || lat < -90*100000 || lon > 180*100000 || lon <-180*100000) { - return false; - } - return true; - } - -}; - -inline ostream & operator<<(ostream & out, const _Coordinate & c){ - out << "(" << c.lat << "," << c.lon << ")"; - return out; -} - struct _Way { _Way() : id(UINT_MAX), nameID(UINT_MAX) { @@ -172,73 +123,6 @@ struct _Edge { }; -struct _Restriction { - NodeID viaNode; - NodeID fromNode; - NodeID toNode; - struct Bits { //mostly unused - Bits() : isOnly(false), unused1(false), unused2(false), unused3(false), unused4(false), unused5(false), unused6(false), unused7(false) {} - char isOnly:1; - char unused1:1; - char unused2:1; - char unused3:1; - char unused4:1; - char unused5:1; - char unused6:1; - char unused7:1; - } flags; - - _Restriction(NodeID vn) : viaNode(vn), fromNode(UINT_MAX), toNode(UINT_MAX) { } - _Restriction(bool isOnly = false) : viaNode(UINT_MAX), fromNode(UINT_MAX), toNode(UINT_MAX) { - flags.isOnly = isOnly; - } -}; - -inline bool CmpRestrictionByFrom ( _Restriction a, _Restriction b) { return (a.fromNode < b.fromNode); } - -struct _RawRestrictionContainer { - _Restriction restriction; - EdgeID fromWay; - EdgeID toWay; - unsigned viaNode; - - _RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaNode(vw) { restriction.viaNode = vn;} - _RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;} - - static _RawRestrictionContainer min_value() { - return _RawRestrictionContainer((numeric_limits::min)(), (numeric_limits::min)(), (numeric_limits::min)(), (numeric_limits::min)()); - } - static _RawRestrictionContainer max_value() { - return _RawRestrictionContainer((numeric_limits::max)(), (numeric_limits::max)(), (numeric_limits::max)(), (numeric_limits::max)()); - } -}; - -struct CmpRestrictionContainerByFrom: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { - typedef _RawRestrictionContainer value_type; - bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const { - return a.fromWay < b.fromWay; - } - value_type max_value() { - return _RawRestrictionContainer::max_value(); - } - value_type min_value() { - return _RawRestrictionContainer::min_value(); - } -}; - -struct CmpRestrictionContainerByTo: public std::binary_function<_RawRestrictionContainer, _RawRestrictionContainer, bool> { - typedef _RawRestrictionContainer value_type; - bool operator () (const _RawRestrictionContainer & a, const _RawRestrictionContainer & b) const { - return a.toWay < b.toWay; - } - value_type max_value() { - return _RawRestrictionContainer::max_value(); - } - value_type min_value() { - return _RawRestrictionContainer::min_value(); - } -}; - struct _WayIDStartAndEndEdge { unsigned wayID; NodeID firstStart; @@ -361,29 +245,6 @@ struct CmpEdgeByTargetID : public std::binary_function<_Edge, _Edge, bool> } }; -inline double ApproximateDistance( const int lat1, const int lon1, const int lat2, const int lon2 ) { - assert(lat1 != INT_MIN); - assert(lon1 != INT_MIN); - assert(lat2 != INT_MIN); - assert(lon2 != INT_MIN); - static const double DEG_TO_RAD = 0.017453292519943295769236907684886; - //Earth's quatratic mean radius for WGS-84 - static const double EARTH_RADIUS_IN_METERS = 6372797.560856; - double latitudeArc = ( lat1/100000. - lat2/100000. ) * DEG_TO_RAD; - double longitudeArc = ( lon1/100000. - lon2/100000. ) * DEG_TO_RAD; - double latitudeH = sin( latitudeArc * 0.5 ); - latitudeH *= latitudeH; - double lontitudeH = sin( longitudeArc * 0.5 ); - lontitudeH *= lontitudeH; - double tmp = cos( lat1/100000. * DEG_TO_RAD ) * cos( lat2/100000. * DEG_TO_RAD ); - double distanceArc = 2.0 * asin( sqrt( latitudeH + tmp * lontitudeH ) ); - return EARTH_RADIUS_IN_METERS * distanceArc; -} - -inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) { - return ApproximateDistance( c1.lat, c1.lon, c2.lat, c2.lon ); -} - inline string GetRandomString() { char s[128]; static const char alphanum[] = diff --git a/DataStructures/PBFParser.h b/Extractor/PBFParser.h similarity index 99% rename from DataStructures/PBFParser.h rename to Extractor/PBFParser.h index 7fb8166e1..29f5661d3 100644 --- a/DataStructures/PBFParser.h +++ b/Extractor/PBFParser.h @@ -30,9 +30,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../typedefs.h" #include "BaseParser.h" -#include "HashTable.h" #include "ExtractorStructs.h" -#include "ConcurrentQueue.h" +#include "../DataStructures/HashTable.h" +#include "../DataStructures/ConcurrentQueue.h" class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { diff --git a/Extractor/V8Helper.h b/Extractor/V8Helper.h new file mode 100644 index 000000000..e6a67cd08 --- /dev/null +++ b/Extractor/V8Helper.h @@ -0,0 +1,105 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +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 V8HELPER_H_ +#define V8HELPER_H_ + +//Most of the stuff below is from http://blog.owned.co.za provided with an MIT License + +template +v8::Handle WrapClass(T* y) { + // Handle scope for temporary handles, + v8::HandleScope handle_scope; + v8::Persistent class_template_; + + v8::Handle raw_template = v8::ObjectTemplate::New(); + + //The raw template is the ObjectTemplate (that can be exposed to script too) + //but is maintained internally. + raw_template->SetInternalFieldCount(1); + + //Create the actual template object, + class_template_ = v8::Persistent::New(raw_template); + + //Create the new handle to return, and set its template type + v8::Handle result = class_template_->NewInstance(); + v8::Handle class_ptr = v8::External::New(static_cast(y)); + + //Point the 0 index Field to the c++ pointer for unwrapping later + result->SetInternalField(0, class_ptr); + + //Return the value, releasing the other handles on its way. + return handle_scope.Close(result); +} + + +template +v8::Handle ExposeClass(v8::Persistent context, T* y, v8::Handle exposedName, v8::PropertyAttribute props) { + v8::HandleScope handle_scope; + + v8::Handle obj = WrapClass(y); + context->Global()->Set(exposedName, obj, props); + + return handle_scope.Close(obj); +} + +template +T* UnwrapClass(v8::Handle obj) { + v8::Handle field = v8::Handle::Cast(obj->GetInternalField(0)); + void* ptr = field->Value(); + return static_cast(ptr); +} + +void Expose(v8::Handle intoObject, v8::Handle namev8String, v8::InvocationCallback funcID) { + v8::HandleScope handle_scope; + + v8::Handle thisFunc = v8::FunctionTemplate::New(funcID); + intoObject->Set(namev8String, thisFunc->GetFunction()); +} + +template +v8::Handle GetMember(v8::Local property, const v8::AccessorInfo &info) { + v8::Local self = info.Holder(); + v8::Local wrap = v8::Local::Cast(self->GetInternalField(0)); + void* ptr = wrap->Value(); + int value = static_cast(ptr)->*MemVar; + return PropertyType::New(value); +} + + +template +void SetIntMember(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + v8::Local wrap = v8::Local::Cast(self->GetInternalField(0)); + void * ptr = wrap->Value(); + static_cast(ptr)->*MemVar = value->Int32Value(); +} + +template +v8::Handle GetInt(v8::Local property, const v8::AccessorInfo &info) { + v8::Local self = info.Holder(); + v8::Local wrap = v8::Local::Cast(self->GetInternalField(0)); + void* ptr = wrap->Value(); + CPPProperyType value = static_cast(ptr)->member1; + return JSPropertyType::New(value); +} + + +#endif /* V8HELPER_H_ */ diff --git a/DataStructures/XMLParser.h b/Extractor/XMLParser.h similarity index 99% rename from DataStructures/XMLParser.h rename to Extractor/XMLParser.h index 71d9b61c2..9a5538086 100644 --- a/DataStructures/XMLParser.h +++ b/Extractor/XMLParser.h @@ -25,9 +25,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../typedefs.h" #include "BaseParser.h" -#include "HashTable.h" #include "ExtractorStructs.h" -#include "InputReaderFactory.h" +#include "../DataStructures/HashTable.h" +#include "../DataStructures/InputReaderFactory.h" class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { public: diff --git a/Plugins/RawRouteData.h b/Plugins/RawRouteData.h index eeb0d98a5..f0c105486 100644 --- a/Plugins/RawRouteData.h +++ b/Plugins/RawRouteData.h @@ -21,6 +21,16 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef RAWROUTEDATA_H_ #define RAWROUTEDATA_H_ +#include "../typedefs.h" + +struct _PathData { + _PathData(NodeID no, unsigned na, unsigned tu, unsigned dur) : node(no), nameID(na), durationOfSegment(dur), turnInstruction(tu) { } + NodeID node; + unsigned nameID; + unsigned durationOfSegment; + short turnInstruction; +}; + struct RawRouteData { std::vector< _PathData > computedShortestPath; std::vector< _PathData > computedAlternativePath; diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index cbace85b3..5920a0b6e 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -31,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "ServerConfiguration.h" #include "../Util/InputFileUtil.h" -#include "../Util/OpenMPReplacement.h" +#include "../Util/OpenMPWrapper.h" typedef http::Server Server; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 5eba224a0..ef04f8d8f 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -32,9 +32,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#include "../DataStructures/ExtractorStructs.h" +#include "../DataStructures/ImportNode.h" #include "../DataStructures/ImportEdge.h" #include "../DataStructures/NodeCoords.h" +#include "../DataStructures/Restriction.h" #include "../typedefs.h" typedef boost::unordered_map ExternalNodeMap; diff --git a/Util/OpenMPWrapper.h b/Util/OpenMPWrapper.h new file mode 100644 index 000000000..232dcbd62 --- /dev/null +++ b/Util/OpenMPWrapper.h @@ -0,0 +1,34 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +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 _OPENMPREPLACEMENTY_H +#define _OPENMPREPLACEMENTY_H + +#ifdef _OPENMP +#include +#else +inline const int omp_get_num_procs() { return 1; } +inline const int omp_get_max_threads() { return 1; } +inline const int omp_get_thread_num() { return 0; } +inline const void omp_set_num_threads(int i) {} +#endif + +#endif diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 0027e8389..6024a9697 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -24,8 +24,9 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include -#include "../DataStructures/ExtractorStructs.h" +#include "../DataStructures/Coordinate.h" // precision: position after decimal point // length: maximum number of digits including comma and decimals diff --git a/createHierarchy.cpp b/createHierarchy.cpp index a3b8b7b93..f13f05b58 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -38,19 +38,18 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include "Algorithms/CRC32.h" -#include "Util/OpenMPReplacement.h" +#include "Util/OpenMPWrapper.h" #include "typedefs.h" #include "Contractor/Contractor.h" #include "Contractor/EdgeBasedGraphFactory.h" #include "DataStructures/BinaryHeap.h" #include "DataStructures/DeallocatingVector.h" -#include "DataStructures/ExtractorStructs.h" +//#include "Extractor/ExtractorStructs.h" #include "DataStructures/NNGrid.h" #include "DataStructures/QueryEdge.h" #include "Util/BaseConfiguration.h" #include "Util/InputFileUtil.h" #include "Util/GraphLoader.h" -#include "Util/OpenMPReplacement.h" using namespace std; diff --git a/extractor.cpp b/extractor.cpp index 7160b80c9..eef253867 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -44,10 +44,10 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "typedefs.h" #include "DataStructures/InputReaderFactory.h" -#include "DataStructures/ExtractorCallBacks.h" -#include "DataStructures/ExtractorStructs.h" -#include "DataStructures/PBFParser.h" -#include "DataStructures/XMLParser.h" +#include "Extractor/ExtractorCallBacks.h" +#include "Extractor/ExtractorStructs.h" +#include "Extractor/PBFParser.h" +#include "Extractor/XMLParser.h" #include "Util/BaseConfiguration.h" #include "Util/InputFileUtil.h" #include "Util/MachineInfo.h" diff --git a/routed.cpp b/routed.cpp index a9f71e23b..95e0e3129 100644 --- a/routed.cpp +++ b/routed.cpp @@ -37,7 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Plugins/ViaRoutePlugin.h" #include "Util/InputFileUtil.h" -#include "Util/OpenMPReplacement.h" +#include "Util/OpenMPWrapper.h" #ifndef _WIN32 #include "Util/LinuxStackTrace.h"