fawkes::Time Class Reference

A class for handling time. More...

#include <utils/time/time.h>

List of all members.

Public Member Functions

 Time ()
 Constructor.
 Time (const timeval *tv)
 Constructor.
 Time (long sec, long usec, Clock *clock=0)
 Constructor.
 Time (long ms)
 Constructor.
 Time (float sec)
 Constructor.
 Time (Clock *clock)
 Constructor.
 Time (const Time &t)
 Copy constructor.
 Time (const Time *t)
 Copy constructor.
 ~Time ()
 Destructor.
float in_sec () const
 Convet time to seconds.
long in_msec () const
 Convert the stored time into milli-seconds.
long in_usec () const
 Convert the stored time into micro-seconds.
const timeval * get_timeval () const
 Obtain the timeval where the time is stored.
long get_sec () const
 Get seconds.
long get_msec () const
 Get milliseconds.
long get_usec () const
 Get microseconds.
void get_timestamp (long &sec, long &usec) const
 Get time stamp.
void set_time (const timeval *tv)
 Sets the time.
void set_time (long int sec, long int usec)
 Sets the time.
void set_time (long ms)
 Sets the time.
void set_time (float sec)
 Sets the time.
void set_time (const Time &t)
 Set time to given time.
void set_time (const Time *t)
 Set time to given time.
void set_clock (Clock *clock)
 Set clock for this instance.
void add (float seconds)
 Add seconds.
Timestamp ()
 Set this time to the current time.
Timestamp_systime ()
 Set this time to the current system time.
Time operator+ (const float sec) const
 Operator that adds times.
Time operator+ (const Time &t) const
 Operator that adds times.
Time operator+ (const Time *t) const
 Operator that adds times.
Time operator- (const Time &t) const
 Operator that substracts one Time from another.
float operator- (const Time *t) const
 Operator that substracts one Time from another.
Timeoperator+= (const long int usec)
 += operator
Timeoperator+= (const Time &t)
 += operator
Timeoperator+= (const float sec)
 += operator for float seconds
Timeoperator-= (const Time &t)
 -= operator.
Timeoperator= (const Time &t)
 Assign operator.
bool operator== (const Time &t) const
 Check equality of times.
bool operator== (const Time *t) const
 Check equality of times.
bool operator!= (const Time &t) const
 Check inequality of times.
bool operator!= (const Time *t) const
 Check inequality of times.
void wait ()
 Wait (sleep) for this time.
void wait_systime ()
 Wait (sleep) for this system time.
const char * str (bool utc=false) const
 Output function.
void str_r (char *s, bool utc=false)
 Output function.

Static Public Attributes

static const unsigned int TIMESTR_SIZE = 26
 Maximum size of string returned by str() and the minimum size of the string passwd to str_r().

Friends

class Clock

Detailed Description

A class for handling time.

Author:
Daniel Beck
Tim Niemueller

Definition at line 80 of file time.h.


Constructor & Destructor Documentation

fawkes::Time::Time (  ) 

Constructor.

Sets time to the current time.

Definition at line 79 of file time.cpp.

References fawkes::Clock::get_time(), and fawkes::Clock::instance().

fawkes::Time::Time ( const timeval *  tv  ) 

Constructor.

Sets time to the given time.

Parameters:
tv the Time object is initialized with the time given in this timeval

Definition at line 91 of file time.cpp.

References fawkes::Clock::instance().

fawkes::Time::Time ( long  sec,
long  usec,
Clock clock = 0 
)

Constructor.

Sets time to the given time. Basically the same as setting from a timeval struct but the components are given separately.

Parameters:
sec time in seconds since the epoch (or time range)
usec fractions in microseconds added to sec
clock optional clock to use, if NULL Clock::instance() will be used

Definition at line 107 of file time.cpp.

References fawkes::Clock::instance().

fawkes::Time::Time ( long  ms  ) 

Constructor.

Sets time to given number of ms, use for time range.

Parameters:
ms the Time object is initialized to the time given in milli-seconds

Definition at line 124 of file time.cpp.

References fawkes::Clock::instance().

fawkes::Time::Time ( float  s  ) 

Constructor.

Sets time to given number of ms, use for time range.

Parameters:
s the Time object is initialized to the time given in seconds

Definition at line 140 of file time.cpp.

References fawkes::Clock::instance().

fawkes::Time::Time ( Clock clock  ) 

Constructor.

This constructor uses the supplied clock for setting the time. The time is set to the current time.

Parameters:
clock clock

Definition at line 157 of file time.cpp.

References fawkes::Clock::get_time().

fawkes::Time::Time ( const Time t  ) 

Copy constructor.

Parameters:
t time to copy

Definition at line 168 of file time.cpp.

References TIMESTR_SIZE.

fawkes::Time::Time ( const Time t  ) 

Copy constructor.

Parameters:
t time to copy

Definition at line 185 of file time.cpp.

References TIMESTR_SIZE.

fawkes::Time::~Time (  ) 

Destructor.

Definition at line 200 of file time.cpp.


Member Function Documentation

void fawkes::Time::add ( float  seconds  ) 

Add seconds.

The effect is equivalent to operator+=(const float sec), but this can be used when the operator is not available (i.e. wrapper languages) and it does not return itself.

Parameters:
seconds time in seconds to add

Definition at line 324 of file time.cpp.

long fawkes::Time::get_msec (  )  const [inline]

Get milliseconds.

Returns:
milliseconds stored in time stamp

Definition at line 100 of file time.h.

long fawkes::Time::get_sec (  )  const [inline]

Get seconds.

Returns:
seconds stored in time stamp

Definition at line 99 of file time.h.

void fawkes::Time::get_timestamp ( long &  sec,
long &  usec 
) const [inline]

Get time stamp.

Parameters:
sec upon return contains seconds stored in time stamp
usec upon return contains microseconds stored in time stamp

Definition at line 102 of file time.h.

Referenced by fawkes::Message::mark_enqueued(), and fawkes::Interface::write().

const timeval * fawkes::Time::get_timeval (  )  const [inline]

Obtain the timeval where the time is stored.

Returns:
a const pointer to the timeval where the time is stored

Definition at line 98 of file time.h.

Referenced by BBLoggerThread::BBLoggerThread(), BlackBoardLoggerPlugin::BlackBoardLoggerPlugin(), fawkes::Clock::ext_to_realtime(), fawkes::SimulatorTimeSource::get_time(), and firevision::SharedMemoryImageBuffer::set_capture_time().

long fawkes::Time::get_usec (  )  const [inline]

Get microseconds.

Returns:
microseconds stored in time stamp

Definition at line 101 of file time.h.

long fawkes::Time::in_msec (  )  const

Convert the stored time into milli-seconds.

Returns:
the time in milli-seconds

Definition at line 223 of file time.cpp.

Referenced by fawkes::WorldInfoDataContainer::check_timeout(), and XabslEngineThread::current_time().

float fawkes::Time::in_sec (  )  const

Convet time to seconds.

Convert the stored time in a floating point number representing the number of seconds. For a time the integral part is the number of seconds since the epoch, for ranges you get the value as a float second.

Returns:
the time in seconds

Definition at line 213 of file time.cpp.

Referenced by fawkes::SimulatorTimeSource::conv_to_realtime(), BBLogReplayThread::loop(), and BBLogFile::print_entry().

long fawkes::Time::in_usec (  )  const

Convert the stored time into micro-seconds.

Returns:
the time in micro-seconds

Definition at line 233 of file time.cpp.

Referenced by wait(), and wait_systime().

bool fawkes::Time::operator!= ( const Time t  )  const

Check inequality of times.

Parameters:
t time to compare to
Returns:
true if sec or usec of both times are different, false otherwise

Definition at line 558 of file time.cpp.

bool fawkes::Time::operator!= ( const Time t  )  const

Check inequality of times.

Parameters:
t time to compare to
Returns:
true if sec or usec of both times are different, false otherwise

Definition at line 546 of file time.cpp.

Time fawkes::Time::operator+ ( const Time t  )  const

Operator that adds times.

Parameters:
t the other summand
Returns:
the sum

Definition at line 357 of file time.cpp.

Time fawkes::Time::operator+ ( const Time t  )  const

Operator that adds times.

Parameters:
t the other summand
Returns:
the sum

Definition at line 334 of file time.cpp.

Time fawkes::Time::operator+ ( const float  sec  )  const

Operator that adds times.

Parameters:
sec number of seconds to add
Returns:
the sum

Definition at line 368 of file time.cpp.

Time & fawkes::Time::operator+= ( const float  sec  ) 

+= operator for float seconds

Parameters:
sec number of seconds to add
Returns:
the sum

Definition at line 472 of file time.cpp.

Time & fawkes::Time::operator+= ( const Time t  ) 

+= operator

Parameters:
t the other time
Returns:
reference to this instance

Definition at line 427 of file time.cpp.

Time & fawkes::Time::operator+= ( const long int  usec  ) 

+= operator

Parameters:
usec microseconds to add
Returns:
reference to this instance

Definition at line 449 of file time.cpp.

float fawkes::Time::operator- ( const Time t  )  const

Operator that substracts one Time from another.

Parameters:
t the Time that is substracted
Returns:
the difference

Definition at line 416 of file time.cpp.

References fawkes::time_diff_sec().

Time fawkes::Time::operator- ( const Time t  )  const

Operator that substracts one Time from another.

Parameters:
t the Time that is substracted
Returns:
the difference

Definition at line 393 of file time.cpp.

Time & fawkes::Time::operator-= ( const Time t  ) 

-= operator.

Parameters:
t the other time
Returns:
reference to this instance

Definition at line 496 of file time.cpp.

Time & fawkes::Time::operator= ( const Time t  ) 

Assign operator.

Parameters:
t time to assign to this instance
Returns:
reference to this instance

Definition at line 508 of file time.cpp.

bool fawkes::Time::operator== ( const Time t  )  const

Check equality of times.

Parameters:
t time to compare to
Returns:
true if sec and usec of both times are the same, false otherwise

Definition at line 534 of file time.cpp.

bool fawkes::Time::operator== ( const Time t  )  const

Check equality of times.

Parameters:
t time to compare to
Returns:
true if sec and usec of both times are the same, false otherwise

Definition at line 522 of file time.cpp.

void fawkes::Time::set_clock ( Clock clock  ) 

Set clock for this instance.

Parameters:
clock clock to use from now on

Definition at line 310 of file time.cpp.

Referenced by fawkes::Interface::set_clock().

void fawkes::Time::set_time ( const Time t  ) 

Set time to given time.

Parameters:
t time to set to

Definition at line 299 of file time.cpp.

void fawkes::Time::set_time ( const Time t  ) 

Set time to given time.

this is equivalent to operator+, but can be used in situations where the operator cannot be used (for example in Lua).

Parameters:
t time to set to

Definition at line 289 of file time.cpp.

void fawkes::Time::set_time ( float  s  ) 

Sets the time.

Parameters:
s set the time to this value

Definition at line 277 of file time.cpp.

void fawkes::Time::set_time ( long  ms  ) 

Sets the time.

Parameters:
ms set the time to this value

Definition at line 266 of file time.cpp.

void fawkes::Time::set_time ( long int  sec,
long int  usec 
)

Sets the time.

Parameters:
sec seconds part of the time
usec microseconds part of the time

Definition at line 255 of file time.cpp.

void fawkes::Time::set_time ( const timeval *  tv  ) 
Time & fawkes::Time::stamp (  ) 
Time & fawkes::Time::stamp_systime (  ) 

Set this time to the current system time.

This bypasses any possibly registered time source. Use with care and only where you really need the system time.

Returns:
reference to this instance

Definition at line 586 of file time.cpp.

References fawkes::Clock::get_systime().

Referenced by FawkesMainThread::loop().

const char * fawkes::Time::str ( bool  utc = false  )  const

Output function.

Returns:
a pointer to a member containing a string represenation of the given time. If seconds is smaller than 1 billion it is assumed that this time represents a time range rather than a point in time and the time is formatted as seconds.microseconds, otherwise the time is formatted either via localtime() (if utc is false) or gmtime (if utc is true).
Parameters:
utc true to get type formatted in UTC, otherwise local time

Definition at line 658 of file time.cpp.

References TIMESTR_SIZE.

Referenced by BBLogFile::print_info(), and WebviewBlackBoardRequestProcessor::process_request().

void fawkes::Time::str_r ( char *  s,
bool  utc = false 
)

Output function.

This is the thread-safe version of str().

Parameters:
s pointer to a string of at least TIMESTR_SIZE bytes.
utc true to get type formatted in UTC, otherwise local time

Definition at line 691 of file time.cpp.

References TIMESTR_SIZE.

void fawkes::Time::wait (  ) 

Wait (sleep) for this time.

This waits for as much time as this instance provides. Note that you have to make sure that you call this on a sensible time range. You probably do not want to wait for almost 40 years when passing a time point...

Definition at line 603 of file time.cpp.

References in_usec(), and stamp().

Referenced by BBLogReplayThread::loop().

void fawkes::Time::wait_systime (  ) 

Wait (sleep) for this system time.

This waits for as much time as this instance provides. Unlike wait() this method calculates the time in system time, althouh the main clock may run slower for example in a simulation. Note that you have to make sure that you call this on a sensible time range. You probably do not want to wait for almost 40 years when passing a time point...

Definition at line 628 of file time.cpp.

References fawkes::Clock::get_systime(), and in_usec().

Referenced by FestivalSynthThread::say().


Member Data Documentation

const unsigned int fawkes::Time::TIMESTR_SIZE = 26 [static]

Maximum size of string returned by str() and the minimum size of the string passwd to str_r().

Definition at line 140 of file time.h.

Referenced by str(), str_r(), and Time().


The documentation for this class was generated from the following files:

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1