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 Time & | operator*= (const struct timespec &_tv) |
| Multiplication assignment operator. More... | |
| const Time & | operator*= (const Time &_time) |
| Multiplication operators. More... | |
| Time | operator+ (const Time &_time) const |
| Addition operators. More... | |
| const Time & | operator+= (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 Time & | operator-= (const struct timespec &_tv) |
| Subtraction assignment operator. More... | |
| const Time & | operator-= (const Time &_time) |
| Subtraction assignment operator. More... | |
| Time | operator/ (const Time &_time) const |
| Division 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 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... | |
| Time & | operator= (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 Time & | SystemTime () |
| 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
|
strong |
Constructor & Destructor Documentation
◆ Time() [1/5]
| Time | ( | ) |
Constructors.
◆ Time() [2/5]
◆ Time() [3/5]
◆ Time() [4/5]
| Time | ( | int32_t | _sec, |
| int32_t | _nsec | ||
| ) |
Constructor.
- Parameters
-
[in] _sec Seconds [in] _nsec Nanoseconds
◆ Time() [5/5]
◆ ~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] _start Start point. [in] _end End point.
- Returns
- String representing time.
◆ operator!=() [1/2]
| bool operator!= | ( | const Time & | _time | ) | const |
Equal to operator.
- Parameters
-
[in] _time the 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] _time the time to compare to
- Returns
- true if values are the same, false otherwise
◆ operator*() [1/2]
| Time operator* | ( | const struct timespec & | _tv | ) | const |
◆ operator*() [2/2]
◆ operator*=() [1/2]
| const Time& operator*= | ( | const struct timespec & | _tv | ) |
Multiplication assignment operator.
- Parameters
-
[in] _tv the scaling duration
- Returns
- a reference to this instance
◆ operator*=() [2/2]
◆ operator+()
◆ operator+=()
◆ operator-() [1/2]
| Time operator- | ( | const struct timespec & | _tv | ) | const |
◆ operator-() [2/2]
◆ operator-=() [1/2]
| const Time& operator-= | ( | const struct timespec & | _tv | ) |
◆ operator-=() [2/2]
Subtraction assignment operator.
- Parameters
-
[in] _time The time to subtract
- Returns
- a reference to this instance
◆ operator/()
◆ operator/=() [1/2]
| const Time& operator/= | ( | const struct timespec & | _tv | ) |
◆ operator/=() [2/2]
◆ operator<() [1/2]
| bool operator< | ( | const Time & | _time | ) | const |
Less than operator.
- Parameters
-
[in] _time the 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] _time the 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] _time the 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] _time the time to compare with
- Returns
- true if time is shorter than or equal to this, false otherwise
◆ operator=()
Assignment operator.
- Parameters
-
[in] _time the new time
- Returns
- a reference to this instance
◆ operator==() [1/2]
| bool operator== | ( | const Time & | _time | ) | const |
Equal to operator.
- Parameters
-
[in] _time the 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] _time the 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] _tv the 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] _time the 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] _time the 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] _tv the 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] _time the 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] _time the 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] _seconds Number of seconds
◆ Set() [2/2]
| void Set | ( | int32_t | _sec, |
| int32_t | _nsec | ||
| ) |
Set to sec and nsec.
- Parameters
-
[in] _sec Seconds [in] _nsec Nanoseconds
◆ Sleep()
|
static |
Sleep for the specified time.
- Parameters
-
[in] _time Sleep time
- Returns
- On OSX and Linux the return value is the time slept, as reported by
nanosleepfor OSX andclock_nanosleepfor 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 |
Get the wall time.
- Returns
- the current time
Member Data Documentation
◆ nsec
| int32_t nsec |
Nanoseconds.
◆ sec
| int32_t sec |
Seconds.
◆ Zero
|
static |
A static zero time variable set to common::Time(0, 0).
The documentation for this class was generated from the following file: