#include <TimeVal.h>
Public Types | |
enum | { gmt, loc } |
Public Member Functions | |
TimeVal () | |
Default constructor. | |
TimeVal (long sec_, long msec_) | |
Constructor from seconds/microseconds pair. | |
TimeVal (double d_) | |
Constructor from double. | |
TimeVal (const timeval &tv_) | |
Constructor from struct timeval . | |
TimeVal (const TimeVal &tv_) | |
Copy constructor. | |
operator double () const | |
Implicit conversion to double. | |
void | sec (long sec_) |
Set seconds. | |
long | sec (void) const |
Get secons. | |
void | msec (long msec_) |
Set microseconds. | |
long | msec (void) const |
Get microseconds. | |
long | millisec () const |
Convert tv_usec's microseconds (=1/1,000,000 sec) to milliseconds (=1/1,000 sec). | |
void | tz (int tz_) |
Set timezone. | |
int | tz (void) const |
Get timezone. | |
TimeVal & | operator= (const TimeVal &tv_) |
TimeVal & | operator+= (const TimeVal &rhs_) |
Addition. | |
TimeVal & | operator-= (const TimeVal &rhs_) |
Substraction. | |
bool | operator< (const TimeVal &rhs_) const |
Comparison. | |
bool | operator== (const TimeVal &rhs_) const |
Equality. | |
string | fmtString (const char *fmt_=NULL) const |
Format timeval structure into readable format. | |
string | fmt_hh_mm_ss () const |
Format timeval structure in readable format HH:MM:SS. | |
string | fmt_hh_mm_ss_mls () const |
Format timeval structure in readable format HH:MM:SS.MLS. | |
string | fmt_mm_ss () const |
Format timeval structure in readable format MM:SS. | |
string | fmt_mm_ss_mls () const |
Format timeval structure in readable format MM:SS.MLS. | |
string | fmt_ss_mls () const |
Format timeval structure in readable format SS.MLS. | |
void | dump_to_log (const string &name_="") const |
Dump value of struct timeval to the log file with mask TRACE = DBG_APP15. | |
Static Public Member Functions | |
static TimeVal | zeroTime () |
Static that returns zero timeval: {0,0}. | |
static TimeVal | gettimeofday () |
Shields off underlying OS differences in getting current time. | |
Protected Member Functions | |
void | init (long, long, int) |
Internal initialization common to most constructors. | |
Private Member Functions | |
void | normalize () |
Normalization after arithmetic operation. | |
Private Attributes | |
int | m_tz |
Time zone. | |
Static Private Attributes | |
static TimeVal | m_zero |
Zero time value. | |
Friends | |
TimeVal | operator+ (const TimeVal &lhs_, const TimeVal &rhs_) |
Addition. | |
TimeVal | operator- (const TimeVal &lhs_, const TimeVal &rhs_) |
Substraction. | |
bool | operator> (const TimeVal &lhs_, const TimeVal &rhs_) |
Comparison. | |
bool | operator!= (const TimeVal &lhs_, const TimeVal &rhs_) |
Comparison. | |
bool | operator<= (const TimeVal &lhs_, const TimeVal &rhs_) |
Comparison. | |
bool | operator>= (const TimeVal &lhs_, const TimeVal &rhs_) |
Comparison. |
Definition at line 30 of file TimeVal.h.
|
Definition at line 33 of file TimeVal.h.
|
|
Default constructor. Sets time to 0 sec. 0 usecs. To get current time, use TimeVal (gettimeofday()); Definition at line 196 of file TimeVal.h.
|
|
Constructor from seconds/microseconds pair.
Definition at line 203 of file TimeVal.h.
|
|
Constructor from double.
Definition at line 210 of file TimeVal.h. References normalize(). 00211 : m_tz (gmt) 00212 { 00213 long l = long(d_); 00214 tv_sec = l; 00215 tv_usec = (long) ((d_ - double(l))*1000000.0); 00216 normalize(); 00217 }
|
|
Constructor from
Definition at line 221 of file TimeVal.h.
|
|
Copy constructor.
Definition at line 228 of file TimeVal.h. 00229 { 00230 init (tv_.tv_sec, tv_.tv_usec, tv_.m_tz); 00231 }
|
|
Dump value of struct timeval to the log file with mask TRACE = DBG_APP15.
Definition at line 188 of file TimeVal.cpp. References DL, fmt_mm_ss_mls(), ASSA::Singleton< Logger >::get_instance(), millisec(), msec(), ASSA::REACT, sec(), and trace. 00189 { 00190 static const char self []="TimeVal::dump_to_log"; trace(self); 00191 00192 if (Logger::get_instance ()->group_enabled (REACT)) 00193 { 00194 DL((REACT,"=== TimeVal %s ===\n", var_name_.c_str ())); 00195 DL((REACT,"MM:SS:MLS = %s\n", fmt_mm_ss_mls ().c_str ())); 00196 DL((REACT,"tv_sec = %d, tv_msec = %d, tv_mls = %d\n", 00197 sec (), msec (), millisec ())); 00198 DL((REACT,"(double) = %7.4f\n", double (*this))); 00199 DL((REACT,"==================\n")); 00200 } 00201 }
|
|
Format timeval structure in readable format HH:MM:SS.
Definition at line 257 of file TimeVal.h. References fmtString(). 00258 { 00259 return fmtString ("%T"); 00260 }
|
|
Format timeval structure in readable format HH:MM:SS.MLS.
Definition at line 131 of file TimeVal.cpp. References gmt, m_tz, and millisec(). 00132 { 00133 struct tm ct; 00134 char buf [80]; 00135 memset (buf, 0, 80); 00136 00137 if (m_tz == gmt) 00138 ct = *( localtime ((const time_t*) &tv_sec) ); 00139 else 00140 ct = *( gmtime ((const time_t*) &tv_sec) ); 00141 00142 strftime (buf, 80, "%H:%M:%S", &ct); 00143 sprintf (buf + strlen(buf), ".%03ld", millisec ()); 00144 00145 return string (buf); 00146 }
|
|
Format timeval structure in readable format MM:SS.
Definition at line 264 of file TimeVal.h. References fmtString(). 00265 { 00266 return fmtString ("%M:%S"); 00267 }
|
|
Format timeval structure in readable format MM:SS.MLS.
Definition at line 150 of file TimeVal.cpp. References gmt, m_tz, and millisec(). Referenced by ASSA::Timer::dump(), and dump_to_log(). 00151 { 00152 struct tm ct; 00153 char buf [80]; 00154 memset (buf, 0, 80); 00155 00156 if (m_tz == gmt) 00157 ct = *( localtime ((const time_t*) &tv_sec) ); 00158 else 00159 ct = *( gmtime ((const time_t*) &tv_sec) ); 00160 00161 strftime (buf, 80, "%M:%S", &ct); 00162 sprintf (buf + strlen(buf), ".%03ld", millisec ()); 00163 00164 return string (buf); 00165 }
|
|
Format timeval structure in readable format SS.MLS.
Definition at line 169 of file TimeVal.cpp. References gmt, m_tz, and millisec(). 00170 { 00171 struct tm ct; 00172 char buf [80]; 00173 memset (buf, 0, 80); 00174 00175 if (m_tz == gmt) 00176 ct = *( localtime ((const time_t*) &tv_sec) ); 00177 else 00178 ct = *( gmtime ((const time_t*) &tv_sec) ); 00179 00180 strftime (buf, 80, "%S", &ct); 00181 sprintf (buf + strlen(buf), ".%03ld", millisec ()); 00182 00183 return string (buf); 00184 }
|
|
Format timeval structure into readable format. Default format is CCYY/DDD HH:MM:SS.MMM which is de fasco for the software. To get something different, pass fmt_ format string as specified by strftime(3). Popular format is "%c" which will return something like: "Fri Oct 1 10:54:27 1999". Note that timezone aspect of formatting time is controlled by tz() member function.
Definition at line 107 of file TimeVal.cpp. Referenced by ASSA::Logger_Impl::add_timestamp(), ASSA::Timer::dump(), fmt_hh_mm_ss(), fmt_mm_ss(), and ASSA::Reactor::registerTimerHandler(). 00108 { 00109 struct tm ct; 00110 char buf[80]; 00111 memset (buf, 0, 80); 00112 00113 if (m_tz == gmt) 00114 ct = *( localtime ((const time_t*) &tv_sec) ); 00115 else 00116 ct = *( gmtime ((const time_t*) &tv_sec) ); 00117 00118 if (fmt_ == NULL) { 00119 strftime (buf, 80, "%Y/%j %H:%M:%S", &ct); 00120 sprintf (buf + strlen(buf), 00121 ".%03ld", (tv_usec %1000000)/1000); 00122 } 00123 else { 00124 strftime(buf, 80, fmt_, &ct); 00125 } 00126 return string (buf); 00127 }
|
|
Shields off underlying OS differences in getting current time.
Definition at line 235 of file TimeVal.h. Referenced by ASSA::Logger_Impl::add_timestamp(), ASSA::Reactor::dispatch(), ASSA::Reactor::registerTimerHandler(), ASSA::Timer::rescheduleExpirationTime(), ASSA::Reactor::waitForEvents(), and ASSA::TimerCountdown::~TimerCountdown(). 00236 { 00237 timeval tv; 00238 ::gettimeofday (&tv, 0); 00239 return tv; 00240 }
|
|
Internal initialization common to most constructors.
Definition at line 186 of file TimeVal.h. References m_tz, and normalize(). Referenced by operator=(), and TimeVal().
|
|
Convert tv_usec's microseconds (=1/1,000,000 sec) to milliseconds (=1/1,000 sec).
Definition at line 250 of file TimeVal.h. References msec(). Referenced by dump_to_log(), fmt_hh_mm_ss_mls(), fmt_mm_ss_mls(), and fmt_ss_mls(). 00251 { 00252 return (msec () % 1000000) / 1000; 00253 }
|
|
Get microseconds.
Definition at line 73 of file TimeVal.h. Referenced by dump_to_log(), and millisec().
|
|
Set microseconds.
Definition at line 70 of file TimeVal.h. Referenced by ASSA::Logger_Impl::add_timestamp(), and ASSA::Reactor::registerTimerHandler().
|
|
Normalization after arithmetic operation.
Definition at line 73 of file TimeVal.cpp. References ONE_SECOND. Referenced by init(), ASSA::operator+(), operator+=(), ASSA::operator-(), operator-=(), and TimeVal(). 00074 { 00075 if (tv_usec >= ONE_SECOND) { 00076 do { 00077 tv_sec++; 00078 tv_usec -= ONE_SECOND; 00079 } 00080 while (tv_usec >= ONE_SECOND); 00081 } 00082 else if (tv_usec <= -ONE_SECOND) { 00083 do { 00084 tv_sec--; 00085 tv_usec += ONE_SECOND; 00086 } 00087 while (tv_usec <= -ONE_SECOND); 00088 } 00089 00090 if (tv_sec >= 1 && tv_usec < 0) { 00091 tv_sec--; 00092 tv_usec += ONE_SECOND; 00093 } 00094 else if (tv_sec < 0 && tv_usec > 0) { 00095 tv_sec++; 00096 tv_usec -= ONE_SECOND; 00097 } 00098 }
|
|
Implicit conversion to double.
Definition at line 243 of file TimeVal.h.
|
|
Addition.
Definition at line 35 of file TimeVal.cpp. References normalize(), and ONE_SECOND. 00036 { 00037 tv_sec += rhs_.tv_sec; 00038 tv_usec += rhs_.tv_usec; 00039 00040 if (tv_usec >= ONE_SECOND) { 00041 tv_usec -= ONE_SECOND; 00042 tv_sec++; 00043 } 00044 else if (tv_sec >= 1 && tv_usec < 0) { 00045 tv_usec += ONE_SECOND; 00046 tv_sec--; 00047 } 00048 normalize (); 00049 return *this; 00050 }
|
|
Substraction.
Definition at line 54 of file TimeVal.cpp. References normalize(), and ONE_SECOND. 00055 { 00056 tv_sec -= rhs_.tv_sec; 00057 tv_usec -= rhs_.tv_usec; 00058 00059 if (tv_usec < 0) { 00060 tv_usec += ONE_SECOND; 00061 tv_sec--; 00062 } 00063 else if (tv_usec >= ONE_SECOND) { 00064 tv_usec -= ONE_SECOND; 00065 tv_sec++; 00066 } 00067 normalize (); 00068 return *this; 00069 }
|
|
Comparison.
Definition at line 301 of file TimeVal.h. 00302 { 00303 return (tv_sec < rhs_.tv_sec 00304 || (tv_sec == rhs_.tv_sec && tv_usec < rhs_.tv_usec) ) ; 00305 }
|
|
Definition at line 275 of file TimeVal.h. 00276 { 00277 init (tv_.tv_sec, tv_.tv_usec, tv_.m_tz); 00278 return *this; 00279 }
|
|
Equality.
Definition at line 309 of file TimeVal.h.
|
|
Get secons.
Definition at line 67 of file TimeVal.h. Referenced by dump_to_log().
|
|
Set seconds.
Definition at line 64 of file TimeVal.h. Referenced by ASSA::Reactor::registerTimerHandler().
|
|
Get timezone.
Definition at line 84 of file TimeVal.h. References m_tz. 00084 { return m_tz; }
|
|
Set timezone.
Definition at line 81 of file TimeVal.h. References m_tz. Referenced by ASSA::Logger_Impl::add_timestamp(). 00081 { m_tz = tz_; }
|
|
Static that returns zero timeval: {0,0}.
Definition at line 157 of file TimeVal.h. References m_zero. Referenced by ASSA::TimerCountdown::~TimerCountdown(). 00157 { return m_zero; }
|
|
Comparison.
Definition at line 321 of file TimeVal.h.
|
|
Addition.
Definition at line 282 of file TimeVal.h. 00283 { 00284 TimeVal temp(lhs_); 00285 temp += rhs_; 00286 temp.normalize (); 00287 return temp; 00288 }
|
|
Substraction.
Definition at line 291 of file TimeVal.h. 00292 { 00293 TimeVal temp(lhs_); 00294 temp -= rhs_; 00295 temp.normalize (); 00296 return temp; 00297 }
|
|
Comparison.
Definition at line 327 of file TimeVal.h.
|
|
Comparison.
Definition at line 315 of file TimeVal.h.
|
|
Comparison.
Definition at line 333 of file TimeVal.h.
|
|
Time zone.
Definition at line 175 of file TimeVal.h. Referenced by fmt_hh_mm_ss_mls(), fmt_mm_ss_mls(), fmt_ss_mls(), fmtString(), init(), operator=(), TimeVal(), and tz(). |
|
Zero time value.
Definition at line 178 of file TimeVal.h. Referenced by zeroTime(). |