-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hotspot.h
239 lines (212 loc) · 4.44 KB
/
Hotspot.h
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifndef __HOTSPOT_H__
#define __HOTSPOT_H__
#include<iostream>
#include<stdlib.h>
#include<sstream>
#include<vector>
#include<cmath>
#include<math.h>
#include<fstream>
using namespace std;
class Hotspot
{
public:
// Default constructor ; fills fields with zeros or null strings
Hotspot (){};
// Constructor that creates Hotspot object from a hotspot file text line
Hotspot(const string dataline)
{
vector<string> info;
istringstream s(dataline);
string parsed,i;
bool success=true;
while (getline(s,parsed,','))
{
if(parsed.length()<1 || parsed[0]==' ' || parsed[parsed.length()-1]==' ' )
{
success=false;
}
else if(parsed[0]=='"')
{
i+=parsed+',';
while(parsed[parsed.length()-1]!='"')
{
if(!getline(s,parsed,','))
{
success=false;
break;
}
else if(parsed[parsed.length()-1]=='"')
{
i+=parsed;
}
else
{
i+=parsed+',';
}
}
info.push_back(i);
i="";
}
else
{
info.push_back(parsed);
}
}
if(info.size()==9 && success==true)
{
Objectid=atoi(info[0].c_str());
Borough=info[1];
Type=info[2];
Provider=info[3];
Name=info[4];
Location=info[5];
Latitude=atof(info[6].c_str());
Longitude=atof(info[7].c_str());
SSID=info[8];
}
};
// Copy constructor
Hotspot ( const Hotspot ¤t)
{
Objectid=current.Objectid;
Borough=current.Borough;
Type=current.Type;
Provider=current.Provider;
Name=current.Name;
Location=current.Location;
Latitude=current.Latitude;
Longitude=current.Longitude;
SSID=current.SSID;
};
// Constructor to create a Hotspot object from nine separate data values
Hotspot(int id,
string boro,
string type,
string prov,
string nameof,
string loc,
double lat,
double lon,
string wifiname)
{
Objectid=id;
Borough=boro;
Type=type;
Provider=prov;
Name=wifiname;
Location=loc;
Latitude=lat;
Longitude=lon;
SSID=wifiname;
};
// Sets all nine data member
void set( const int id,
const string boro,
const string type,
const string prov,
const string nameof,
const string loc,
const double lat,
const double lon,
const string wifiname)
{
Objectid=id;
Borough=boro;
Type=type;
Provider=prov;
Name=wifiname;
Location=loc;
Latitude=lat;
Longitude=lon;
SSID=wifiname;
};
//Gets all nine data members
void get( int &id ,
string &boro ,
string &type ,
string &prov ,
string &nameof ,
string &loc ,
double &lat ,
double &lon,
string &wifiname)
{
id=Objectid;
boro=Borough;
type=Type;
prov=Provider;
wifiname=Name;
loc=Location;
lat=Latitude;
lon=Longitude;
wifiname=SSID;
};
double deg2rad(double deg)
{
return (deg * M_PI / 180);
}
double rad2deg(double rad)
{
return (rad * 180 / M_PI);
}
float GetDistance(float lat2 , float lon2)
{
double lat1r, lon1r, lat2r, lon2r, u, v;
double earthRadiusMi=3959;
lat1r = deg2rad(Latitude);
lon1r = deg2rad(Longitude);
lat2r = deg2rad(lat2);
lon2r = deg2rad(lon2);
u = sin((lat2r - lat1r)/2);
v = sin((lon2r - lon1r)/2);
return 2.0 * earthRadiusMi * asin(sqrt(u * u + cos(Latitude) * cos(lat2) * v * v));
};
/** GetId() - returns the ObjectId of a given hotspot
*/
int GetId() const
{
return Objectid;
};
void p()
{
cout<<Objectid<<","<<Borough<<","<<Type<<","<<Provider<<","<<Name<<","<<Location<<","<<Latitude<<","<<Longitude<<","<<SSID<<endl;
};
void print(ofstream & o)
{
o<<Objectid<<","<<Borough<<","<<Type<<","<<Provider<<","<<Name<<","<<Location<<","<<Latitude<<","<<Longitude<<","<<SSID<<endl;
};
string GetBorough()const
{
return Borough;
};
/** Two friend comparison operators:
* bool operator < (lt , rt) is true if and only if:
* lt.ObjectId < rt.ObjectId
*bool operator == (lt , rt ) is true if and only if :
* lt.ObjectId == rt.ObjectId
*/
friend bool operator< (const Hotspot & lt , const Hotspot & rt )
{
return lt.Objectid < rt.Objectid;
};
friend bool operator> (const Hotspot & lt , const Hotspot & rt )
{
return lt.Objectid > rt.Objectid;
};
friend bool operator== (const Hotspot & lt , const Hotspot & rt )
{
return lt.Objectid == rt.Objectid;
};
private :
int Objectid;
string Borough;
string Type;
string Provider;
string Name;
string Location;
double Latitude;
double Longitude;
string SSID;
};
#endif