-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSegmentMapper.cpp
109 lines (95 loc) · 2.17 KB
/
SegmentMapper.cpp
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
#include "provided.h"
#include "MyMap.h"
#include <vector>
#include "support.h"
using namespace std;
class SegmentMapperImpl
{
public:
SegmentMapperImpl();
~SegmentMapperImpl();
void init(const MapLoader& ml);
vector<StreetSegment> getSegments(const GeoCoord& gc) const;
private:
MyMap<GeoCoord, vector<StreetSegment>> segmentMap;
};
SegmentMapperImpl::SegmentMapperImpl()
{
}
SegmentMapperImpl::~SegmentMapperImpl()
{
}
void SegmentMapperImpl::init(const MapLoader& ml)
{
for (int i = 0; i < ml.getNumSegments(); i++)
{
StreetSegment s;
ml.getSegment(i, s);
GeoCoord geoStart(s.segment.start.latitudeText, s.segment.start.longitudeText);
auto it = segmentMap.find(geoStart); //start coord
if (it == nullptr)
{
vector<StreetSegment> vs;
vs.push_back(s);
segmentMap.associate(geoStart, vs);
}
else
{
it->push_back(s);
}
GeoCoord geoEnd(s.segment.end.latitudeText, s.segment.end.longitudeText);
it = segmentMap.find(geoEnd); //end coord
if (it == nullptr)
{
vector<StreetSegment> vs;
vs.push_back(s);
segmentMap.associate(geoEnd, vs);
}
else
{
it->push_back(s);
}
for (int j = 0; j < s.attractions.size(); j++)
{
GeoCoord attractGeo(s.attractions[j].geocoordinates.latitudeText, s.attractions[j].geocoordinates.longitudeText);
it = segmentMap.find(attractGeo);
if (it == nullptr)
{
vector<StreetSegment> vs;
vs.push_back(s);
segmentMap.associate(attractGeo, vs);
}
else
{
it->push_back(s);
}
}
}
}
vector<StreetSegment> SegmentMapperImpl::getSegments(const GeoCoord& gc) const
{
vector<StreetSegment> vs;
auto it = segmentMap.find(gc);
if (it == nullptr)
return vs;
return *it;
}
//******************** SegmentMapper functions ********************************
// These functions simply delegate to SegmentMapperImpl's functions.
// You probably don't want to change any of this code.
SegmentMapper::SegmentMapper()
{
m_impl = new SegmentMapperImpl;
}
SegmentMapper::~SegmentMapper()
{
delete m_impl;
}
void SegmentMapper::init(const MapLoader& ml)
{
m_impl->init(ml);
}
vector<StreetSegment> SegmentMapper::getSegments(const GeoCoord& gc) const
{
return m_impl->getSegments(gc);
}