Public Member Functions | Private Member Functions | Private Attributes | Friends

util::timestamp Class Reference

allow to keep track of time with a precision of a microseconds. More...

#include <util/timestamp.hpp>


Detailed Description

allow to keep track of time with a precision of a microseconds.

The default constructors obtains the time with gettimeofday(2). Timestamps can be added or substracted and pushed to streams such as std::cout. It keeps track of time using integers so as not to lose precision. Typical use of the class are:

 timestamp t1; 
 foo();
 timestamp t2;
 std::cout<<"foo() took "<<t2-t1<<" seconds"<<std::endl;

or

 timestamp acc (0,0);
 while (some_condition()){ 
   do_stuff();
   timestamp t1;
   do_important_stuff();
   timestamp t2;
   acc += t2-t1;
   do_more_stuff();
 }
 std::cout<<"do_important_stuff() took "<<acc<<" seconds"<<std::endl;

List of all members.

Public Member Functions

 timestamp ()
 obtains time using gettimeofday(2)
 timestamp (int s, int us)
 provides time in seconds and microseconds
timestamp operator+ (const timestamp &b)
timestamp operator- (const timestamp &b)
const timestampoperator+= (const timestamp &b)
const timestampoperator-= (const timestamp &b)

Private Member Functions

void fixme ()
 fix overflow after an add or a substract.

Private Attributes

int seconds
int microseconds

Friends

std::ostream & operator<< (std::ostream &, const util::timestamp &)

Constructor & Destructor Documentation

util::timestamp::timestamp (  )  [inline]

obtains time using gettimeofday(2)

util::timestamp::timestamp ( int  s,
int  us 
) [inline]

provides time in seconds and microseconds


Member Function Documentation

void util::timestamp::fixme (  )  [inline, private]

fix overflow after an add or a substract.

Notice it only fix the overflow of one unit.

timestamp util::timestamp::operator+ ( const timestamp b  )  [inline]
const timestamp& util::timestamp::operator+= ( const timestamp b  )  [inline]
timestamp util::timestamp::operator- ( const timestamp b  )  [inline]
const timestamp& util::timestamp::operator-= ( const timestamp b  )  [inline]

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const util::timestamp t 
) [friend]

Member Data Documentation

int util::timestamp::seconds [private]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines