-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAttractionMapper.cpp
More file actions
84 lines (70 loc) · 1.96 KB
/
Copy pathAttractionMapper.cpp
File metadata and controls
84 lines (70 loc) · 1.96 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
#include "provided.h"
#include "MyMap.h"
#include <cctype>
#include <string>
using namespace std;
class AttractionMapperImpl
{
public:
AttractionMapperImpl();
~AttractionMapperImpl();
void init(const MapLoader& ml);
bool getGeoCoord(string attraction, GeoCoord& gc) const;
private:
MyMap<string, GeoCoord> mymap;
};
AttractionMapperImpl::AttractionMapperImpl()
{
}
AttractionMapperImpl::~AttractionMapperImpl()
{
}
void AttractionMapperImpl::init(const MapLoader& ml)
{
//for every segment
for(int i = 0; i < ml.getNumSegments(); i++) {
StreetSegment s;
ml.getSegment(i, s);
//if there are attractions, make lower case and associate
if(s.attractions.size() > 0) {
for(int j = 0; j < s.attractions.size(); j++) {
string lowerCaseAttractionName;
for(int k = 0; k < s.attractions[j].name.length(); k++) {
lowerCaseAttractionName += tolower(s.attractions[j].name[k]);
}
mymap.associate(lowerCaseAttractionName, s.attractions[j].geocoordinates);
}
}
}
}
bool AttractionMapperImpl::getGeoCoord(string attraction, GeoCoord& gc) const
{
for(int i = 0; i < attraction.length(); i++) {
attraction[i] = tolower(attraction[i]);
}
const GeoCoord* temp = mymap.find(attraction);
if(temp == nullptr) {
return false;
}
gc = *temp;
return true;
}
//******************** AttractionMapper functions *****************************
// These functions simply delegate to AttractionMapperImpl's functions.
// You probably don't want to change any of this code.
AttractionMapper::AttractionMapper()
{
m_impl = new AttractionMapperImpl;
}
AttractionMapper::~AttractionMapper()
{
delete m_impl;
}
void AttractionMapper::init(const MapLoader& ml)
{
m_impl->init(ml);
}
bool AttractionMapper::getGeoCoord(string attraction, GeoCoord& gc) const
{
return m_impl->getGeoCoord(attraction, gc);
}