Gazebo Common

API Reference

3.17.0

A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec. 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 struct timespec &_tv)
 Constructor. More...
 
 Time (const Time &_time)
 Copy constructor. More...
 
 Time (double _time)
 Constuctor. More...
 
 Time (int32_t _sec, int32_t _nsec)
 Constructor. 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=FormatOption::DAYS, FormatOption _end=FormatOption::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 Time &_time) const
 Equal to operator. More...
 
bool operator!= (double _time) const
 Equal to 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 timespec &_tv)
 Multiplication assignment operator. More...
 
const Timeoperator*= (const Time &_time)
 Multiplication operators. More...
 
Time operator+ (const Time &_time) const
 Addition operators. More...
 
const Timeoperator+= (const Time &_time)
 Addition assignemtn 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 timespec &_tv)
 Subtraction assignment operator. More...
 
const Timeoperator-= (const Time &_time)
 Subtraction assignment operator. More...
 
Time operator/ (const Time &_time) const
 Division operator. More...
 
const Timeoperator/= (const struct timespec &_tv)
 Division assignment operator. More...
 
const Timeoperator/= (const Time &time)
 Division assignment operator. More...
 
bool operator< (const Time &_time) const
 Less than operator. More...
 
bool operator< (double _time) const
 Less than 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 Time &_time)
 Assignment 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 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 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 (double _seconds)
 Set to seconds. More...
 
void Set (int32_t _sec, int32_t _nsec)
 Set to sec and nsec. More...
 

Static Public Member Functions

static Time Sleep (const common::Time &_time)
 Sleep for the specified time. More...
 
static const TimeSystemTime ()
 Get the wall time. More...
 

Public Attributes

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

Static Public Attributes

static const Time Zero
 A static zero time variable set to common::Time(0, 0). 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

enum FormatOption
strong
Enumerator
DAYS 

Days.

HOURS 

Hours.

MINUTES 

Minutes.

SECONDS 

Seconds.

MILLISECONDS 

Milliseconds.

Constructor & Destructor Documentation

◆ Time() [1/5]

Time ( )

Constructors.

◆ Time() [2/5]

Time ( const Time _time)

Copy constructor.

Parameters
[in]timeTime to copy

◆ Time() [3/5]

Time ( const struct timespec &  _tv)
explicit

Constructor.

Parameters
[in]_tvTime to initialize to

◆ Time() [4/5]

Time ( int32_t  _sec,
int32_t  _nsec 
)

Constructor.

Parameters
[in]_secSeconds
[in]_nsecNanoseconds

◆ Time() [5/5]

Time ( double  _time)
explicit

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 = FormatOption::DAYS,
FormatOption  _end = FormatOption::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.

◆ operator!=() [1/2]

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!=() [2/2]

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/2]

Time operator* ( const struct timespec &  _tv) const

Multiplication operator.

Parameters
[in]_tvthe scaling duration
Returns
Time instance

◆ operator*() [2/2]

Time operator* ( const Time _time) const

Multiplication operators.

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

◆ operator*=() [1/2]

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

Multiplication assignment operator.

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

◆ operator*=() [2/2]

const Time& operator*= ( const Time _time)

Multiplication operators.

Parameters
[in]_timescale factor
Returns
a scaled Time instance

◆ operator+()

Time operator+ ( const Time _time) const

Addition operators.

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

◆ operator+=()

const Time& operator+= ( const Time _time)

Addition assignemtn operator.

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

◆ operator-() [1/2]

Time operator- ( const struct timespec &  _tv) const

Subtraction operator.

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

◆ operator-() [2/2]

Time operator- ( const Time _time) const

Subtraction operator.

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

◆ operator-=() [1/2]

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

Subtraction assignment operator.

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

◆ operator-=() [2/2]

const Time& operator-= ( const Time _time)

Subtraction assignment operator.

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

◆ operator/()

Time operator/ ( const Time _time) const

Division operator.

Parameters
[in]_timethe divisor
Returns
a Time instance

◆ operator/=() [1/2]

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

Division assignment operator.

Parameters
[in]_tva divisor
Returns
a Time instance

◆ operator/=() [2/2]

const Time& operator/= ( const Time time)

Division assignment operator.

Parameters
[in]timethe divisor
Returns
a Time instance

◆ operator<() [1/2]

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<() [2/2]

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/2]

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<=() [2/2]

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=()

Time& operator= ( const Time _time)

Assignment operator.

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

◆ operator==() [1/2]

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==() [2/2]

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]

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>() [2/3]

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>() [3/3]

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/3]

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>=() [2/3]

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>=() [3/3]

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

◆ Set() [1/2]

void Set ( double  _seconds)

Set to seconds.

Parameters
[in]_secondsNumber of seconds

◆ Set() [2/2]

void Set ( int32_t  _sec,
int32_t  _nsec 
)

Set to sec and nsec.

Parameters
[in]_secSeconds
[in]_nsecNanoseconds

◆ Sleep()

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

Sleep for the specified time.

Parameters
[in]_timeSleep time
Returns
On OSX and Linux the return value is the time slept, as reported by nanosleep for OSX and clock_nanosleep for Linux. The return value does not include time spent before and after the actual call to the system's sleep function.

On Windows the return value is always common::Time::Zero.

◆ SystemTime()

static const Time& SystemTime ( )
static

Get the wall time.

Returns
the current time

Member Data Documentation

◆ nsec

int32_t nsec

Nanoseconds.

◆ sec

int32_t sec

Seconds.

◆ 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: