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 Time & | operator*= (const struct timeval &_tv) |
Multiplication assignment operator. More... | |
const Time & | operator*= (const struct timespec &_tv) |
Multiplication assignment operator. More... | |
const Time & | operator*= (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 Time & | operator+= (const struct timeval &_tv) |
Addition assignment operator. More... | |
const Time & | operator+= (const struct timespec &_tv) |
Addition assignment operator. More... | |
const Time & | operator+= (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 Time & | operator-= (const struct timeval &_tv) |
Subtraction assignment operator. More... | |
const Time & | operator-= (const struct timespec &_tv) |
Subtraction assignment operator. More... | |
const Time & | operator-= (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 Time & | operator/= (const struct timeval &_tv) |
Division assignment operator. More... | |
const Time & | operator/= (const struct timespec &_tv) |
Division assignment operator. More... | |
const Time & | operator/= (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... | |
Time & | operator= (const struct timeval &_tv) |
Assignment operator. More... | |
Time & | operator= (const struct timespec &_tv) |
Assignment operator. More... | |
Time & | operator= (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 Time & | GetWallTime () |
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... | |
A Time class, can be used to hold wall- or sim-time.
stored as sec and nano-sec.
enum FormatOption |
Time | ( | ) |
Constructors.
Time | ( | int32_t | _sec, |
int32_t | _nsec | ||
) |
Constructor.
[in] | _sec | Seconds |
[in] | _nsec | Nanoseconds |
|
virtual |
Destructor.
double Double | ( | ) | const |
Get the time as a double.
float Float | ( | ) | const |
Get the time as a float.
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.
[in] | _start | Start point. |
[in] | _end | End point. |
|
static |
Get the wall time.
|
static |
Get the wall time as an ISO string: YYYY-MM-DDTHH:MM:SS.
|
inlinestatic |
Convert microseconds to nanoseconds.
_ms | microseconds |
|
inlinestatic |
Convert milliseconds to nanoseconds.
[in] | _ms | milliseconds |
|
static |
|
static |
bool operator!= | ( | const struct timeval & | _tv | ) | const |
Equal to operator.
[in] | _tv | the time to compare to |
bool operator!= | ( | const struct timespec & | _tv | ) | const |
Equal to operator.
[in] | _tv | the time to compare to |
bool operator!= | ( | const Time & | _time | ) | const |
Equal to operator.
[in] | _time | the time to compare to |
bool operator!= | ( | double | _time | ) | const |
Equal to operator.
[in] | _time | the time to compare to |
Time operator* | ( | const struct timeval & | _tv | ) | const |
Time operator* | ( | const struct timespec & | _tv | ) | const |
const Time& operator*= | ( | const struct timeval & | _tv | ) |
Multiplication assignment operator.
[in] | _tv | the scaling duration |
const Time& operator*= | ( | const struct timespec & | _tv | ) |
Multiplication assignment operator.
[in] | _tv | the scaling duration |
Time operator+ | ( | const struct timeval & | _tv | ) | const |
Time operator+ | ( | const struct timespec & | _tv | ) | const |
const Time& operator+= | ( | const struct timeval & | _tv | ) |
Addition assignment operator.
[in] | _tv | the time to add |
const Time& operator+= | ( | const struct timespec & | _tv | ) |
Addition assignment operator.
[in] | _tv | the time to add |
Time operator- | ( | const struct timeval & | _tv | ) | const |
Time operator- | ( | const struct timespec & | _tv | ) | const |
const Time& operator-= | ( | const struct timeval & | _tv | ) |
const Time& operator-= | ( | const struct timespec & | _tv | ) |
Subtraction assignment operator.
[in] | _time | The time to subtract |
Time operator/ | ( | const struct timeval & | _tv | ) | const |
Time operator/ | ( | const struct timespec & | _tv | ) | const |
const Time& operator/= | ( | const struct timeval & | _tv | ) |
const Time& operator/= | ( | const struct timespec & | _tv | ) |
bool operator< | ( | const struct timeval & | _tv | ) | const |
Less than operator.
[in] | _tv | the time to compare with |
bool operator< | ( | const struct timespec & | _tv | ) | const |
Less than operator.
[in] | _tv | the time to compare with |
bool operator< | ( | const Time & | _time | ) | const |
Less than operator.
[in] | _time | the time to compare with |
bool operator< | ( | double | _time | ) | const |
Less than operator.
[in] | _time | the time to compare with |
bool operator<= | ( | const struct timeval & | _tv | ) | const |
Less than or equal to operator.
[in] | _tv | the time to compare with |
bool operator<= | ( | const struct timespec & | _tv | ) | const |
Less than or equal to operator.
[in] | _tv | the time to compare with |
bool operator<= | ( | const Time & | _time | ) | const |
Less than or equal to operator.
[in] | _time | the time to compare with |
bool operator<= | ( | double | _time | ) | const |
Less than or equal to operator.
[in] | _time | the time to compare with |
Time& operator= | ( | const struct timeval & | _tv | ) |
Assignment operator.
[in] | _tv | the new time |
Time& operator= | ( | const struct timespec & | _tv | ) |
Assignment operator.
[in] | _tv | the new time |
Assignment operator.
[in] | _time | the new time |
bool operator== | ( | const struct timeval & | _tv | ) | const |
Equal to operator.
[in] | _tv | the time to compare to |
bool operator== | ( | const struct timespec & | _tv | ) | const |
Equal to operator.
[in] | _tv | the time to compare to |
bool operator== | ( | const Time & | _time | ) | const |
Equal to operator.
[in] | _time | the time to compare to |
bool operator== | ( | double | _time | ) | const |
Equal to operator.
[in] | _time | the time to compare to |
bool operator> | ( | const struct timeval & | _tv | ) | const |
Greater than operator.
[in] | _tv | the time to compare with |
bool operator> | ( | const struct timespec & | _tv | ) | const |
Greater than operator.
[in] | _tv | the time to compare with |
bool operator> | ( | const Time & | _time | ) | const |
Greater than operator.
[in] | _time | the time to compare with |
bool operator> | ( | double | _time | ) | const |
Greater than operator.
[in] | _time | the time to compare with |
bool operator>= | ( | const struct timeval & | _tv | ) | const |
Greater than or equal operator.
[in] | _tv | the time to compare with |
bool operator>= | ( | const struct timespec & | _tv | ) | const |
Greater than or equal operator.
[in] | _tv | the time to compare with |
bool operator>= | ( | const Time & | _time | ) | const |
Greater than or equal operator.
[in] | _time | the time to compare with |
bool operator>= | ( | double | _time | ) | const |
Greater than or equal operator.
[in] | _time | the time to compare with |
|
inlinestatic |
Convert seconds to nanoseconds.
[in] | _sec | duration in seconds |
void Set | ( | int32_t | _sec, |
int32_t | _nsec | ||
) |
Set to sec and nsec.
[in] | _sec | Seconds |
[in] | _nsec | Nanoseconds |
void Set | ( | double | _seconds | ) |
Set to seconds.
[in] | _seconds | Number of seconds |
void SetToWallTime | ( | ) |
Set the time to the wall time.
|
static |
|
friend |
Stream insertion operator.
[in] | _out | the output stream |
[in] | _time | time to write to the stream |
|
friend |
Stream extraction operator.
[in] | _in | the input stream |
[in] | _time | time to read from to the stream |
|
static |
A static time variable set to an hour: common::Time(3600, 0).
int32_t nsec |
Nanoseconds.
|
static |
Constant multiplier to convert from nanoseconds to milliseconds.
|
static |
Constant multiplier to convert from nanoseconds to seconds.
int32_t sec |
Seconds.
|
static |
A static time variable set to a second: common::Time(1, 0).
|
static |
A static zero time variable set to common::Time(0, 0).