Aria  2.8.0
ArTime Class Reference

A class for time readings and measuring durations. More...

#include <ariaUtil.h>

Public Member Functions

bool addMSec (long ms)
 Add some milliseconds (can be negative) to this time.
 
bool addMSecLL (long long ms)
 Add some milliseconds (can be negative) to this time.
 
 ArTime ()
 Constructor. Time is initialized to the current time.
 
 ArTime (const ArTime &other)
 Copy constructor.
 
unsigned long getMSec (void) const
 Gets the milliseconds value (occuring after the seconds value)
 
unsigned long long getMSecLL (void) const
 Gets the milliseconds value (occuring after the seconds value)
 
unsigned long getSec (void) const
 Gets the seconds value (since the arbitrary starting time)
 
unsigned long long getSecLL (void) const
 Gets the seconds value (since the arbitrary starting time)
 
bool isAfter (ArTime testTime) const
 returns whether the given time is after this one or not
 
bool isAt (ArTime testTime) const
 returns whether the given time is equal to this time or not
 
bool isBefore (ArTime testTime) const
 returns whether the given time is before this one or not
 
void log (const char *prefix=NULL) const
 Logs the time.
 
long mSecSince (ArTime since) const
 Gets the number of milliseconds since the given timestamp to this one.
 
long mSecSince (void) const
 Finds the number of milliseconds from this timestamp to now.
 
long long mSecSinceLL (ArTime since) const
 Gets the number of milliseconds since the given timestamp to this one.
 
long long mSecSinceLL (void) const
 Finds the number of milliseconds from this timestamp to now.
 
long mSecTo (void) const
 Finds the number of millisecs from when this timestamp is set to to now (the inverse of mSecSince())
 
long long mSecToLL (void) const
 Finds the number of millisecs from when this timestamp is set to to now (the inverse of mSecSince())
 
bool operator!= (const ArTime &other) const
 
bool operator< (const ArTime &other) const
 
ArTimeoperator= (const ArTime &other)
 Assignment operator.
 
bool operator== (const ArTime &other) const
 Equality operator (for sets)
 
long secSince (ArTime since) const
 Gets the number of seconds since the given timestamp to this one.
 
long secSince (void) const
 Finds the number of seconds from when this timestamp was set to now.
 
long long secSinceLL (ArTime since) const
 Gets the number of seconds since the given timestamp to this one.
 
long long secSinceLL (void) const
 Finds the number of seconds from when this timestamp was set to now.
 
long secTo (void) const
 Finds the number of seconds from when this timestamp is set to to now (the inverse of secSince())
 
long long secToLL (void) const
 Finds the number of seconds from when this timestamp is set to to now (the inverse of secSince())
 
void setMSec (unsigned long msec)
 Sets the milliseconds value (occuring after the seconds value)
 
void setMSecLL (unsigned long long msec)
 Sets the milliseconds value (occuring after the seconds value)
 
void setSec (unsigned long sec)
 Sets the seconds value (since the arbitrary starting time)
 
void setSecLL (unsigned long long sec)
 Sets the seconds value (since the arbitrary starting time)
 
void setToNow (void)
 Resets the time.
 
 ~ArTime ()
 Destructor.
 

Static Public Member Functions

static bool usingMonotonicClock ()
 Gets if we're using a monotonic (ever increasing) clock.
 

Protected Attributes

unsigned long long myMSec
 
unsigned long long mySec
 

Detailed Description

A class for time readings and measuring durations.

This class is for timing durations or time between events. The time values it stores are relative to an abritrary starting time; it does not correspond to "real world" or "wall clock" time in any way, so DON'T use this for keeping track of what time it is, just for timestamps and relative timing (e.g. "this loop needs to sleep another 100 ms").

The recommended methods to use are setToNow() to reset the time, mSecSince() to obtain the number of milliseconds elapsed since it was last reset (or secSince() if you don't need millisecond precision), and mSecSince(ArTime) or secSince(ArTime) to find the difference between two ArTime objects.

On systems where it is supported this will use a monotonic clock, this is an ever increasing system that is not dependent on what the time of day is set to. Normally for linux gettimeofday is used, but if the time is changed forwards or backwards then bad things can happen. Windows uses a time since bootup, which functions the same as the monotonic clock anyways. You can use ArTime::usingMonotonicClock() to see if this is being used. Note that an ArTime will have had to have been set to for this to be a good value... Aria::init does this however, so that should not be an issue. It looks like the monotonic clocks won't work on linux kernels before 2.6.

Examples:
actsColorFollowingExample.cpp, directMotionExample.cpp, gotoActionExample.cpp, and gpsExample.cpp.

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