-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.h
More file actions
95 lines (69 loc) · 2.08 KB
/
Parser.h
File metadata and controls
95 lines (69 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef PARSER_H
#define PARSER_H
#include <cstdlib>
#include <string>
#include <fstream>
#include <iostream>
#include <vector>
#include "Location.h"
using namespace std;
vector<Location*> locationParser(string filename, vector<Route*> routes){
fstream locations(filename.c_str());
string country;
string city;
string latitude;
string longitude;
vector<Location*> cities;
Location* node;
while(locations.good()){
getline(locations, country, ',');
getline(locations, city, ',');
getline(locations, latitude, ',');
getline(locations, longitude);
//cout << "Country:" << country << " City:" << city << " Lat:" << latitude << " Lon:" << longitude << endl << endl << endl;
node = new Location(country, city, atof(latitude.c_str()), atof(longitude.c_str()));
vector<Route*>::iterator it = routes.begin();
while(it != routes.end()){
if((*it) -> originS.compare(node -> capital) == 0){
(*it) -> origin = node;
node -> routes.push_back((*it));
}
else if((*it) -> destinationS.compare(node -> capital) == 0){
(*it) -> destination = node;
}
++it;
}
cities.push_back(node);
}
cout << "Cities Parsed from: " << filename << endl;
return cities;
}
vector<Route*> routeParser(string filename){
fstream routes(filename.c_str());
string originS;
string destinationS;
Location* origin = new Location();
Location* destination = new Location();
string type;
string time;
string cost;
string note;
vector<Route*> allRoutes;
Route* edge;
while(routes.good()){
getline(routes, originS, ',');
getline(routes, destinationS, ',');
getline(routes, type, ',');
getline(routes, time, ',');
getline(routes, cost, ',');
getline(routes, note);
//cout << "Origin: " << originS << " Destination: " << destinationS << "---" << type << " " << time << " " << cost << " " << endl;
edge = new Route(origin, destination, type, atof(time.c_str()), atof(cost.c_str()), note);
edge -> destinationS = destinationS;
edge -> originS = originS;
allRoutes.push_back(edge);
}
cout << "Routes Parsed from: " << filename << endl;
return allRoutes;
}
#endif