Fawkes API  Fawkes Development Version
fawkes::Time Class Reference

#include <>>

Public Member Functions

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

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

Detailed Description

A class for handling time.

Author
Daniel Beck
Tim Niemueller

Definition at line 98 of file time.h.

Constructor & Destructor Documentation

◆ Time() [1/8]

fawkes::Time::Time ( )

Constructor.

Sets time to the current time.

Definition at line 100 of file time.cpp.

References fawkes::Clock::instance().

Referenced by fawkes::time_diff_usec().

◆ Time() [2/8]

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

Constructor.

Sets time to the given time.

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

Definition at line 111 of file time.cpp.

◆ Time() [3/8]

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
sectime in seconds since the epoch (or time range)
usecfractions in microseconds added to sec
clockoptional clock to use, if NULL Clock::instance() will be used

Definition at line 126 of file time.cpp.

◆ Time() [4/8]

fawkes::Time::Time ( long  ms)

Constructor.

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

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

Definition at line 142 of file time.cpp.

◆ Time() [5/8]

fawkes::Time::Time ( double  s)

Constructor.

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

Parameters
sthe Time object is initialized to the time given in seconds

Definition at line 157 of file time.cpp.

◆ Time() [6/8]

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
clockclock

Definition at line 173 of file time.cpp.

References TIMESTR_SIZE.

◆ Time() [7/8]

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

Copy constructor.

Parameters
ttime to copy

Definition at line 183 of file time.cpp.

◆ Time() [8/8]

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

Copy constructor.

Parameters
ttime to copy

Definition at line 199 of file time.cpp.

◆ ~Time()

fawkes::Time::~Time ( )

Destructor.

Definition at line 213 of file time.cpp.

Member Function Documentation

◆ add()

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

Add seconds.

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

Parameters
secondstime in seconds to add

Definition at line 329 of file time.cpp.

◆ get_msec()

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

Get milliseconds.

Returns
milliseconds stored in time stamp

Definition at line 128 of file time.h.

◆ get_nsec()

long fawkes::Time::get_nsec ( ) const
inline

Get nanoseconds.

Returns
microsecons converted to nanoseconds

Definition at line 138 of file time.h.

Referenced by RosLaserScanThread::bb_interface_data_changed(), GossipExampleSenderThread::loop(), RosSkillerThread::loop(), and fawkes::tf::TimeCache::~TimeCache().

◆ get_sec()

◆ get_timestamp()

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

Get time stamp.

Parameters
secupon return contains seconds stored in time stamp
usecupon return contains microseconds stored in time stamp

Definition at line 143 of file time.h.

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

◆ get_timeval()

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 118 of file time.h.

Referenced by BBLoggerThread::BBLoggerThread(), BlackBoardLoggerPlugin::BlackBoardLoggerPlugin(), RosPointCloudThread::loop(), firevision::SharedMemoryImageBuffer::set_capture_time(), fawkes::Clock::sys_elapsed(), and fawkes::SimulatorTimeSource::~SimulatorTimeSource().

◆ get_usec()

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

◆ in_msec()

long fawkes::Time::in_msec ( ) const

Convert the stored time into milli-seconds.

Returns
the time in milli-seconds

Definition at line 235 of file time.cpp.

Referenced by XabslEngineThread::current_time(), MongoLogPointCloudThread::loop(), MongoLogImagesThread::loop(), and fawkes::tf::MongoDBTransformer::restore().

◆ in_sec()

double 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 226 of file time.cpp.

Referenced by fawkes::tf::Transformer::all_frames_as_dot(), fawkes::LaserOccupancyGrid::get_cell_costs(), fawkes::SyncPointCallStats::get_last_call(), ClockPlexilTimeAdapter::getCurrentTime(), VisLocalizationThread::init(), VisLocalizationThread::loop(), BBLogReplayThread::loop(), fawkes::LaserOccupancyGrid::reset_old(), and ClockPlexilTimeAdapter::setThresholds().

◆ in_usec()

long fawkes::Time::in_usec ( ) const

Convert the stored time into micro-seconds.

Returns
the time in micro-seconds

Definition at line 244 of file time.cpp.

Referenced by wait().

◆ is_zero()

bool fawkes::Time::is_zero ( ) const
inline

Check if time is zero.

Returns
true if time is zero, i.e. sec = usec = 0, false otherwise

Definition at line 149 of file time.h.

Referenced by FvRetrieverThread::init(), and PlexilTimerThread::loop().

◆ operator!=() [1/2]

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

Check inequality of times.

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

Definition at line 604 of file time.cpp.

◆ operator!=() [2/2]

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

Check inequality of times.

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

Definition at line 614 of file time.cpp.

◆ operator+() [1/4]

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

Operator that adds times.

Parameters
secnumber of seconds to add
Returns
the sum

Definition at line 368 of file time.cpp.

◆ operator+() [2/4]

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

Operator to add usec value.

Parameters
usecmicroseconds to add
Returns
new resulting instance

Definition at line 389 of file time.cpp.

◆ operator+() [3/4]

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

Operator that adds times.

Parameters
tthe other summand
Returns
the sum

Definition at line 339 of file time.cpp.

◆ operator+() [4/4]

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

Operator that adds times.

Parameters
tthe other summand
Returns
the sum

Definition at line 358 of file time.cpp.

◆ operator+=() [1/3]

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

+= operator for double seconds

Parameters
secnumber of seconds to add
Returns
the sum

Definition at line 518 of file time.cpp.

◆ operator+=() [2/3]

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

+= operator

Parameters
usecmicroseconds to add
Returns
reference to this instance

Definition at line 499 of file time.cpp.

◆ operator+=() [3/3]

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

+= operator

Parameters
tthe other time
Returns
reference to this instance

Definition at line 481 of file time.cpp.

◆ operator-() [1/4]

Time fawkes::Time::operator- ( const double  sec) const

Operator that subtracts some time.

Parameters
secnumber of seconds to subtract
Returns
the difference

Definition at line 439 of file time.cpp.

◆ operator-() [2/4]

Time fawkes::Time::operator- ( const long int  usec) const

Operator that subtracts some time.

Parameters
usecnumber of microseconds to subtract
Returns
the difference

Definition at line 460 of file time.cpp.

◆ operator-() [3/4]

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

Operator that substracts one Time from another.

Parameters
tthe Time that is substracted
Returns
the difference

Definition at line 410 of file time.cpp.

◆ operator-() [4/4]

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

Operator that substracts one Time from another.

Parameters
tthe Time that is substracted
Returns
the difference

Definition at line 429 of file time.cpp.

◆ operator-=() [1/3]

Time & fawkes::Time::operator-= ( const double  sec)

-= operator.

Parameters
secseconds to subtract
Returns
reference to this instance after subtraction

Definition at line 549 of file time.cpp.

◆ operator-=() [2/3]

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

-= operator.

Parameters
usecmicroseconds to subtract
Returns
reference to this instance after subtraction

Definition at line 560 of file time.cpp.

◆ operator-=() [3/3]

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

-= operator.

Parameters
tthe other time
Returns
reference to this instance after subtraction

Definition at line 538 of file time.cpp.

◆ operator<() [1/2]

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

Less than operator.

Parameters
ttime to compare to
Returns
true if this time is less than t, false otherwise

Definition at line 668 of file time.cpp.

◆ operator<() [2/2]

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

Less than operator.

Parameters
ttime to compare to
Returns
true if this time is less than t, false otherwise

Definition at line 679 of file time.cpp.

◆ operator<=() [1/2]

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

Less than or equal to operator.

Parameters
ttime to compare to
Returns
true if this time is less than t, false otherwise

Definition at line 690 of file time.cpp.

◆ operator<=() [2/2]

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

Less than or equal to operator.

Parameters
ttime to compare to
Returns
true if this time is less than t, false otherwise

Definition at line 701 of file time.cpp.

References fawkes::Clock::get_time().

◆ operator=()

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

Assign operator.

Parameters
ttime to assign to this instance
Returns
reference to this instance

Definition at line 571 of file time.cpp.

◆ operator==() [1/2]

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

Check equality of times.

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

Definition at line 584 of file time.cpp.

◆ operator==() [2/2]

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

Check equality of times.

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

Definition at line 594 of file time.cpp.

◆ operator>() [1/2]

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

Greater than operator.

Parameters
ttime to compare to
Returns
true if this time is greater than t, false otherwise

Definition at line 624 of file time.cpp.

◆ operator>() [2/2]

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

Greater than operator.

Parameters
ttime to compare to
Returns
true if this time is greater than t, false otherwise

Definition at line 635 of file time.cpp.

◆ operator>=() [1/2]

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

Greater than or equal to operator.

Parameters
ttime to compare to
Returns
true if this time is greater than t, false otherwise

Definition at line 646 of file time.cpp.

◆ operator>=() [2/2]

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

Greater than or equal to operator.

Parameters
ttime to compare to
Returns
true if this time is greater than t, false otherwise

Definition at line 657 of file time.cpp.

◆ set_clock()

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

Set clock for this instance.

Parameters
clockclock to use from now on

Definition at line 315 of file time.cpp.

Referenced by OpenNiContextThread::init(), NaoQiButtonThread::init(), RosTfThread::init(), and KatanaActThread::init().

◆ set_time() [1/6]

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
ttime to set to

Definition at line 296 of file time.cpp.

◆ set_time() [2/6]

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

Set time to given time.

Parameters
ttime to set to

Definition at line 305 of file time.cpp.

◆ set_time() [3/6]

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

◆ set_time() [4/6]

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

Sets the time.

Parameters
sset the time to this value

Definition at line 284 of file time.cpp.

◆ set_time() [5/6]

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

Sets the time.

Parameters
secseconds part of the time
usecmicroseconds part of the time

Definition at line 264 of file time.cpp.

◆ set_time() [6/6]

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

Sets the time.

Parameters
msset the time to this value

Definition at line 274 of file time.cpp.

◆ stamp()

◆ stamp_systime()

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 727 of file time.cpp.

Referenced by OpenNiDepthThread::init(), OpenNiImageThread::init(), OpenNiPointCloudThread::init(), and fawkes::FawkesTimingThread::loop().

◆ str()

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
utctrue to get type formatted in UTC, otherwise local time

Definition at line 797 of file time.cpp.

References TIMESTR_SIZE.

Referenced by fawkes::tf::Transformer::all_frames_as_dot(), and ROSTalkerPubThread::loop().

◆ str_r()

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

Output function.

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

Parameters
spointer to a string of at least TIMESTR_SIZE bytes.
utctrue to get type formatted in UTC, otherwise local time

Definition at line 826 of file time.cpp.

◆ wait()

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 743 of file time.cpp.

References in_usec(), and stamp().

Referenced by BBLogReplayThread::loop().

◆ wait_systime()

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 767 of file time.cpp.

Referenced by JoystickAcquisitionThread::loop(), and FestivalSynthThread::say().

Member Data Documentation

◆ TIMESTR_SIZE

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 202 of file time.h.

Referenced by str(), and Time().


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