00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __TIME_H
00032 #define __TIME_H
00033
00034 #include <assert.h>
00035 #include "common/h/Types.h"
00036 #include "common/h/fraction.h"
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 class timeUnit {
00058 private:
00059
00060 COMMON_EXPORT static const timeUnit *_leapYear;
00061 COMMON_EXPORT static const timeUnit *_year;
00062 COMMON_EXPORT static const timeUnit *_day;
00063 COMMON_EXPORT static const timeUnit *_hour;
00064 COMMON_EXPORT static const timeUnit *_minute;
00065 COMMON_EXPORT static const timeUnit *_sec;
00066 COMMON_EXPORT static const timeUnit *_ms;
00067 COMMON_EXPORT static const timeUnit *_us;
00068 COMMON_EXPORT static const timeUnit *_ns;
00069 COMMON_EXPORT static const timeUnit *nsHelp();
00070 COMMON_EXPORT static const timeUnit *usHelp();
00071 COMMON_EXPORT static const timeUnit *msHelp();
00072 COMMON_EXPORT static const timeUnit *secHelp();
00073 COMMON_EXPORT static const timeUnit *minHelp();
00074 COMMON_EXPORT static const timeUnit *hourHelp();
00075 COMMON_EXPORT static const timeUnit *dayHelp();
00076 COMMON_EXPORT static const timeUnit *yearHelp();
00077 COMMON_EXPORT static const timeUnit *leapYearHelp();
00078 public:
00079 COMMON_EXPORT static const timeUnit &ns();
00080 COMMON_EXPORT static const timeUnit &us();
00081 COMMON_EXPORT static const timeUnit &ms();
00082 COMMON_EXPORT static const timeUnit &sec();
00083 COMMON_EXPORT static const timeUnit &minute();
00084 COMMON_EXPORT static const timeUnit &hour();
00085 COMMON_EXPORT static const timeUnit &day();
00086 COMMON_EXPORT static const timeUnit &year();
00087 COMMON_EXPORT static const timeUnit &leapYear();
00088
00089 public:
00090 typedef enum { sparse, verbose } ostream_fmt;
00091 static ostream_fmt curFmt;
00092
00093 private:
00094 fraction ns_per_unit;
00095 fraction units_per_ns;
00096
00097 public:
00098 COMMON_EXPORT timeUnit(fraction _ns_per_unit);
00099
00100
00101
00102 COMMON_EXPORT fraction get_ns_per_unit() const;
00103 COMMON_EXPORT fraction get_units_per_ns() const;
00104
00105
00106 COMMON_EXPORT void set_ns_per_unit(const fraction &nspu);
00107 COMMON_EXPORT int64_t cvtTo_ns(double units) const;
00108 COMMON_EXPORT int64_t cvtTo_ns(int64_t units) const;
00109 COMMON_EXPORT double cvtFrom_nsD(int64_t ns) const;
00110 COMMON_EXPORT int64_t cvtFrom_nsI(int64_t ns) const;
00111 };
00112
00113 COMMON_EXPORT ostream& operator<<(ostream&s, const timeUnit::ostream_fmt &u);
00114 COMMON_EXPORT ostream& operator<<(ostream&s, const timeUnit &u);
00115
00116 class timeStamp;
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 class timeBase {
00136 private:
00137
00138 COMMON_EXPORT static const timeBase *_b1970;
00139 COMMON_EXPORT static const timeBase *_bStd;
00140 COMMON_EXPORT static const timeBase *bStdHelp();
00141 COMMON_EXPORT static const timeBase *b1970Help();
00142 public:
00143
00144
00145 enum { StdBaseMark = 2000 };
00146 COMMON_EXPORT static const timeBase &bStd();
00147 COMMON_EXPORT static const timeBase &b1970();
00148
00149
00150
00151 COMMON_EXPORT static const timeBase &bNone();
00152
00153 private:
00154 int64_t ns2StdBaseMark;
00155
00156 public:
00157
00158
00159 COMMON_EXPORT timeBase(int64_t ns2stdMark);
00160 COMMON_EXPORT timeBase(timeStamp mark);
00161 COMMON_EXPORT int64_t get_ns2StdBaseMark() const;
00162 COMMON_EXPORT int64_t cvtTo_bStd(int64_t ns) const;
00163 COMMON_EXPORT double cvtFrom_bStd(double ns) const;
00164 COMMON_EXPORT int64_t cvtFrom_bStd(int64_t ns) const;
00165 };
00166
00167 COMMON_EXPORT ostream& operator<<(ostream&s, timeBase b);
00168
00169
00170
00171
00172
00173
00174
00175 class timeParent {
00176 private:
00177 COMMON_EXPORT static const int64_t uninitializedValue;
00178 int64_t ns;
00179
00180
00181 public:
00182
00183 COMMON_EXPORT int64_t get_ns() const;
00184
00185
00186 COMMON_EXPORT bool isInitialized() const;
00187
00188
00189
00190
00191
00192
00193
00194 protected:
00195 COMMON_EXPORT timeParent();
00196 COMMON_EXPORT timeParent(int64_t _ns);
00197
00198 COMMON_EXPORT void assign(const int64_t v);
00199 COMMON_EXPORT int64_t getRolloverTime(double t);
00200 };
00201
00202
00203
00204 class timeLength;
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 class timeStamp : public timeParent {
00215 private:
00216 COMMON_EXPORT static const timeStamp *_ts1800;
00217 COMMON_EXPORT static const timeStamp *_ts1970;
00218 COMMON_EXPORT static const timeStamp *_tsStd;
00219 COMMON_EXPORT static const timeStamp *_ts2200;
00220 COMMON_EXPORT static const timeStamp *ts1800Help();
00221 COMMON_EXPORT static const timeStamp *ts1970Help();
00222 COMMON_EXPORT static const timeStamp *tsStdHelp();
00223 COMMON_EXPORT static const timeStamp *ts2200Help();
00224 public:
00225 COMMON_EXPORT static const timeStamp &ts1800();
00226 COMMON_EXPORT static const timeStamp &ts1970();
00227 COMMON_EXPORT static const timeStamp &tsStd();
00228 COMMON_EXPORT static const timeStamp &ts2200();
00229 COMMON_EXPORT static const timeStamp &tsLongAgoTime();
00230 COMMON_EXPORT static const timeStamp &tsFarOffTime();
00231
00232
00233
00234 COMMON_EXPORT timeStamp();
00235
00236
00237
00238
00239
00240
00241
00242 COMMON_EXPORT timeStamp(int64_t iTime, const timeUnit &u, timeBase b);
00243 COMMON_EXPORT timeStamp(int iTime, const timeUnit &u, timeBase b);
00244 COMMON_EXPORT timeStamp(const timeLength &tl, timeBase b);
00245 COMMON_EXPORT timeStamp(double dTime, const timeUnit &u, timeBase b);
00246
00247
00248 COMMON_EXPORT double getD(const timeUnit &u, timeBase b) const;
00249
00250
00251 COMMON_EXPORT int64_t getI(const timeUnit &u, timeBase b) const;
00252
00253
00254
00255 friend COMMON_EXPORT const timeStamp operator+=(timeStamp &ts, timeLength tl);
00256 friend COMMON_EXPORT const timeStamp operator-=(timeStamp &ts, timeLength tl);
00257 friend COMMON_EXPORT const timeLength operator-(const timeStamp& a, const timeStamp& b);
00258 friend COMMON_EXPORT const timeStamp operator+(const timeStamp& a, const timeLength& b);
00259 friend COMMON_EXPORT const timeStamp operator-(const timeStamp& a, const timeLength& b);
00260 friend COMMON_EXPORT const timeStamp operator+(const timeLength& a, const timeStamp& b);
00261
00262
00263 private:
00264 COMMON_EXPORT void initI(int64_t iTime, const timeUnit &u, timeBase b);
00265 COMMON_EXPORT timeStamp(int64_t ns_);
00266 };
00267
00268 COMMON_EXPORT ostream& operator<<(ostream&s, timeStamp z);
00269
00270
00271
00272
00273
00274
00275
00276 class relTimeStamp : public timeParent {
00277 private:
00278 COMMON_EXPORT static const relTimeStamp *_Zero;
00279 COMMON_EXPORT static const relTimeStamp *ZeroHelp();
00280 public:
00281 COMMON_EXPORT static const relTimeStamp &Zero();
00282
00283
00284 COMMON_EXPORT relTimeStamp();
00285 COMMON_EXPORT relTimeStamp(int64_t iTime, const timeUnit &u);
00286 COMMON_EXPORT relTimeStamp(int iTime, const timeUnit &u);
00287 COMMON_EXPORT relTimeStamp(const timeLength &tl);
00288 COMMON_EXPORT relTimeStamp(double dTime, const timeUnit &u);
00289
00290
00291 COMMON_EXPORT double getD(const timeUnit &u) const;
00292 COMMON_EXPORT int64_t getI(const timeUnit &u) const;
00293
00294
00295 friend COMMON_EXPORT const relTimeStamp operator+=(relTimeStamp &ts, timeLength tl);
00296 friend COMMON_EXPORT const relTimeStamp operator-=(relTimeStamp &ts, timeLength tl);
00297 friend COMMON_EXPORT const timeLength operator-(const relTimeStamp& a,const relTimeStamp& b);
00298 friend COMMON_EXPORT const relTimeStamp operator+(const relTimeStamp& a, const timeLength& b);
00299 friend COMMON_EXPORT const relTimeStamp operator-(const relTimeStamp& a, const timeLength& b);
00300 friend COMMON_EXPORT const relTimeStamp operator+(const timeLength& a, const relTimeStamp& b);
00301
00302
00303 private:
00304 COMMON_EXPORT void initI(int64_t iTime, const timeUnit &u);
00305 COMMON_EXPORT relTimeStamp(int64_t ns_);
00306 };
00307
00308 COMMON_EXPORT ostream& operator<<(ostream&s, relTimeStamp z);
00309
00310
00311
00312
00313
00314
00315
00316 class timeLength : public timeParent {
00317 private:
00318
00319 COMMON_EXPORT static const timeLength *_zero;
00320 COMMON_EXPORT static const timeLength *_ns;
00321 COMMON_EXPORT static const timeLength *_us;
00322 COMMON_EXPORT static const timeLength *_ms;
00323 COMMON_EXPORT static const timeLength *_sec;
00324 COMMON_EXPORT static const timeLength *_minute;
00325 COMMON_EXPORT static const timeLength *_hour;
00326 COMMON_EXPORT static const timeLength *_day;
00327 COMMON_EXPORT static const timeLength *_year;
00328 COMMON_EXPORT static const timeLength *_leapYear;
00329 COMMON_EXPORT static const timeLength *ZeroHelp();
00330 COMMON_EXPORT static const timeLength *nsHelp();
00331 COMMON_EXPORT static const timeLength *usHelp();
00332 COMMON_EXPORT static const timeLength *msHelp();
00333 COMMON_EXPORT static const timeLength *secHelp();
00334 COMMON_EXPORT static const timeLength *minHelp();
00335 COMMON_EXPORT static const timeLength *hourHelp();
00336 COMMON_EXPORT static const timeLength *dayHelp();
00337 COMMON_EXPORT static const timeLength *yearHelp();
00338 COMMON_EXPORT static const timeLength *leapYearHelp();
00339 public:
00340 COMMON_EXPORT static const timeLength &Zero();
00341 COMMON_EXPORT static const timeLength &ns();
00342 COMMON_EXPORT static const timeLength &us();
00343 COMMON_EXPORT static const timeLength &ms();
00344 COMMON_EXPORT static const timeLength &sec();
00345 COMMON_EXPORT static const timeLength &minute();
00346 COMMON_EXPORT static const timeLength &hour();
00347 COMMON_EXPORT static const timeLength &day();
00348 COMMON_EXPORT static const timeLength &year();
00349 COMMON_EXPORT static const timeLength &leapYear();
00350
00351
00352 COMMON_EXPORT timeLength();
00353 COMMON_EXPORT timeLength(int64_t iTime, const timeUnit &u);
00354 COMMON_EXPORT timeLength(int iTime, const timeUnit &u);
00355 COMMON_EXPORT timeLength(double dTime, const timeUnit &u);
00356
00357
00358 COMMON_EXPORT double getD(const timeUnit &u) const;
00359 COMMON_EXPORT int64_t getI(const timeUnit &u) const;
00360
00361
00362
00363 friend COMMON_EXPORT const timeLength operator+=(timeLength &t, timeLength tl);
00364 friend COMMON_EXPORT const timeLength operator-=(timeLength &t, timeLength tl);
00365 friend COMMON_EXPORT const timeLength operator*=(timeLength &t, double d);
00366 friend COMMON_EXPORT const timeLength operator/=(timeLength &t, double d);
00367 friend COMMON_EXPORT const timeLength operator-(const timeLength &t);
00368 friend COMMON_EXPORT const timeLength operator-(const timeStamp& a, const timeStamp& b);
00369 friend COMMON_EXPORT const timeLength operator-(const relTimeStamp& a,const relTimeStamp& b);
00370 friend COMMON_EXPORT const timeStamp operator+(const timeStamp& a, const timeLength& b);
00371 friend COMMON_EXPORT const timeStamp operator-(const timeStamp& a, const timeLength& b);
00372 friend COMMON_EXPORT const timeStamp operator+(const timeLength& a, const timeStamp& b);
00373 friend COMMON_EXPORT const timeLength operator+(const timeLength& a, const timeLength& b);
00374 friend COMMON_EXPORT const timeLength operator-(const timeLength& a, const timeLength& b);
00375 friend COMMON_EXPORT const timeLength operator*(const timeLength& a, double b);
00376 friend COMMON_EXPORT const timeLength operator/(const timeLength& a, double b);
00377 friend COMMON_EXPORT const timeLength operator*(double a, const timeLength& b);
00378 friend COMMON_EXPORT const timeLength operator/(double a, const timeLength& b);
00379 friend COMMON_EXPORT double operator/(const timeLength& a, const timeLength& b);
00380
00381
00382 private:
00383 COMMON_EXPORT void initI(int64_t iTime, const timeUnit &u);
00384
00385 COMMON_EXPORT timeLength(int64_t ns_);
00386 };
00387
00388 COMMON_EXPORT ostream& operator<<(ostream&s, timeLength z);
00389
00390
00391 COMMON_EXPORT const timeStamp operator+=(timeStamp &ts, timeLength tl);
00392 COMMON_EXPORT const timeStamp operator-=(timeStamp &ts, timeLength tl);
00393
00394
00395 COMMON_EXPORT const timeLength operator+=(timeLength &t, timeLength tl);
00396 COMMON_EXPORT const timeLength operator-=(timeLength &t, timeLength tl);
00397
00398
00399 COMMON_EXPORT const timeLength operator*=(timeLength &t, double d);
00400 COMMON_EXPORT const timeLength operator/=(timeLength &t, double d);
00401
00402
00403 COMMON_EXPORT const timeLength operator-(const timeLength &t);
00404
00405
00406 COMMON_EXPORT const timeLength operator-(const timeStamp& a, const timeStamp& b);
00407
00408
00409 COMMON_EXPORT const timeStamp operator+(const timeStamp& a, const timeLength& b);
00410 COMMON_EXPORT const timeStamp operator-(const timeStamp& a, const timeLength& b);
00411
00412
00413 COMMON_EXPORT const timeStamp operator+(const timeLength& a, const timeStamp& b);
00414
00415
00416
00417 COMMON_EXPORT const timeLength operator+(const timeLength& a, const timeLength& b);
00418 COMMON_EXPORT const timeLength operator-(const timeLength& a, const timeLength& b);
00419
00420
00421 COMMON_EXPORT const timeLength operator*(const timeLength& a, double b);
00422 COMMON_EXPORT const timeLength operator/(const timeLength& a, double b);
00423
00424
00425 COMMON_EXPORT const timeLength operator*(double a, const timeLength& b);
00426 COMMON_EXPORT const timeLength operator/(double a, const timeLength& b);
00427
00428
00429
00430
00431
00432
00433 COMMON_EXPORT bool operator==(const timeStamp& a, const timeStamp& b);
00434 COMMON_EXPORT bool operator!=(const timeStamp& a, const timeStamp& b);
00435 COMMON_EXPORT bool operator>(const timeStamp& a, const timeStamp& b);
00436 COMMON_EXPORT bool operator>=(const timeStamp& a, const timeStamp& b);
00437 COMMON_EXPORT bool operator<(const timeStamp& a, const timeStamp& b);
00438 COMMON_EXPORT bool operator<=(const timeStamp& a, const timeStamp& b);
00439
00440 COMMON_EXPORT timeStamp earlier(const timeStamp& a, const timeStamp& b);
00441 COMMON_EXPORT timeStamp later(const timeStamp& a, const timeStamp& b);
00442
00443 COMMON_EXPORT bool operator==(const timeLength& a, const timeLength& b);
00444 COMMON_EXPORT bool operator!=(const timeLength& a, const timeLength& b);
00445 COMMON_EXPORT bool operator>(const timeLength& a, const timeLength& b);
00446 COMMON_EXPORT bool operator>=(const timeLength& a, const timeLength& b);
00447 COMMON_EXPORT bool operator<(const timeLength& a, const timeLength& b);
00448 COMMON_EXPORT bool operator<=(const timeLength& a, const timeLength& b);
00449
00450
00451 COMMON_EXPORT timeLength minimum(const timeLength& a, const timeLength& b);
00452
00453 COMMON_EXPORT timeLength maximum(const timeLength& a, const timeLength& b);
00454 COMMON_EXPORT const timeLength abs(const timeLength& a);
00455
00456
00457 COMMON_EXPORT const relTimeStamp operator+=(relTimeStamp &ts, timeLength tl);
00458 COMMON_EXPORT const relTimeStamp operator-=(relTimeStamp &ts, timeLength tl);
00459
00460
00461 COMMON_EXPORT const timeLength operator-(const relTimeStamp& a, const relTimeStamp& b);
00462
00463
00464 COMMON_EXPORT const relTimeStamp operator+(const relTimeStamp& a, const timeLength& b);
00465 COMMON_EXPORT const relTimeStamp operator-(const relTimeStamp& a, const timeLength& b);
00466
00467
00468 COMMON_EXPORT const relTimeStamp operator+(const timeLength& a, const relTimeStamp& b);
00469
00470
00471
00472
00473
00474
00475
00476
00477 COMMON_EXPORT bool operator==(const relTimeStamp& a, const relTimeStamp& b);
00478 COMMON_EXPORT bool operator!=(const relTimeStamp& a, const relTimeStamp& b);
00479 COMMON_EXPORT bool operator>(const relTimeStamp& a, const relTimeStamp& b);
00480 COMMON_EXPORT bool operator>=(const relTimeStamp& a, const relTimeStamp& b);
00481 COMMON_EXPORT bool operator<(const relTimeStamp& a, const relTimeStamp& b);
00482 COMMON_EXPORT bool operator<=(const relTimeStamp& a, const relTimeStamp& b);
00483
00484 COMMON_EXPORT relTimeStamp earlier(const relTimeStamp& a, const relTimeStamp& b);
00485
00486 COMMON_EXPORT relTimeStamp later(const relTimeStamp& a, const relTimeStamp& b);
00487
00488
00489
00490 #endif
00491