Bridges-C++ 3.5.0-dev2-1-ge3e57bf
Bridges(C++ API)
EarthquakeUSGS.h
Go to the documentation of this file.
1#ifndef EARTHQUAKEUSGS_H
2
3#define EARTHQUAKEUSGS_H
4
5#include <string>
6
7using namespace std;
8
9namespace bridges {
10 namespace dataset {
29 private:
30 double magnitude; // earthquake magnitude
31 double latit; // earthquake location
32 double longit; // (lat/long)
33 string location; // location of quake
34 string title; // combo info of quake
35 string url; // url for more info
36 string time; // date
37
38 // access by date
39 mutable int year, month, day, hour, minu, sec; //calling min minu to bypass a VS macro
40 mutable bool date_correct;
41
42#ifdef _WIN32
43 //visual studio 2017 has not yet adopted the posix gmtime_r but has its platform specific gmtime_s.
44 //this function converts the call (though drops error handling)
45 void gmtime_r(time_t* eq_time, struct tm *eqt) const {
46 gmtime_s(eqt, eq_time);
47 }
48#endif
49
55 void getDate () const {
56 if (date_correct)
57 return;
58 // get eq's epoch time
59 string s = getTime();
60
61 long epoch_time = std::stol(getTime());
62 time_t eq_time = epoch_time / 1000;
63
64 // convert to time_t
65
66 struct tm reqt;
67 struct tm *eqt = &reqt;
68 gmtime_r(&eq_time, eqt);
69
70 year = eqt->tm_year + 1900;
71 month = eqt->tm_mon;
72 day = eqt->tm_mday;
73 hour = eqt->tm_hour;
74 sec = eqt->tm_sec;
75 minu = eqt->tm_min;
76
77 date_correct = true;
78 }
79
80 public:
81
86 : magnitude(0.0), latit(0.0), longit(0.0),
87 location(""), title(""), url(""), time(""),
88 year(0), month(0), day(0), hour(0), minu(0), sec(0),
89 date_correct(false) {
90 }
91
103 EarthquakeUSGS(double magnitude, double longit, double latit,
104 const string& location, const string& title, const string& url, const string& time)
105 : magnitude(magnitude), latit(latit), longit(longit),
106 location(location), title(title), url(url), time(time),
107 year(0), month(0), day(0), hour(0), minu(0), sec(0),
108 date_correct(false) {
109 }
110
112 : magnitude(eq->magnitude), latit(eq->latit), longit(eq->longit),
113 location(eq->location), title(eq->title), url(eq->url), time(eq->time),
114 year(0), month(0), day(0), hour(0), minu(0), sec(0),
115 date_correct(false) {
116 }
117
124 string getTime() const {
125 return time;
126 }
127
133 string getDateStr() const {
134 getDate();
135 string mstr;
136
137 switch (month) {
138 case 0 :
139 mstr = "Jan. ";
140 break;
141 case 1 :
142 mstr = "Feb. ";
143 break;
144 case 2 :
145 mstr = "Mar. ";
146 break;
147 case 3 :
148 mstr = "Apr. ";
149 break;
150 case 4 :
151 mstr = "May ";
152 break;
153 case 5 :
154 mstr = "Jun. ";
155 break;
156 case 6 :
157 mstr = "Jul. ";
158 break;
159 case 7 :
160 mstr = "Aug. ";
161 break;
162 case 8 :
163 mstr = "Sept. ";
164 break;
165 case 9 :
166 mstr = "Oct. ";
167 break;
168 case 10 :
169 mstr = "Nov. ";
170 break;
171 case 11 :
172 mstr = "Dec. ";
173 break;
174 default :
175 mstr = "???. ";
176 break;
177 }
178
179 // put into a string
180 string date_str = " " + mstr + to_string(day) + " " + to_string(year) +
181 " " + to_string(hour) + ":" + to_string(minu) + ":" + to_string(sec);
182
183 return date_str;
184 }
185
192 void setTime (const string& tm) {
193 // process tm to convert to a date
194 time = tm;
195 date_correct = false;
196 }
197
203 int getYear() const {
204 getDate();
205
206 return year;
207 }
213 int getMonth() const {
214 getDate();
215
216 return month;
217 }
223 int getDay() const {
224 getDate();
225
226 return day;
227 }
233 int getHour() const {
234 getDate();
235
236 return hour;
237 }
243 int getMinutes() const {
244 getDate();
245
246 return minu;
247 }
253 int getSeconds() const {
254 getDate();
255
256 return sec;
257 }
258
264 float getLatit() const {
265 return (float) this->latit;
266 }
272 void setLatit(float latit) {
273 this->latit = latit;
274 }
280 float getLongit() const {
281 return (float) longit;
282 }
288 void setLongit(float longit) {
289 this->longit = longit;
290 }
298 string getLocation() const {
299 return location;
300 }
306 void setLocation(string location) {
307 this->location = location;
308 }
316 string getTitle() const {
317 return this->title;
318 }
324 void setTitle(const string& title) {
325 this->title = title;
326 }
332 string getUrl() const {
333 return url;
334 }
335
342 void setUrl(const string& url) {
343 this->url = url;
344 }
350 double getMagnitude() const {
351 return this->magnitude;
352 }
358 void setMagnitude(double magnitude) {
359 this->magnitude = magnitude;
360 }
361 };
362 }
363} // namespace bridges
364
365#endif
Class that hold earthquake data, for use with USGIS retrieved quake data.
Definition: EarthquakeUSGS.h:28
int getMonth() const
get month of quake
Definition: EarthquakeUSGS.h:213
int getMinutes() const
get minutes of quake
Definition: EarthquakeUSGS.h:243
EarthquakeUSGS()
Definition: EarthquakeUSGS.h:85
EarthquakeUSGS(const EarthquakeUSGS *eq)
Definition: EarthquakeUSGS.h:111
EarthquakeUSGS(double magnitude, double longit, double latit, const string &location, const string &title, const string &url, const string &time)
Definition: EarthquakeUSGS.h:103
string getTitle() const
get quake title
Definition: EarthquakeUSGS.h:316
int getHour() const
get hour of quake
Definition: EarthquakeUSGS.h:233
int getYear() const
get year of quake
Definition: EarthquakeUSGS.h:203
string getLocation() const
get quake location.
Definition: EarthquakeUSGS.h:298
int getDay() const
get day of quake
Definition: EarthquakeUSGS.h:223
void setLatit(float latit)
set latitude
Definition: EarthquakeUSGS.h:272
string getDateStr() const
returns the real date in a string format
Definition: EarthquakeUSGS.h:133
void setLongit(float longit)
set longitude of quake location
Definition: EarthquakeUSGS.h:288
void setLocation(string location)
set quake location (string)
Definition: EarthquakeUSGS.h:306
void setTitle(const string &title)
set quake title
Definition: EarthquakeUSGS.h:324
string getTime() const
return the epoch time of the quake
Definition: EarthquakeUSGS.h:124
float getLongit() const
get longitude of quake location
Definition: EarthquakeUSGS.h:280
string getUrl() const
get quake url
Definition: EarthquakeUSGS.h:332
void setMagnitude(double magnitude)
set quake magnitude
Definition: EarthquakeUSGS.h:358
float getLatit() const
get latitude of quake
Definition: EarthquakeUSGS.h:264
double getMagnitude() const
get quake magnitude
Definition: EarthquakeUSGS.h:350
void setUrl(const string &url)
set quake url
Definition: EarthquakeUSGS.h:342
void setTime(const string &tm)
set epoch time
Definition: EarthquakeUSGS.h:192
int getSeconds() const
get seconds of quake
Definition: EarthquakeUSGS.h:253
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4