Skip to content
This repository
Browse code

Names vector of strings is now passes as reference

  • Loading branch information...
commit 60ffe55565f45c508457a99e591e2724889fa7a0 1 parent dd03c6b
authored April 14, 2012
17  DataStructures/NodeInformationHelpDesk.h
@@ -33,25 +33,26 @@ class NodeInformationHelpDesk{
33 33
 public:
34 34
     NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) {
35 35
         readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
36  
-        coordinateVector.reserve(numberOfNodes);
37 36
         assert(0 == coordinateVector.size());
38 37
     }
39 38
 
40 39
     //Todo: Shared memory mechanism
41  
-    NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) {
42  
-        readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
43  
-    }
  40
+//    NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) {
  41
+//        readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput);
  42
+//    }
44 43
 
45 44
 	~NodeInformationHelpDesk() {
46 45
 		delete readOnlyGrid;
47 46
 	}
48  
-	void initNNGrid(ifstream& in) {
  47
+	void initNNGrid(std::ifstream& in) {
  48
+		NodeInfo b;
49 49
 	    while(!in.eof()) {
50  
-			NodeInfo b;
51  
-			in.read((char *)&b, sizeof(b));
  50
+			in.read((char *)&b, sizeof(NodeInfo));
52 51
 			coordinateVector.push_back(_Coordinate(b.lat, b.lon));
53 52
 		}
54  
-		in.close();
  53
+	    std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
  54
+	    numberOfNodes = coordinateVector.size();
  55
+	    in.close();
55 56
 		readOnlyGrid->OpenIndexFiles();
56 57
 	}
57 58
 
6  DataStructures/SearchEngine.h
@@ -44,14 +44,14 @@ class SearchEngine {
44 44
 private:
45 45
 	const GraphT * _graph;
46 46
 	NodeInformationHelpDesk * nodeHelpDesk;
47  
-	std::vector<string> * _names;
  47
+	std::vector<string> & _names;
48 48
 	static HeapPtr _forwardHeap;
49 49
 	static HeapPtr _backwardHeap;
50 50
 	static HeapPtr _forwardHeap2;
51 51
 	static HeapPtr _backwardHeap2;
52 52
 	inline double absDouble(double input) { if(input < 0) return input*(-1); else return input;}
53 53
 public:
54  
-	SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> * n = new std::vector<string>()) : _graph(g), nodeHelpDesk(nh), _names(n) {}
  54
+	SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> & n) : _graph(g), nodeHelpDesk(nh), _names(n) {}
55 55
 	~SearchEngine() {}
56 56
 
57 57
 	inline const void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const {
@@ -377,7 +377,7 @@ class SearchEngine {
377 377
 	}
378 378
 
379 379
 	inline std::string GetEscapedNameForNameID(const NodeID nameID) const {
380  
-		return ((nameID >= _names->size() || nameID == 0) ? std::string("") : HTMLEntitize(_names->at(nameID)));
  380
+		return ((nameID >= _names.size() || nameID == 0) ? std::string("") : HTMLEntitize(_names.at(nameID)));
381 381
 	}
382 382
 
383 383
 	inline std::string GetEscapedNameForEdgeBasedEdgeID(const unsigned edgeID) const {
10  Plugins/ObjectForPluginStruct.h
@@ -34,7 +34,7 @@ struct ObjectsForQueryStruct {
34 34
     typedef QueryGraph::InputEdge InputEdge;
35 35
 
36 36
     NodeInformationHelpDesk * nodeHelpDesk;
37  
-    std::vector<std::string> * names;
  37
+    std::vector<std::string> names;
38 38
     QueryGraph * graph;
39 39
     unsigned checkSum;
40 40
 
@@ -61,7 +61,7 @@ struct ObjectsForQueryStruct {
61 61
         std::ifstream namesInStream(namesPath.c_str(), ios::binary);
62 62
         unsigned size(0);
63 63
         namesInStream.read((char *)&size, sizeof(unsigned));
64  
-        names = new std::vector<std::string>();
  64
+//        names = new std::vector<std::string>();
65 65
 
66 66
         char buf[1024];
67 67
         for(unsigned i = 0; i < size; ++i) {
@@ -69,16 +69,16 @@ struct ObjectsForQueryStruct {
69 69
             namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
70 70
             buf[sizeOfString] = '\0'; // instead of memset
71 71
             namesInStream.read(buf, sizeOfString);
72  
-            names->push_back(buf);
  72
+            names.push_back(buf);
73 73
         }
74  
-        std::vector<std::string>(*names).swap(*names);
  74
+        std::vector<std::string>(names).swap(names);
75 75
         hsgrInStream.close();
76 76
         namesInStream.close();
77 77
         INFO("All query data structures loaded");
78 78
     }
79 79
 
80 80
     ~ObjectsForQueryStruct() {
81  
-        delete names;
  81
+//        delete names;
82 82
         delete graph;
83 83
         delete nodeHelpDesk;
84 84
     }
5  Plugins/ViaRoutePlugin.h
@@ -47,17 +47,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
47 47
 class ViaRoutePlugin : public BasePlugin {
48 48
 private:
49 49
     NodeInformationHelpDesk * nodeHelpDesk;
50  
-    std::vector<std::string> * names;
  50
+    std::vector<std::string> & names;
51 51
     StaticGraph<EdgeData> * graph;
52 52
     HashTable<std::string, unsigned> descriptorTable;
53 53
     std::string pluginDescriptorString;
54 54
     SearchEngine<EdgeData, StaticGraph<EdgeData> > * searchEngine;
55 55
 public:
56 56
 
57  
-    ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : pluginDescriptorString(psd) {
  57
+    ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) {
58 58
         nodeHelpDesk = objects->nodeHelpDesk;
59 59
         graph = objects->graph;
60  
-        names = objects->names;
61 60
 
62 61
         searchEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);
63 62
 

0 notes on commit 60ffe55

Please sign in to comment.
Something went wrong with that request. Please try again.