Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

HTime Class Reference

Time representation class. More...

#include <htime.h>

Collaboration diagram for HTime:

Collaboration graph
[legend]
List of all members.

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:.

HTimeoperator= (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 ()
HTimeoperator= (_CurrentTime)
HTimeoperator= (_InvalidTime)
HTimeoperator= (_NullTime)
HTimeSet (long val, TimeSpec sp=msec)
HTimeSetL (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.

HTimeAdd (long val, TimeSpec sp=msec)
HTimeSub (long val, TimeSpec sp=msec)
HTime operator- (const HTime &start) const
HTimeoperator-= (const HTime &start)
HTime operator+ (const HTime &start) const
HTimeoperator+= (const HTime &start)
HTimeoperator- ()
 Negative time: (Stays Invalid if invalid.).

HTimeDiv (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 []

Detailed Description

Time representation class.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
This is a general replacement for timeval and time_t and can both be used to save dates as well as to measure time with usec precision (at least on some processors and operating systems).

This is from HLib (GPL (c) Wolfgang Wieser), hence the name HTime.

Definition at line 60 of file htime.h.


Member Typedef Documentation

typedef ::timeval HTime::timeval
 

Definition at line 80 of file htime.h.

Referenced by _Delta(), _gettimeofday(), _LLConv(), _Normalize(), _SetVal(), _SetValL(), Add(), do_gettimeofday(), MsecElapsed(), MsecElapsedR(), and Sub().


Member Enumeration Documentation

enum HTime::_CurrentTime
 

Enumeration values:
Curr 

Definition at line 65 of file htime.h.

enum HTime::_InvalidTime
 

Enumeration values:
Invalid 

Definition at line 67 of file htime.h.

enum HTime::_NullTime
 

Enumeration values:
Null 

Definition at line 66 of file htime.h.

enum HTime::TimeSpec
 

Enumeration values:
usec 
msec 
seconds 
minutes 
hours 
days 
_tslast 

Definition at line 63 of file htime.h.


Constructor & Destructor Documentation

HTime::HTime  )  [inline]
 

Create time in invalid state.

Definition at line 132 of file htime.h.

References tv.

HTime::HTime _CurrentTime   )  [inline]
 

Create current time.

Definition at line 134 of file htime.h.

References SetCurr().

HTime::HTime _NullTime   )  [inline]
 

Create null time.

Definition at line 136 of file htime.h.

References tv.

HTime::HTime _InvalidTime   )  [inline]
 

Explicitly create invalid time.

Definition at line 138 of file htime.h.

References tv.

HTime::~HTime  )  [inline]
 

Definition at line 145 of file htime.h.

HTime::HTime const HTime h  )  [inline]
 

Copy:.

Definition at line 148 of file htime.h.

References tv.

HTime::HTime long  val,
TimeSpec  sp = msec
[inline]
 

Store/set value (SetCurr() for current time; others never needed):.

Definition at line 158 of file htime.h.

References _SetVal(), and tv.


Member Function Documentation

int64_t HTime::_Delta const HTime endtime  )  const [private]
 

Definition at line 126 of file htime.cc.

References do_gettimeofday(), timeval, and tv.

Referenced by Elapsed(), ElapsedD(), ElapsedL(), and ElapsedR().

int HTime::_DoReadTime const char *  str  )  [private]
 

Definition at line 342 of file htime.cc.

References tv.

Referenced by ReadTime().

void HTime::_gettimeofday timeval tv  )  [inline, static, private]
 

Definition at line 86 of file htime.h.

References timeval, and tv.

Referenced by do_gettimeofday().

int64_t HTime::_LLConv const timeval tv  )  [inline, static, private]
 

Definition at line 121 of file htime.h.

References timeval.

Referenced by Get(), GetD(), GetL(), GetLR(), and GetR().

void HTime::_Normalize timeval tv  )  [inline, static, private]
 

Definition at line 113 of file htime.h.

References timeval.

Referenced by Add(), Div(), operator+(), operator+=(), operator-(), operator-=(), and Sub().

int64_t HTime::_RoundAdd int64_t  x,
TimeSpec  sp
[inline, static, private]
 

Definition at line 123 of file htime.h.

References round_delta.

Referenced by ElapsedR(), GetLR(), and GetR().

long HTime::_RoundAddMs long  x  )  [inline, static, private]
 

Definition at line 125 of file htime.h.

Referenced by MsecElapsedR().

void HTime::_SetVal long  val,
TimeSpec  sp,
timeval tv
[private]
 

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().

void HTime::_SetValL int64_t  val,
TimeSpec  sp,
timeval tv
[private]
 

Definition at line 71 of file htime.cc.

References _SetVal(), msec, seconds, timeval, and usec.

Referenced by SetL().

HTime & HTime::Add long  val,
TimeSpec  sp = msec
 

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.

HTime & HTime::Div int  fact  ) 
 

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.

void HTime::do_gettimeofday timeval tv  )  [inline, static, private]
 

Definition at line 94 of file htime.h.

References _gettimeofday(), and timeval.

Referenced by _Delta(), MsecElapsed(), MsecElapsedR(), and SetCurr().

long HTime::Elapsed TimeSpec  sp,
const HTime endtime = NULL
const [inline]
 

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 292 of file htime.h.

References _Delta(), _tslast, and conv_fact.

double HTime::ElapsedD TimeSpec  sp,
const HTime endtime = NULL
const [inline]
 

Definition at line 298 of file htime.h.

References _Delta(), _tslast, and conv_factD.

int64_t HTime::ElapsedL TimeSpec  sp,
const HTime endtime = NULL
const [inline]
 

Definition at line 294 of file htime.h.

References _Delta(), _tslast, and conv_fact.

long HTime::ElapsedR TimeSpec  sp,
const HTime endtime = NULL
const [inline]
 

Definition at line 296 of file htime.h.

References _Delta(), _RoundAdd(), _tslast, and conv_fact.

long HTime::Get TimeSpec  sp  )  const [inline]
 

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().

Note:
DO NOT CALL IF TIME IS INVALID.
Get integer value; result truncated at division

Definition at line 182 of file htime.h.

References _LLConv(), _tslast, conv_fact, and tv.

Referenced by main().

double HTime::GetD TimeSpec  sp  )  const [inline]
 

Get floating point value.

(See Get for more info.)

Definition at line 202 of file htime.h.

References _LLConv(), _tslast, conv_factD, and tv.

int64_t HTime::GetL TimeSpec  sp  )  const [inline]
 

Get 64bit integer value; result truncated at division.

(See Get for more info.)

Definition at line 192 of file htime.h.

References _LLConv(), _tslast, conv_fact, and tv.

int64_t HTime::GetLR TimeSpec  sp  )  const [inline]
 

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.

long HTime::GetR TimeSpec  sp  )  const [inline]
 

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.

int HTime::IsInvalid  )  const [inline]
 

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().

long HTime::MsecElapsed  )  const
 

Definition at line 141 of file htime.cc.

References do_gettimeofday(), timeval, and tv.

long HTime::MsecElapsed const HTime endtime  )  const [inline]
 

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().

long HTime::MsecElapsedR  )  const
 

Definition at line 150 of file htime.cc.

References do_gettimeofday(), timeval, and tv.

long HTime::MsecElapsedR const HTime endtime  )  const [inline]
 

Definition at line 309 of file htime.h.

References _RoundAddMs(), and tv.

int HTime::operator!= _NullTime   )  const [inline]
 

Definition at line 268 of file htime.h.

References IsInvalid(), and tv.

int HTime::operator!= _InvalidTime   )  const [inline]
 

Definition at line 264 of file htime.h.

References IsInvalid().

int HTime::operator!= const HTime h  )  const [inline]
 

Definition at line 245 of file htime.h.

References IsInvalid(), and tv.

HTime HTime::operator+ const HTime start  )  const
 

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.

HTime & HTime::operator+= const HTime start  ) 
 

Definition at line 211 of file htime.cc.

References _Normalize(), IsInvalid(), SetInvalid(), and tv.

HTime & HTime::operator-  ) 
 

Negative time: (Stays Invalid if invalid.).

Definition at line 228 of file htime.cc.

References _Normalize(), IsInvalid(), and tv.

HTime HTime::operator- const HTime start  )  const
 

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.

HTime & HTime::operator-= const HTime start  ) 
 

Definition at line 180 of file htime.cc.

References _Normalize(), IsInvalid(), SetInvalid(), and tv.

int HTime::operator< _NullTime   )  const [inline]
 

Definition at line 272 of file htime.h.

References tv.

int HTime::operator< const HTime h  )  const [inline]
 

Definition at line 251 of file htime.h.

References tv.

int HTime::operator<= _NullTime   )  const [inline]
 

Definition at line 278 of file htime.h.

References tv.

int HTime::operator<= const HTime h  )  const [inline]
 

Definition at line 257 of file htime.h.

References tv.

HTime& HTime::operator= _NullTime   )  [inline]
 

Definition at line 162 of file htime.h.

References tv.

HTime& HTime::operator= _InvalidTime   )  [inline]
 

Definition at line 161 of file htime.h.

References SetInvalid().

HTime& HTime::operator= _CurrentTime   )  [inline]
 

Definition at line 160 of file htime.h.

References SetCurr().

HTime& HTime::operator= const HTime h  )  [inline]
 

Definition at line 149 of file htime.h.

References tv.

int HTime::operator== _NullTime   )  const [inline]
 

Definition at line 266 of file htime.h.

References IsInvalid(), and tv.

int HTime::operator== _InvalidTime   )  const [inline]
 

Special compare functions to compare against HTime::Invalid or HTime::Null:

Definition at line 262 of file htime.h.

References IsInvalid().

int HTime::operator== const HTime h  )  const [inline]
 

To compare time values: NOTE: - The operator== and operator!= always return false if at least one time is invalid.

  • The other operators are UNDEFINED if at least one time is invalid.

Definition at line 242 of file htime.h.

References IsInvalid(), and tv.

int HTime::operator> _NullTime   )  const [inline]
 

Definition at line 270 of file htime.h.

References tv.

int HTime::operator> const HTime h  )  const [inline]
 

Definition at line 248 of file htime.h.

References tv.

int HTime::operator>= _NullTime   )  const [inline]
 

Definition at line 275 of file htime.h.

References tv.

int HTime::operator>= const HTime h  )  const [inline]
 

Definition at line 254 of file htime.h.

References tv.

char * HTime::PrintElapsed char *  buf,
size_t  len,
int  with_msec = 1
const
 

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.

char * HTime::PrintTime char *  buf,
size_t  len,
int  local = 1,
int  with_msec = 0
const
 

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 '
', of course...)

Definition at line 267 of file htime.cc.

References _is_invalid_str, IsInvalid(), msec, and tv.

void HTime::PruneUsec  )  [inline]
 

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.

int HTime::ReadTime const char *  str  )  [inline]
 

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().

HTime& HTime::Set long  val,
TimeSpec  sp = msec
[inline]
 

Definition at line 166 of file htime.h.

References _SetVal(), and tv.

void HTime::SetCurr  )  [inline]
 

Definition at line 159 of file htime.h.

References do_gettimeofday(), and tv.

Referenced by HTime(), and operator=().

void HTime::SetInvalid  )  [inline]
 

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().

HTime& HTime::SetL int64_t  val,
TimeSpec  sp = msec
[inline]
 

Definition at line 168 of file htime.h.

References _SetValL(), and tv.

HTime & HTime::Sub long  val,
TimeSpec  sp = msec
 

Definition at line 112 of file htime.cc.

References _Normalize(), _SetVal(), IsInvalid(), timeval, and tv.


Member Data Documentation

const int64_t HTime::conv_fact [static, private]
 

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().

const double HTime::conv_factD [static, private]
 

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().

const int64_t HTime::round_delta [static, private]
 

Initial value:

{ 0LL,  500LL,  500000LL, 30000000LL, 1800000000LL, 43200000000LL }

Definition at line 27 of file htime.cc.

Referenced by _RoundAdd().

timeval HTime::tv [private]
 

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().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:25 2005 for Ray by doxygen 1.3.5