#include <htime.h>
Collaboration diagram for HTime:
Public Types | |
typedef ::timeval | timeval |
enum | TimeSpec { usec = 0, msec, seconds, minutes, hours, days, _tslast } |
enum | _CurrentTime { Curr } |
enum | _NullTime { Null } |
enum | _InvalidTime { Invalid } |
Public Member Functions | |
HTime () | |
Create time in invalid state. | |
HTime (_CurrentTime) | |
Create current time. | |
HTime (_NullTime) | |
Create null time. | |
HTime (_InvalidTime) | |
Explicitly create invalid time. | |
~HTime () | |
HTime (const HTime &h) | |
Copy:. | |
HTime & | operator= (const HTime &h) |
void | SetInvalid () |
int | IsInvalid () const |
HTime (long val, TimeSpec sp=msec) | |
Store/set value (SetCurr() for current time; others never needed):. | |
void | SetCurr () |
HTime & | operator= (_CurrentTime) |
HTime & | operator= (_InvalidTime) |
HTime & | operator= (_NullTime) |
HTime & | Set (long val, TimeSpec sp=msec) |
HTime & | SetL (int64_t val, TimeSpec sp=msec) |
void | PruneUsec () |
long | Get (TimeSpec sp) const |
long | GetR (TimeSpec sp) const |
Get integer value; result rounded at division. | |
int64_t | GetL (TimeSpec sp) const |
Get 64bit integer value; result truncated at division. | |
int64_t | GetLR (TimeSpec sp) const |
Get 64bit integer value; result rounded at division. | |
double | GetD (TimeSpec sp) const |
Get floating point value. | |
HTime & | Add (long val, TimeSpec sp=msec) |
HTime & | Sub (long val, TimeSpec sp=msec) |
HTime | operator- (const HTime &start) const |
HTime & | operator-= (const HTime &start) |
HTime | operator+ (const HTime &start) const |
HTime & | operator+= (const HTime &start) |
HTime & | operator- () |
Negative time: (Stays Invalid if invalid.). | |
HTime & | Div (int fact) |
int | operator== (const HTime &h) const |
int | operator!= (const HTime &h) const |
int | operator> (const HTime &h) const |
int | operator< (const HTime &h) const |
int | operator>= (const HTime &h) const |
int | operator<= (const HTime &h) const |
int | operator== (_InvalidTime) const |
int | operator!= (_InvalidTime) const |
int | operator== (_NullTime) const |
int | operator!= (_NullTime) const |
int | operator> (_NullTime) const |
int | operator< (_NullTime) const |
int | operator>= (_NullTime) const |
int | operator<= (_NullTime) const |
long | Elapsed (TimeSpec sp, const HTime *endtime=NULL) const |
int64_t | ElapsedL (TimeSpec sp, const HTime *endtime=NULL) const |
long | ElapsedR (TimeSpec sp, const HTime *endtime=NULL) const |
double | ElapsedD (TimeSpec sp, const HTime *endtime=NULL) const |
long | MsecElapsed (const HTime *endtime) const |
long | MsecElapsedR (const HTime *endtime) const |
long | MsecElapsed () const |
long | MsecElapsedR () const |
char * | PrintTime (char *buf, size_t len, int local=1, int with_msec=0) const |
char * | PrintElapsed (char *buf, size_t len, int with_msec=1) const |
int | ReadTime (const char *str) |
Read time specification from string. | |
Private Member Functions | |
void | _SetVal (long val, TimeSpec sp, timeval *tv) |
void | _SetValL (int64_t val, TimeSpec sp, timeval *tv) |
int64_t | _Delta (const HTime *endtime) const |
int | _DoReadTime (const char *str) |
Static Private Member Functions | |
void | _gettimeofday (timeval *tv) |
void | do_gettimeofday (timeval *tv) |
void | _Normalize (timeval *tv) |
int64_t | _LLConv (const timeval *tv) |
int64_t | _RoundAdd (int64_t x, TimeSpec sp) |
long | _RoundAddMs (long x) |
Private Attributes | |
timeval | tv |
Used to store the time. (Note the typedef!). | |
Static Private Attributes | |
const int64_t | conv_fact [] |
const int64_t | round_delta [] |
const double | conv_factD [] |
This is from HLib (GPL (c) Wolfgang Wieser), hence the name HTime.
Definition at line 60 of file htime.h.
|
Definition at line 80 of file htime.h. Referenced by _Delta(), _gettimeofday(), _LLConv(), _Normalize(), _SetVal(), _SetValL(), Add(), do_gettimeofday(), MsecElapsed(), MsecElapsedR(), and Sub(). |
|
|
|
|
|
|
|
|
|
Create time in invalid state.
Definition at line 132 of file htime.h. References tv. |
|
Create current time.
Definition at line 134 of file htime.h. References SetCurr(). |
|
Create null time.
Definition at line 136 of file htime.h. References tv. |
|
Explicitly create invalid time.
Definition at line 138 of file htime.h. References tv. |
|
|
|
Copy:.
Definition at line 148 of file htime.h. References tv. |
|
Store/set value (SetCurr() for current time; others never needed):.
|
|
Definition at line 126 of file htime.cc. References do_gettimeofday(), timeval, and tv. Referenced by Elapsed(), ElapsedD(), ElapsedL(), and ElapsedR(). |
|
Definition at line 342 of file htime.cc. References tv. Referenced by ReadTime(). |
|
Definition at line 86 of file htime.h. Referenced by do_gettimeofday(). |
|
Definition at line 121 of file htime.h. References timeval. |
|
Definition at line 113 of file htime.h. References timeval. Referenced by Add(), Div(), operator+(), operator+=(), operator-(), operator-=(), and Sub(). |
|
Definition at line 123 of file htime.h. References round_delta. Referenced by ElapsedR(), GetLR(), and GetR(). |
|
Definition at line 125 of file htime.h. Referenced by MsecElapsedR(). |
|
Definition at line 44 of file htime.cc. References days, hours, minutes, msec, seconds, timeval, and usec. Referenced by _SetValL(), Add(), HTime(), Set(), and Sub(). |
|
Definition at line 71 of file htime.cc. References _SetVal(), msec, seconds, timeval, and usec. Referenced by SetL(). |
|
Arithmetics: (val may be <0) These don't do anything if time is invalid. Definition at line 98 of file htime.cc. References _Normalize(), _SetVal(), IsInvalid(), timeval, and tv. |
|
Some more arithmetics useful for elapsed time: Divide time by passed factor (e.g. for averaging). Does nothing if time is invalid. fact<0 is allowed; fact=0 yields do invalid time. Definition at line 240 of file htime.cc. References _Normalize(), IsInvalid(), SetInvalid(), and tv. |
|
Definition at line 94 of file htime.h. References _gettimeofday(), and timeval. Referenced by _Delta(), MsecElapsed(), MsecElapsedR(), and SetCurr(). |
|
Time differences: starttime: *this; endtime: NULL=current BEWARE OF OVERFLOWS. Only call if !IsInvalid(). Note: Elapsed() -> result truncated at division ElapsedL() -> result truncated at division ElapsedR() -> result rounded at division ElapsedD() -> floating point division |
|
Definition at line 298 of file htime.h. References _Delta(), _tslast, and conv_factD. |
|
|
|
Definition at line 296 of file htime.h. References _Delta(), _RoundAdd(), _tslast, and conv_fact. |
|
Get stored time. This is only useful if HTime stores some elapsed time (e.g. consumed system time) and not a real date. Only call if !IsInvalid().
Definition at line 182 of file htime.h. References _LLConv(), _tslast, conv_fact, and tv. Referenced by main(). |
|
Get floating point value. (See Get for more info.) Definition at line 202 of file htime.h. References _LLConv(), _tslast, conv_factD, and tv. |
|
Get 64bit integer value; result truncated at division. (See Get for more info.) |
|
Get 64bit integer value; result rounded at division. (See Get for more info.) Definition at line 197 of file htime.h. References _LLConv(), _RoundAdd(), _tslast, conv_fact, and tv. |
|
Get integer value; result rounded at division. (See Get for more info.) Definition at line 187 of file htime.h. References _LLConv(), _RoundAdd(), _tslast, conv_fact, and tv. |
|
Definition at line 155 of file htime.h. References tv. Referenced by Add(), Div(), operator!=(), operator+(), operator+=(), operator-(), operator-=(), operator==(), PrintElapsed(), PrintTime(), PruneUsec(), and Sub(). |
|
Definition at line 141 of file htime.cc. References do_gettimeofday(), timeval, and tv. |
|
Faster for milliseconds: Only call if !IsInvalid(). MsecElapsed() -> result truncated at division MsecElapsedR() -> result rounded at division NEVER supply NULL as argument endtime here! There are versions which take no argument for endtime = current time Definition at line 306 of file htime.h. References tv. Referenced by _DoSortAndTest(). |
|
Definition at line 150 of file htime.cc. References do_gettimeofday(), timeval, and tv. |
|
Definition at line 309 of file htime.h. References _RoundAddMs(), and tv. |
|
Definition at line 268 of file htime.h. References IsInvalid(), and tv. |
|
Definition at line 264 of file htime.h. References IsInvalid(). |
|
Definition at line 245 of file htime.h. References IsInvalid(), and tv. |
|
Add time differences: Result gets invalid if either time is invalid. Definition at line 197 of file htime.cc. References _Normalize(), Invalid, IsInvalid(), and tv. |
|
Definition at line 211 of file htime.cc. References _Normalize(), IsInvalid(), SetInvalid(), and tv. |
|
Negative time: (Stays Invalid if invalid.).
Definition at line 228 of file htime.cc. References _Normalize(), IsInvalid(), and tv. |
|
Calc time differences: (*this = endtime) Result gets invalid if either time is invalid. Definition at line 166 of file htime.cc. References _Normalize(), Invalid, IsInvalid(), and tv. |
|
Definition at line 180 of file htime.cc. References _Normalize(), IsInvalid(), SetInvalid(), and tv. |
|
Definition at line 272 of file htime.h. References tv. |
|
Definition at line 251 of file htime.h. References tv. |
|
Definition at line 278 of file htime.h. References tv. |
|
Definition at line 257 of file htime.h. References tv. |
|
Definition at line 162 of file htime.h. References tv. |
|
Definition at line 161 of file htime.h. References SetInvalid(). |
|
Definition at line 160 of file htime.h. References SetCurr(). |
|
Definition at line 149 of file htime.h. References tv. |
|
Definition at line 266 of file htime.h. References IsInvalid(), and tv. |
|
Special compare functions to compare against HTime::Invalid or HTime::Null: Definition at line 262 of file htime.h. References IsInvalid(). |
|
To compare time values: NOTE: - The operator== and operator!= always return false if at least one time is invalid.
Definition at line 242 of file htime.h. References IsInvalid(), and tv. |
|
Definition at line 270 of file htime.h. References tv. |
|
Definition at line 248 of file htime.h. References tv. |
|
Definition at line 275 of file htime.h. References tv. |
|
Definition at line 254 of file htime.h. References tv. |
|
This is useful to print elapsed times: (You may use operator-() to calc elapsed time.) Must pass buffer to store time as first argument; its length is specified by len (32 bytes is enough). Returns passed buffer. Definition at line 298 of file htime.cc. References _is_invalid_str, hours, IsInvalid(), msec, and tv. |
|
Print standard time string for local / universal time: local: 1 -> local time 0 -> universal (Greenwich) time with_msec: include msec spec Must pass buffer to store time as first argument; its length is specified by len (48 bytes is enough). Returns passed buffer. (No trailing ' Definition at line 267 of file htime.cc. References _is_invalid_str, IsInvalid(), msec, and tv. |
|
Cut off msec/usec part of the time. Does nothing if time is invalid. Definition at line 173 of file htime.h. References IsInvalid(), and tv. |
|
Read time specification from string. This can be used to read in time from a string. This is done in the following way: localtime(3) is used to get the current local time. In the string you may specify the TIME and DATE in any order separated by whitespace or comma "," (comma treated like wspace). TIME: HH:MM -> implicitly set seconds to 0 HH:MM:SS -> as usual examples: 17:23, 5:3, 06:1:02 DATE: DD.MM. -> implicitly set current year. (NOTE the trailing dot ".") DD.MM.YYYY -> be sure to use the 4 digits for the year and NOT 2-digt abbreviation YYYY/MM/DD -> ...if you like that one more You may only specify one TIME and one DATE. Only specifying the TIME will use the current date. Only specifying the DATE will use current time at specified date. Not specifying anything or just "now" or "NOW" will use the current date and time. Time offset from current time can be specified with now +|- HH:MM:SS -or- now +|- MM:SS -or- now +|- DD -or- now +|- :SS Return value: 0 -> success -1,-2 -> format error -3 -> mktime failed (time out of range) NOTE: Time can only be specified with second precision; usec (sub-second) information is set to 0. NOTE: Time spec like "Aug 10 2002" and the like will NEVER be supported by ReadTime(). One may, however, add a ReadTime2() for that case. Will set HTime::Invalid if return value is not 0. Definition at line 372 of file htime.h. References _DoReadTime(), and SetInvalid(). |
|
|
|
Definition at line 159 of file htime.h. References do_gettimeofday(), and tv. Referenced by HTime(), and operator=(). |
|
SetInvalid() sets an invalid time (currently usec=-2000000 which never happens otherwise as usec must always be >0) and IsInvalid() checks if time is invalid. Definition at line 154 of file htime.h. References tv. Referenced by Div(), operator+=(), operator-=(), operator=(), and ReadTime(). |
|
Definition at line 168 of file htime.h. References _SetValL(), and tv. |
|
Definition at line 112 of file htime.cc. References _Normalize(), _SetVal(), IsInvalid(), timeval, and tv. |
|
Initial value: { 1LL, 1000LL, 1000000LL, 60000000LL, 3600000000LL, 86400000000LL } Definition at line 24 of file htime.cc. Referenced by Elapsed(), ElapsedL(), ElapsedR(), Get(), GetL(), GetLR(), and GetR(). |
|
Initial value: { 1.0, 1000.0, 1000000.0, 60000000.0, 3600000000.0, 86400000000.0 } Definition at line 30 of file htime.cc. Referenced by ElapsedD(), and GetD(). |
|
Initial value: { 0LL, 500LL, 500000LL, 30000000LL, 1800000000LL, 43200000000LL } Definition at line 27 of file htime.cc. Referenced by _RoundAdd(). |
|
Used to store the time. (Note the typedef!).
Definition at line 111 of file htime.h. Referenced by _Delta(), _DoReadTime(), _gettimeofday(), Add(), Div(), Get(), GetD(), GetL(), GetLR(), GetR(), HTime(), IsInvalid(), MsecElapsed(), MsecElapsedR(), operator!=(), operator+(), operator+=(), operator-(), operator-=(), operator<(), operator<=(), operator=(), operator==(), operator>(), operator>=(), PrintElapsed(), PrintTime(), PruneUsec(), Set(), SetCurr(), SetInvalid(), SetL(), and Sub(). |