Bridges-C++  3.1.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 {
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 
76  : magnitude(0.0), latit(0.0), longit(0.0),
77  location(""), title(""), url(""), time(""),
78  year(0), month(0), day(0), hour(0), minu(0), sec(0),
79  date_correct(false) {
80  }
81 
82  EarthquakeUSGS(double magnitude, double longit, double latit,
83  const string& location, const string& title, const string& url, const string& time)
84  : magnitude(magnitude), latit(latit), longit(longit),
85  location(location), title(title), url(url), time(time),
86  year(0), month(0), day(0), hour(0), minu(0), sec(0),
87  date_correct(false) {
88  }
89 
91  : magnitude(eq->magnitude), latit(eq->latit), longit(eq->longit),
92  location(eq->location), title(eq->title), url(eq->url), time(eq->time),
93  year(0), month(0), day(0), hour(0), minu(0), sec(0),
94  date_correct(false) {
95  }
96 
103  string getTime() const {
104  return time;
105  }
106 
107 
113  string getDateStr() const {
114  getDate();
115  string mstr;
116 
117  switch (month) {
118  case 0 :
119  mstr = "Jan. ";
120  break;
121  case 1 :
122  mstr = "Feb. ";
123  break;
124  case 2 :
125  mstr = "Mar. ";
126  break;
127  case 3 :
128  mstr = "Apr. ";
129  break;
130  case 4 :
131  mstr = "May ";
132  break;
133  case 5 :
134  mstr = "Jun. ";
135  break;
136  case 6 :
137  mstr = "Jul. ";
138  break;
139  case 7 :
140  mstr = "Aug. ";
141  break;
142  case 8 :
143  mstr = "Sept. ";
144  break;
145  case 9 :
146  mstr = "Oct. ";
147  break;
148  case 10 :
149  mstr = "Nov. ";
150  break;
151  case 11 :
152  mstr = "Dec. ";
153  break;
154  default :
155  mstr = "???. ";
156  break;
157  }
158 
159  // put into a string
160  string date_str = " " + mstr + to_string(day) + " " + to_string(year) +
161  " " + to_string(hour) + ":" + to_string(minu) + ":" + to_string(sec);
162 
163  return date_str;
164  }
165 
172  void setTime (const string& tm) {
173  // process tm to convert to a date
174  time = tm;
175  date_correct = false;
176  }
177 
183  int getYear() const {
184  getDate();
185 
186  return year;
187  }
193  int getMonth() const {
194  getDate();
195 
196  return month;
197  }
203  int getDay() const {
204  getDate();
205 
206  return day;
207  }
213  int getHour() const {
214  getDate();
215 
216  return hour;
217  }
223  int getMinutes() const {
224  getDate();
225 
226  return minu;
227  }
233  int getSeconds() const {
234  getDate();
235 
236  return sec;
237  }
238 
244  float getLatit() const {
245  return (float) this->latit;
246  }
252  void setLatit(float latit) {
253  this->latit = latit;
254  }
260  float getLongit() const {
261  return (float) longit;
262  }
268  void setLongit(float longit) {
269  this->longit = longit;
270  }
278  string getLocation() const {
279  return location;
280  }
286  void setLocation(string location) {
287  this->location = location;
288  }
296  string getTitle() const {
297  return this->title;
298  }
304  void setTitle(const string& title) {
305  this->title = title;
306  }
312  string getUrl() const {
313  return url;
314  }
315 
322  void setUrl(const string& url) {
323  this->url = url;
324  }
330  double getMagnitude() const {
331  return this->magnitude;
332  }
338  void setMagnitude(double magnitude) {
339  this->magnitude = magnitude;
340  }
341  };
342  }
343 } // namespace bridges
344 
345 #endif
float getLongit() const
get longitude of quake location
Definition: EarthquakeUSGS.h:260
int getSeconds() const
get seconds of quake
Definition: EarthquakeUSGS.h:233
int getMinutes() const
get minutes of quake
Definition: EarthquakeUSGS.h:223
string getLocation() const
get quake location.
Definition: EarthquakeUSGS.h:278
EarthquakeUSGS()
Definition: EarthquakeUSGS.h:75
STL namespace.
string getTitle() const
get quake title
Definition: EarthquakeUSGS.h:296
EarthquakeUSGS(double magnitude, double longit, double latit, const string &location, const string &title, const string &url, const string &time)
Definition: EarthquakeUSGS.h:82
string getTime() const
return the epoch time of the quake
Definition: EarthquakeUSGS.h:103
float getLatit() const
get latitude of quake
Definition: EarthquakeUSGS.h:244
int getYear() const
get year of quake
Definition: EarthquakeUSGS.h:183
void setLongit(float longit)
set longitude of quake location
Definition: EarthquakeUSGS.h:268
int getMonth() const
get month of quake
Definition: EarthquakeUSGS.h:193
void setLocation(string location)
set quake location (string)
Definition: EarthquakeUSGS.h:286
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:322
int getHour() const
get hour of quake
Definition: EarthquakeUSGS.h:213
void setLatit(float latit)
set latitude
Definition: EarthquakeUSGS.h:252
void setMagnitude(double magnitude)
set quake magnitude
Definition: EarthquakeUSGS.h:338
int getDay() const
get day of quake
Definition: EarthquakeUSGS.h:203
string getDateStr() const
returns the real date in a string format
Definition: EarthquakeUSGS.h:113
void setTime(const string &tm)
set epoch time
Definition: EarthquakeUSGS.h:172
void setTitle(const string &title)
set quake title
Definition: EarthquakeUSGS.h:304
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:312
double getMagnitude() const
get quake magnitude
Definition: EarthquakeUSGS.h:330
EarthquakeUSGS(const EarthquakeUSGS *eq)
Definition: EarthquakeUSGS.h:90