Bridges-C++  3.2.0
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 {
22  private:
23  double magnitude; // earthquake magnitude
24  double latit; // earthquake location
25  double longit; // (lat/long)
26  string location; // location of quake
27  string title; // combo info of quake
28  string url; // url for more info
29  string time; // date
30 
31  // access by date
32  mutable int year, month, day, hour, minu, sec; //calling min minu to bypass a VS macro
33  mutable bool date_correct;
34 
35 #ifdef _WIN32
36  //visual studio 2017 has not yet adopted the posix gmtime_r but has its platform specific gmtime_s.
37  //this function converts the call (though drops error handling)
38  void gmtime_r(time_t* eq_time, struct tm *eqt) const {
39  gmtime_s(eqt, eq_time);
40  }
41 #endif
42 
48  void getDate () const {
49  if (date_correct)
50  return;
51  // get eq's epoch time
52  string s = getTime();
53 
54  long epoch_time = std::stol(getTime());
55  time_t eq_time = epoch_time / 1000;
56 
57  // convert to time_t
58 
59  struct tm reqt;
60  struct tm *eqt = &reqt;
61  gmtime_r(&eq_time, eqt);
62 
63  year = eqt->tm_year + 1900;
64  month = eqt->tm_mon;
65  day = eqt->tm_mday;
66  hour = eqt->tm_hour;
67  sec = eqt->tm_sec;
68  minu = eqt->tm_min;
69 
70  date_correct = true;
71  }
72 
73  public:
74 
79  : magnitude(0.0), latit(0.0), longit(0.0),
80  location(""), title(""), url(""), time(""),
81  year(0), month(0), day(0), hour(0), minu(0), sec(0),
82  date_correct(false) {
83  }
84 
96  EarthquakeUSGS(double magnitude, double longit, double latit,
97  const string& location, const string& title, const string& url, const string& time)
98  : magnitude(magnitude), latit(latit), longit(longit),
99  location(location), title(title), url(url), time(time),
100  year(0), month(0), day(0), hour(0), minu(0), sec(0),
101  date_correct(false) {
102  }
103 
105  : magnitude(eq->magnitude), latit(eq->latit), longit(eq->longit),
106  location(eq->location), title(eq->title), url(eq->url), time(eq->time),
107  year(0), month(0), day(0), hour(0), minu(0), sec(0),
108  date_correct(false) {
109  }
110 
117  string getTime() const {
118  return time;
119  }
120 
121 
127  string getDateStr() const {
128  getDate();
129  string mstr;
130 
131  switch (month) {
132  case 0 :
133  mstr = "Jan. ";
134  break;
135  case 1 :
136  mstr = "Feb. ";
137  break;
138  case 2 :
139  mstr = "Mar. ";
140  break;
141  case 3 :
142  mstr = "Apr. ";
143  break;
144  case 4 :
145  mstr = "May ";
146  break;
147  case 5 :
148  mstr = "Jun. ";
149  break;
150  case 6 :
151  mstr = "Jul. ";
152  break;
153  case 7 :
154  mstr = "Aug. ";
155  break;
156  case 8 :
157  mstr = "Sept. ";
158  break;
159  case 9 :
160  mstr = "Oct. ";
161  break;
162  case 10 :
163  mstr = "Nov. ";
164  break;
165  case 11 :
166  mstr = "Dec. ";
167  break;
168  default :
169  mstr = "???. ";
170  break;
171  }
172 
173  // put into a string
174  string date_str = " " + mstr + to_string(day) + " " + to_string(year) +
175  " " + to_string(hour) + ":" + to_string(minu) + ":" + to_string(sec);
176 
177  return date_str;
178  }
179 
186  void setTime (const string& tm) {
187  // process tm to convert to a date
188  time = tm;
189  date_correct = false;
190  }
191 
197  int getYear() const {
198  getDate();
199 
200  return year;
201  }
207  int getMonth() const {
208  getDate();
209 
210  return month;
211  }
217  int getDay() const {
218  getDate();
219 
220  return day;
221  }
227  int getHour() const {
228  getDate();
229 
230  return hour;
231  }
237  int getMinutes() const {
238  getDate();
239 
240  return minu;
241  }
247  int getSeconds() const {
248  getDate();
249 
250  return sec;
251  }
252 
258  float getLatit() const {
259  return (float) this->latit;
260  }
266  void setLatit(float latit) {
267  this->latit = latit;
268  }
274  float getLongit() const {
275  return (float) longit;
276  }
282  void setLongit(float longit) {
283  this->longit = longit;
284  }
292  string getLocation() const {
293  return location;
294  }
300  void setLocation(string location) {
301  this->location = location;
302  }
310  string getTitle() const {
311  return this->title;
312  }
318  void setTitle(const string& title) {
319  this->title = title;
320  }
326  string getUrl() const {
327  return url;
328  }
329 
336  void setUrl(const string& url) {
337  this->url = url;
338  }
344  double getMagnitude() const {
345  return this->magnitude;
346  }
352  void setMagnitude(double magnitude) {
353  this->magnitude = magnitude;
354  }
355  };
356  }
357 } // namespace bridges
358 
359 #endif
float getLongit() const
get longitude of quake location
Definition: EarthquakeUSGS.h:274
int getSeconds() const
get seconds of quake
Definition: EarthquakeUSGS.h:247
int getMinutes() const
get minutes of quake
Definition: EarthquakeUSGS.h:237
string getLocation() const
get quake location.
Definition: EarthquakeUSGS.h:292
EarthquakeUSGS()
Definition: EarthquakeUSGS.h:78
STL namespace.
string getTitle() const
get quake title
Definition: EarthquakeUSGS.h:310
EarthquakeUSGS(double magnitude, double longit, double latit, const string &location, const string &title, const string &url, const string &time)
Definition: EarthquakeUSGS.h:96
string getTime() const
return the epoch time of the quake
Definition: EarthquakeUSGS.h:117
float getLatit() const
get latitude of quake
Definition: EarthquakeUSGS.h:258
int getYear() const
get year of quake
Definition: EarthquakeUSGS.h:197
void setLongit(float longit)
set longitude of quake location
Definition: EarthquakeUSGS.h:282
int getMonth() const
get month of quake
Definition: EarthquakeUSGS.h:207
void setLocation(string location)
set quake location (string)
Definition: EarthquakeUSGS.h:300
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:336
int getHour() const
get hour of quake
Definition: EarthquakeUSGS.h:227
void setLatit(float latit)
set latitude
Definition: EarthquakeUSGS.h:266
void setMagnitude(double magnitude)
set quake magnitude
Definition: EarthquakeUSGS.h:352
int getDay() const
get day of quake
Definition: EarthquakeUSGS.h:217
string getDateStr() const
returns the real date in a string format
Definition: EarthquakeUSGS.h:127
void setTime(const string &tm)
set epoch time
Definition: EarthquakeUSGS.h:186
void setTitle(const string &title)
set quake title
Definition: EarthquakeUSGS.h:318
Class that hold earthquake data, for use with USGIS retrieved quake data.
Definition: EarthquakeUSGS.h:21
string getUrl() const
get quake url
Definition: EarthquakeUSGS.h:326
double getMagnitude() const
get quake magnitude
Definition: EarthquakeUSGS.h:344
EarthquakeUSGS(const EarthquakeUSGS *eq)
Definition: EarthquakeUSGS.h:104