Time Class Reference

A Time class, can be used to hold wall- or sim-time. More...

#include <common/common.hh>

Public Types

enum  FormatOption {
  DAYS = 0, HOURS = 1, MINUTES = 2, SECONDS = 3,
  MILLISECONDS = 4
}
 

Public Member Functions

 Time ()
 Constructors. More...
 
 Time (const Time &_time)
 Copy constructor. More...
 
 Time (const struct timeval &_tv)
 Constructor. More...
 
 Time (const struct timespec &_tv)
 Constructor. More...
 
 Time (int32_t _sec, int32_t _nsec)
 Constructor. More...
 
 Time (double _time)
 Constuctor. More...
 
virtual ~Time ()
 Destructor. More...
 
double Double () const
 Get the time as a double. More...
 
float Float () const
 Get the time as a float. More...
 
std::string FormattedString (FormatOption _start=DAYS, FormatOption _end=MILLISECONDS) const
 Get the time as a string formatted as "DD hh:mm:ss.mmm", with the option to choose the start/end. More...
 
bool operator!= (const struct timeval &_tv) const
 Equal to operator. More...
 
bool operator!= (const struct timespec &_tv) const
 Equal to operator. More...
 
bool operator!= (const Time &_time) const
 Equal to operator. More...
 
bool operator!= (double _time) const
 Equal to operator. More...
 
Time operator* (const struct timeval &_tv) const
 Multiplication operator. More...
 
Time operator* (const struct timespec &_tv) const
 Multiplication operator. More...
 
Time operator* (const Time &_time) const
 Multiplication operators. More...
 
const Timeoperator*= (const struct timeval &_tv)
 Multiplication assignment operator. More...
 
const Timeoperator*= (const struct timespec &_tv)
 Multiplication assignment operator. More...
 
const Timeoperator*= (const Time &_time)
 Multiplication operators. More...
 
Time operator+ (const struct timeval &_tv) const
 Addition operators. More...
 
Time operator+ (const struct timespec &_tv) const
 Addition operators. More...
 
Time operator+ (const Time &_time) const
 Addition operators. More...
 
const Timeoperator+= (const struct timeval &_tv)
 Addition assignment operator. More...
 
const Timeoperator+= (const struct timespec &_tv)
 Addition assignment operator. More...
 
const Timeoperator+= (const Time &_time)
 Addition assignemtn operator. More...
 
Time operator- (const struct timeval &_tv) const
 Subtraction operator. More...
 
Time operator- (const struct timespec &_tv) const
 Subtraction operator. More...
 
Time operator- (const Time &_time) const
 Subtraction operator. More...
 
const Timeoperator-= (const struct timeval &_tv)
 Subtraction assignment operator. More...
 
const Timeoperator-= (const struct timespec &_tv)
 Subtraction assignment operator. More...
 
const Timeoperator-= (const Time &_time)
 Subtraction assignment operator. More...
 
Time operator/ (const struct timeval &_tv) const
 Division operator. More...
 
Time operator/ (const struct timespec &_tv) const
 Division operator. More...
 
Time operator/ (const Time &_time) const
 Division operator. More...
 
const Timeoperator/= (const struct timeval &_tv)
 Division assignment operator. More...
 
const Timeoperator/= (const struct timespec &_tv)
 Division assignment operator. More...
 
const Timeoperator/= (const Time &time)
 Division assignment operator. More...
 
bool operator< (const struct timeval &_tv) const
 Less than operator. More...
 
bool operator< (const struct timespec &_tv) const
 Less than operator. More...
 
bool operator< (const Time &_time) const
 Less than operator. More...
 
bool operator< (double _time) const
 Less than operator. More...
 
bool operator<= (const struct timeval &_tv) const
 Less than or equal to operator. More...
 
bool operator<= (const struct timespec &_tv) const
 Less than or equal to operator. More...
 
bool operator<= (const Time &_time) const
 Less than or equal to operator. More...
 
bool operator<= (double _time) const
 Less than or equal to operator. More...
 
Timeoperator= (const struct timeval &_tv)
 Assignment operator. More...
 
Timeoperator= (const struct timespec &_tv)
 Assignment operator. More...
 
Timeoperator= (const Time &_time)
 Assignment operator. More...
 
bool operator== (const struct timeval &_tv) const
 Equal to operator. More...
 
bool operator== (const struct timespec &_tv) const
 Equal to operator. More...
 
bool operator== (const Time &_time) const
 Equal to operator. More...
 
bool operator== (double _time) const
 Equal to operator. More...
 
bool operator> (const struct timeval &_tv) const
 Greater than operator. More...
 
bool operator> (const struct timespec &_tv) const
 Greater than operator. More...
 
bool operator> (const Time &_time) const
 Greater than operator. More...
 
bool operator> (double _time) const
 Greater than operator. More...
 
bool operator>= (const struct timeval &_tv) const
 Greater than or equal operator. More...
 
bool operator>= (const struct timespec &_tv) const
 Greater than or equal operator. More...
 
bool operator>= (const Time &_time) const
 Greater than or equal operator. More...
 
bool operator>= (double _time) const
 Greater than or equal operator. More...
 
void Set (int32_t _sec, int32_t _nsec)
 Set to sec and nsec. More...
 
void Set (double _seconds)
 Set to seconds. More...
 
void SetToWallTime ()
 Set the time to the wall time. More...
 

Static Public Member Functions

static const TimeGetWallTime ()
 Get the wall time. More...
 
static const std::string & GetWallTimeAsISOString ()
 Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS. More...
 
static double MicToNano (double _ms)
 Convert microseconds to nanoseconds. More...
 
static double MilToNano (double _ms)
 Convert milliseconds to nanoseconds. More...
 
static Time MSleep (unsigned int _ms)
 Millisecond sleep. More...
 
static Time NSleep (unsigned int _ns)
 Nano sleep. More...
 
static double SecToNano (double _sec)
 Convert seconds to nanoseconds. More...
 
static Time Sleep (const common::Time &_time)
 Sleep for the specified time. More...
 

Public Attributes

int32_t nsec
 Nanoseconds. More...
 
int32_t sec
 Seconds. More...
 

Static Public Attributes

static const Time Hour
 A static time variable set to an hour: common::Time(3600, 0). More...
 
static const int32_t nsInMs
 Constant multiplier to convert from nanoseconds to milliseconds. More...
 
static const int32_t nsInSec
 Constant multiplier to convert from nanoseconds to seconds. More...
 
static const Time Second
 A static time variable set to a second: common::Time(1, 0). More...
 
static const Time Zero
 A static zero time variable set to common::Time(0, 0). More...
 

Friends

std::ostream & operator<< (std::ostream &_out, const gazebo::common::Time &_time)
 Stream insertion operator. More...
 
std::istream & operator>> (std::istream &_in, gazebo::common::Time &_time)
 Stream extraction operator. More...
 

Detailed Description

A Time class, can be used to hold wall- or sim-time.

stored as sec and nano-sec.

Member Enumeration Documentation

§ FormatOption

Enumerator
DAYS 

Days.

HOURS 

Hours.

MINUTES 

Minutes.

SECONDS 

Seconds.

MILLISECONDS 

Milliseconds.

Constructor & Destructor Documentation

§ Time() [1/6]

Time ( )

Constructors.

§ Time() [2/6]

Time ( const Time _time)

Copy constructor.

Parameters
[in]timeTime to copy

§ Time() [3/6]

Time ( const struct timeval &  _tv)

Constructor.

Parameters
[in]_tvTime to initialize to

§ Time() [4/6]

Time ( const struct timespec &  _tv)

Constructor.

Parameters
[in]_tvTime to initialize to

§ Time() [5/6]

Time ( int32_t  _sec,
int32_t  _nsec 
)

Constructor.

Parameters
[in]_secSeconds
[in]_nsecNanoseconds

§ Time() [6/6]

Time ( double  _time)

Constuctor.

Parameters
[in]_timeTime in double format sec.nsec

§ ~Time()

virtual ~Time ( )
virtual

Destructor.

Member Function Documentation

§ Double()

double Double ( ) const

Get the time as a double.

Returns
Time as a double in seconds

§ Float()

float Float ( ) const

Get the time as a float.

Returns
Time as a float in seconds

§ FormattedString()

std::string FormattedString ( FormatOption  _start = DAYS,
FormatOption  _end = MILLISECONDS 
) const

Get the time as a string formatted as "DD hh:mm:ss.mmm", with the option to choose the start/end.

Parameters
[in]_startStart point.
[in]_endEnd point.
Returns
String representing time.

§ GetWallTime()

static const Time& GetWallTime ( )
static

Get the wall time.

Returns
the current time

§ GetWallTimeAsISOString()

static const std::string& GetWallTimeAsISOString ( )
static

Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS.

Returns
The current wall time as an ISO string.

§ MicToNano()

static double MicToNano ( double  _ms)
inlinestatic

Convert microseconds to nanoseconds.

Parameters
_msmicroseconds
Returns
nanoseconds

§ MilToNano()

static double MilToNano ( double  _ms)
inlinestatic

Convert milliseconds to nanoseconds.

Parameters
[in]_msmilliseconds
Returns
nanoseconds

§ MSleep()

static Time MSleep ( unsigned int  _ms)
static

Millisecond sleep.

Parameters
[in]_msmilliseconds
Returns
Time actually slept

§ NSleep()

static Time NSleep ( unsigned int  _ns)
static

Nano sleep.

Parameters
[in]_nsnanoseconds
Returns
Time actually slept

§ operator!=() [1/4]

bool operator!= ( const struct timeval &  _tv) const

Equal to operator.

Parameters
[in]_tvthe time to compare to
Returns
true if values are the same, false otherwise

§ operator!=() [2/4]

bool operator!= ( const struct timespec &  _tv) const

Equal to operator.

Parameters
[in]_tvthe time to compare to
Returns
true if values are the same, false otherwise

§ operator!=() [3/4]

bool operator!= ( const Time _time) const

Equal to operator.

Parameters
[in]_timethe time to compare to
Returns
true if values are the same, false otherwise

§ operator!=() [4/4]

bool operator!= ( double  _time) const

Equal to operator.

Parameters
[in]_timethe time to compare to
Returns
true if values are the same, false otherwise

§ operator*() [1/3]

Time operator* ( const struct timeval &  _tv) const

Multiplication operator.

Parameters
[in]_tvThe scaling duration
Returns
Time instance

§ operator*() [2/3]

Time operator* ( const struct timespec &  _tv) const

Multiplication operator.

Parameters
[in]_tvthe scaling duration
Returns
Time instance

§ operator*() [3/3]

Time operator* ( const Time _time) const

Multiplication operators.

Parameters
[in]_timethe scaling factor
Returns
a scaled Time instance

§ operator*=() [1/3]

const Time& operator*= ( const struct timeval &  _tv)

Multiplication assignment operator.

Parameters
[in]_tvthe scaling duration
Returns
a reference to this instance

§ operator*=() [2/3]

const Time& operator*= ( const struct timespec &  _tv)

Multiplication assignment operator.

Parameters
[in]_tvthe scaling duration
Returns
a reference to this instance

§ operator*=() [3/3]

const Time& operator*= ( const Time _time)

Multiplication operators.

Parameters
[in]_timescale factor
Returns
a scaled Time instance

§ operator+() [1/3]

Time operator+ ( const struct timeval &  _tv) const

Addition operators.

Parameters
[in]_tvthe time to add
Returns
a Time instance

§ operator+() [2/3]

Time operator+ ( const struct timespec &  _tv) const

Addition operators.

Parameters
[in]_tvthe time to add
Returns
a Time instance

§ operator+() [3/3]

Time operator+ ( const Time _time) const

Addition operators.

Parameters
[in]_timeThe time to add
Returns
a Time instance

§ operator+=() [1/3]

const Time& operator+= ( const struct timeval &  _tv)

Addition assignment operator.

Parameters
[in]_tvthe time to add
Returns
a reference to this instance

§ operator+=() [2/3]

const Time& operator+= ( const struct timespec &  _tv)

Addition assignment operator.

Parameters
[in]_tvthe time to add
Returns
a reference to this instance

§ operator+=() [3/3]

const Time& operator+= ( const Time _time)

Addition assignemtn operator.

Parameters
[in]_timeThe time to add
Returns
a Time instance

§ operator-() [1/3]

Time operator- ( const struct timeval &  _tv) const

Subtraction operator.

Parameters
[in]_tvThe time to subtract
Returns
a Time instance

§ operator-() [2/3]

Time operator- ( const struct timespec &  _tv) const

Subtraction operator.

Parameters
[in]_tvThe time to subtract
Returns
a Time instance

§ operator-() [3/3]

Time operator- ( const Time _time) const

Subtraction operator.

Parameters
[in]_timeThe time to subtract
Returns
a Time instance

§ operator-=() [1/3]

const Time& operator-= ( const struct timeval &  _tv)

Subtraction assignment operator.

Parameters
[in]_tvThe time to subtract
Returns
a Time instance

§ operator-=() [2/3]

const Time& operator-= ( const struct timespec &  _tv)

Subtraction assignment operator.

Parameters
[in]_tvThe time to subtract
Returns
a Time instance

§ operator-=() [3/3]

const Time& operator-= ( const Time _time)

Subtraction assignment operator.

Parameters
[in]_timeThe time to subtract
Returns
a reference to this instance

§ operator/() [1/3]

Time operator/ ( const struct timeval &  _tv) const

Division operator.

Parameters
[in]_tva timeval divisor
Returns
a Time instance

§ operator/() [2/3]

Time operator/ ( const struct timespec &  _tv) const

Division operator.

Parameters
[in]_tva timespec divisor
Returns
a Time instance

§ operator/() [3/3]

Time operator/ ( const Time _time) const

Division operator.

Parameters
[in]_timethe divisor
Returns
a Time instance

§ operator/=() [1/3]

const Time& operator/= ( const struct timeval &  _tv)

Division assignment operator.

Parameters
[in]_tva divisor
Returns
a Time instance

§ operator/=() [2/3]

const Time& operator/= ( const struct timespec &  _tv)

Division assignment operator.

Parameters
[in]_tva divisor
Returns
a Time instance

§ operator/=() [3/3]

const Time& operator/= ( const Time time)

Division assignment operator.

Parameters
[in]timethe divisor
Returns
a Time instance

§ operator<() [1/4]

bool operator< ( const struct timeval &  _tv) const

Less than operator.

Parameters
[in]_tvthe time to compare with
Returns
true if tv is shorter than this, false otherwise

§ operator<() [2/4]

bool operator< ( const struct timespec &  _tv) const

Less than operator.

Parameters
[in]_tvthe time to compare with
Returns
true if tv is shorter than this, false otherwise

§ operator<() [3/4]

bool operator< ( const Time _time) const

Less than operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is shorter than this, false otherwise

§ operator<() [4/4]

bool operator< ( double  _time) const

Less than operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is shorter than this, false otherwise

§ operator<=() [1/4]

bool operator<= ( const struct timeval &  _tv) const

Less than or equal to operator.

Parameters
[in]_tvthe time to compare with
Returns
true if tv is shorter than or equal to this, false otherwise

§ operator<=() [2/4]

bool operator<= ( const struct timespec &  _tv) const

Less than or equal to operator.

Parameters
[in]_tvthe time to compare with
Returns
true if tv is shorter than or equal to this, false otherwise

§ operator<=() [3/4]

bool operator<= ( const Time _time) const

Less than or equal to operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is shorter than or equal to this, false otherwise

§ operator<=() [4/4]

bool operator<= ( double  _time) const

Less than or equal to operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is shorter than or equal to this, false otherwise

§ operator=() [1/3]

Time& operator= ( const struct timeval &  _tv)

Assignment operator.

Parameters
[in]_tvthe new time
Returns
a reference to this instance

§ operator=() [2/3]

Time& operator= ( const struct timespec &  _tv)

Assignment operator.

Parameters
[in]_tvthe new time
Returns
a reference to this instance

§ operator=() [3/3]

Time& operator= ( const Time _time)

Assignment operator.

Parameters
[in]_timethe new time
Returns
a reference to this instance

§ operator==() [1/4]

bool operator== ( const struct timeval &  _tv) const

Equal to operator.

Parameters
[in]_tvthe time to compare to
Returns
true if values are the same, false otherwise

§ operator==() [2/4]

bool operator== ( const struct timespec &  _tv) const

Equal to operator.

Parameters
[in]_tvthe time to compare to
Returns
true if values are the same, false otherwise

§ operator==() [3/4]

bool operator== ( const Time _time) const

Equal to operator.

Parameters
[in]_timethe time to compare to
Returns
true if values are the same, false otherwise

§ operator==() [4/4]

bool operator== ( double  _time) const

Equal to operator.

Parameters
[in]_timethe time to compare to
Returns
true if values are the same, false otherwise

§ operator>() [1/4]

bool operator> ( const struct timeval &  _tv) const

Greater than operator.

Parameters
[in]_tvthe time to compare with
Returns
true if time is greater than this, false otherwise

§ operator>() [2/4]

bool operator> ( const struct timespec &  _tv) const

Greater than operator.

Parameters
[in]_tvthe time to compare with
Returns
true if time is greater than this, false otherwise

§ operator>() [3/4]

bool operator> ( const Time _time) const

Greater than operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is greater than this, false otherwise

§ operator>() [4/4]

bool operator> ( double  _time) const

Greater than operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is greater than this, false otherwise

§ operator>=() [1/4]

bool operator>= ( const struct timeval &  _tv) const

Greater than or equal operator.

Parameters
[in]_tvthe time to compare with
Returns
true if tv is greater than or equal to this, false otherwise

§ operator>=() [2/4]

bool operator>= ( const struct timespec &  _tv) const

Greater than or equal operator.

Parameters
[in]_tvthe time to compare with
Returns
true if tv is greater than or equal to this, false otherwise

§ operator>=() [3/4]

bool operator>= ( const Time _time) const

Greater than or equal operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is greater than or equal to this, false otherwise

§ operator>=() [4/4]

bool operator>= ( double  _time) const

Greater than or equal operator.

Parameters
[in]_timethe time to compare with
Returns
true if time is greater than or equal to this, false otherwise

§ SecToNano()

static double SecToNano ( double  _sec)
inlinestatic

Convert seconds to nanoseconds.

Parameters
[in]_secduration in seconds
Returns
nanoseconds

§ Set() [1/2]

void Set ( int32_t  _sec,
int32_t  _nsec 
)

Set to sec and nsec.

Parameters
[in]_secSeconds
[in]_nsecNanoseconds

§ Set() [2/2]

void Set ( double  _seconds)

Set to seconds.

Parameters
[in]_secondsNumber of seconds

§ SetToWallTime()

void SetToWallTime ( )

Set the time to the wall time.

§ Sleep()

static Time Sleep ( const common::Time _time)
static

Sleep for the specified time.

Parameters
[in]_timeSleep time
Returns
Time actually slept

Friends And Related Function Documentation

§ operator<<

std::ostream& operator<< ( std::ostream &  _out,
const gazebo::common::Time _time 
)
friend

Stream insertion operator.

Parameters
[in]_outthe output stream
[in]_timetime to write to the stream
Returns
the output stream

§ operator>>

std::istream& operator>> ( std::istream &  _in,
gazebo::common::Time _time 
)
friend

Stream extraction operator.

Parameters
[in]_inthe input stream
[in]_timetime to read from to the stream
Returns
the input stream

Member Data Documentation

§ Hour

const Time Hour
static

A static time variable set to an hour: common::Time(3600, 0).

§ nsec

int32_t nsec

Nanoseconds.

§ nsInMs

const int32_t nsInMs
static

Constant multiplier to convert from nanoseconds to milliseconds.

§ nsInSec

const int32_t nsInSec
static

Constant multiplier to convert from nanoseconds to seconds.

§ sec

int32_t sec

Seconds.

§ Second

const Time Second
static

A static time variable set to a second: common::Time(1, 0).

§ Zero

const Time Zero
static

A static zero time variable set to common::Time(0, 0).


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