Bridges-C++  3.4.1
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 
7 using namespace std;
8 
9 namespace bridges {
10  namespace dataset {
30  private:
31  double magnitude; // earthquake magnitude
32  double latit; // earthquake location
33  double longit; // (lat/long)
34  string location; // location of quake
35  string title; // combo info of quake
36  string url; // url for more info
37  string time; // date
38 
39  // access by date
40  mutable int year, month, day, hour, minu, sec; //calling min minu to bypass a VS macro
41  mutable bool date_correct;
42 
43 #ifdef _WIN32
44  //visual studio 2017 has not yet adopted the posix gmtime_r but has its platform specific gmtime_s.
45  //this function converts the call (though drops error handling)
46  void gmtime_r(time_t* eq_time, struct tm *eqt) const {
47  gmtime_s(eqt, eq_time);
48  }
49 #endif
50 
56  void getDate () const {
57  if (date_correct)
58  return;
59  // get eq's epoch time
60  string s = getTime();
61 
62  long epoch_time = std::stol(getTime());
63  time_t eq_time = epoch_time / 1000;
64 
65  // convert to time_t
66 
67  struct tm reqt;
68  struct tm *eqt = &reqt;
69  gmtime_r(&eq_time, eqt);
70 
71  year = eqt->tm_year + 1900;
72  month = eqt->tm_mon;
73  day = eqt->tm_mday;
74  hour = eqt->tm_hour;
75  sec = eqt->tm_sec;
76  minu = eqt->tm_min;
77 
78  date_correct = true;
79  }
80 
81  public:
82 
87  : magnitude(0.0), latit(0.0), longit(0.0),
88  location(""), title(""), url(""), time(""),
89  year(0), month(0), day(0), hour(0), minu(0), sec(0),
90  date_correct(false) {
91  }
92 
104  EarthquakeUSGS(double magnitude, double longit, double latit,
105  const string& location, const string& title, const string& url, const string& time)
106  : magnitude(magnitude), latit(latit), longit(longit),
107  location(location), title(title), url(url), time(time),
108  year(0), month(0), day(0), hour(0), minu(0), sec(0),
109  date_correct(false) {
110  }
111 
113  : magnitude(eq->magnitude), latit(eq->latit), longit(eq->longit),
114  location(eq->location), title(eq->title), url(eq->url), time(eq->time),
115  year(0), month(0), day(0), hour(0), minu(0), sec(0),
116  date_correct(false) {
117  }
118 
125  string getTime() const {
126  return time;
127  }
128 
129 
135  string getDateStr() const {
136  getDate();
137  string mstr;
138 
139  switch (month) {
140  case 0 :
141  mstr = "Jan. ";
142  break;
143  case 1 :
144  mstr = "Feb. ";
145  break;
146  case 2 :
147  mstr = "Mar. ";
148  break;
149  case 3 :
150  mstr = "Apr. ";
151  break;
152  case 4 :
153  mstr = "May ";
154  break;
155  case 5 :
156  mstr = "Jun. ";
157  break;
158  case 6 :
159  mstr = "Jul. ";
160  break;
161  case 7 :
162  mstr = "Aug. ";
163  break;
164  case 8 :
165  mstr = "Sept. ";
166  break;
167  case 9 :
168  mstr = "Oct. ";
169  break;
170  case 10 :
171  mstr = "Nov. ";
172  break;
173  case 11 :
174  mstr = "Dec. ";
175  break;
176  default :
177  mstr = "???. ";
178  break;
179  }
180 
181  // put into a string
182  string date_str = " " + mstr + to_string(day) + " " + to_string(year) +
183  " " + to_string(hour) + ":" + to_string(minu) + ":" + to_string(sec);
184 
185  return date_str;
186  }
187 
194  void setTime (const string& tm) {
195  // process tm to convert to a date
196  time = tm;
197  date_correct = false;
198  }
199 
205  int getYear() const {
206  getDate();
207 
208  return year;
209  }
215  int getMonth() const {
216  getDate();
217 
218  return month;
219  }
225  int getDay() const {
226  getDate();
227 
228  return day;
229  }
235  int getHour() const {
236  getDate();
237 
238  return hour;
239  }
245  int getMinutes() const {
246  getDate();
247 
248  return minu;
249  }
255  int getSeconds() const {
256  getDate();
257 
258  return sec;
259  }
260 
266  float getLatit() const {
267  return (float) this->latit;
268  }
274  void setLatit(float latit) {
275  this->latit = latit;
276  }
282  float getLongit() const {
283  return (float) longit;
284  }
290  void setLongit(float longit) {
291  this->longit = longit;
292  }
300  string getLocation() const {
301  return location;
302  }
308  void setLocation(string location) {
309  this->location = location;
310  }
318  string getTitle() const {
319  return this->title;
320  }
326  void setTitle(const string& title) {
327  this->title = title;
328  }
334  string getUrl() const {
335  return url;
336  }
337 
344  void setUrl(const string& url) {
345  this->url = url;
346  }
352  double getMagnitude() const {
353  return this->magnitude;
354  }
360  void setMagnitude(double magnitude) {
361  this->magnitude = magnitude;
362  }
363  };
364  }
365 } // namespace bridges
366 
367 #endif
float getLongit() const
get longitude of quake location
Definition: EarthquakeUSGS.h:282
int getSeconds() const
get seconds of quake
Definition: EarthquakeUSGS.h:255
int getMinutes() const
get minutes of quake
Definition: EarthquakeUSGS.h:245
string getLocation() const
get quake location.
Definition: EarthquakeUSGS.h:300
EarthquakeUSGS()
Definition: EarthquakeUSGS.h:86
string getTitle() const
get quake title
Definition: EarthquakeUSGS.h:318
EarthquakeUSGS(double magnitude, double longit, double latit, const string &location, const string &title, const string &url, const string &time)
Definition: EarthquakeUSGS.h:104
string getTime() const
return the epoch time of the quake
Definition: EarthquakeUSGS.h:125
float getLatit() const
get latitude of quake
Definition: EarthquakeUSGS.h:266
int getYear() const
get year of quake
Definition: EarthquakeUSGS.h:205
void setLongit(float longit)
set longitude of quake location
Definition: EarthquakeUSGS.h:290
int getMonth() const
get month of quake
Definition: EarthquakeUSGS.h:215
void setLocation(string location)
set quake location (string)
Definition: EarthquakeUSGS.h:308
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
void setUrl(const string &url)
set quake url
Definition: EarthquakeUSGS.h:344
int getHour() const
get hour of quake
Definition: EarthquakeUSGS.h:235
void setLatit(float latit)
set latitude
Definition: EarthquakeUSGS.h:274
void setMagnitude(double magnitude)
set quake magnitude
Definition: EarthquakeUSGS.h:360
int getDay() const
get day of quake
Definition: EarthquakeUSGS.h:225
string getDateStr() const
returns the real date in a string format
Definition: EarthquakeUSGS.h:135
void setTime(const string &tm)
set epoch time
Definition: EarthquakeUSGS.h:194
void setTitle(const string &title)
set quake title
Definition: EarthquakeUSGS.h:326
Class that hold earthquake data, for use with USGIS retrieved quake data.
Definition: EarthquakeUSGS.h:29
string getUrl() const
get quake url
Definition: EarthquakeUSGS.h:334
double getMagnitude() const
get quake magnitude
Definition: EarthquakeUSGS.h:352
EarthquakeUSGS(const EarthquakeUSGS *eq)
Definition: EarthquakeUSGS.h:112