-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMapLoader.cpp
More file actions
147 lines (112 loc) · 3.04 KB
/
Copy pathMapLoader.cpp
File metadata and controls
147 lines (112 loc) · 3.04 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "provided.h"
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
class MapLoaderImpl
{
public:
MapLoaderImpl();
~MapLoaderImpl();
bool load(string mapFile);
size_t getNumSegments() const;
bool getSegment(size_t segNum, StreetSegment& seg) const;
private:
vector<StreetSegment> segVector;
};
MapLoaderImpl::MapLoaderImpl()
{
}
MapLoaderImpl::~MapLoaderImpl()
{
}
bool MapLoaderImpl::load(string mapFile)
{
ifstream infile(mapFile);
if(!infile) {
return false;
}
while(infile) {
//get streetname
string streetName;
if(!getline(infile, streetName)) {
return true;
}
string s1, s2, e1, e2;
getline(infile, s1, ',');
if(infile.peek() == ' ') {
infile.ignore(10000, ' ');
}
getline(infile, s2, ' ');
getline(infile, e1, ',');
if(infile.peek() == ' ') {
infile.ignore(10000, ' ');
}
getline(infile, e2);
GeoSegment gs(GeoCoord(s1, s2), GeoCoord(e1, e2));
//get attractions and store in attraction vector
vector<Attraction> attractionVector;
int numAttractions;
infile >> numAttractions;
infile.ignore(10000, '\n');
while(numAttractions > 0) {
//string attraction;
string attractionName;
getline(infile, attractionName, '|');
string c1, c2;
getline(infile, c1, ',');
if(infile.peek() == ' ') {
infile.ignore(10000, ' ');
}
getline(infile, c2);
Attraction a;
a.name = attractionName;
a.geocoordinates = GeoCoord(c1, c2);
attractionVector.push_back(a);
numAttractions--;
}
//create street segment vector and put it into vector
StreetSegment ss;
ss.streetName = streetName;
ss.segment = gs;
ss.attractions = attractionVector;
segVector.push_back(ss);
}
return true;
}
size_t MapLoaderImpl::getNumSegments() const
{
return segVector.size();
}
bool MapLoaderImpl::getSegment(size_t segNum, StreetSegment &seg) const
{
if(segNum >= segVector.size()) {
return false;
}
seg = segVector[segNum];
return true;
}
//******************** MapLoader functions ************************************
// These functions simply delegate to MapLoaderImpl's functions.
// You probably don't want to change any of this code.
MapLoader::MapLoader()
{
m_impl = new MapLoaderImpl;
}
MapLoader::~MapLoader()
{
delete m_impl;
}
bool MapLoader::load(string mapFile)
{
return m_impl->load(mapFile);
}
size_t MapLoader::getNumSegments() const
{
return m_impl->getNumSegments();
}
bool MapLoader::getSegment(size_t segNum, StreetSegment& seg) const
{
return m_impl->getSegment(segNum, seg);
}