18 #ifndef _GAZEBO_COMMON_TIME_HH_ 19 #define _GAZEBO_COMMON_TIME_HH_ 36 #define GZ_SEC_TO_HOUR(_s) ((_s) / 3600.0) 44 class GZ_COMMON_VISIBLE
Time 80 public:
Time(
const struct timeval &_tv);
84 public:
Time(
const struct timespec &_tv);
89 public:
Time(int32_t _sec, int32_t _nsec);
93 public:
Time(
double _time);
96 public:
virtual ~
Time();
100 public:
static const Time &GetWallTime();
104 public:
static const std::string &GetWallTimeAsISOString();
107 public:
void SetToWallTime();
112 public:
void Set(int32_t _sec, int32_t _nsec);
116 public:
void Set(
double _seconds);
120 public:
double Double()
const;
124 public:
float Float()
const;
131 public: std::string FormattedString(
FormatOption _start = DAYS,
142 public:
static Time MSleep(
unsigned int _ms);
147 public:
static Time NSleep(
unsigned int _ns);
152 public:
Time &operator =(
const struct timeval &_tv);
157 public:
Time &operator =(
const struct timespec &_tv);
162 public:
Time &operator =(
const Time &_time);
167 public:
Time operator +(
const struct timeval &_tv)
const;
172 public:
Time operator +(
const struct timespec &_tv)
const;
177 public:
const Time &operator +=(
const struct timeval &_tv);
182 public:
const Time &operator +=(
const struct timespec &_tv);
187 public:
Time operator +(
const Time &_time)
const;
192 public:
const Time &operator +=(
const Time &_time);
197 public:
Time operator -(
const struct timeval &_tv)
const;
202 public:
const Time &operator -=(
const struct timeval &_tv);
207 public:
Time operator -(
const struct timespec &_tv)
const;
212 public:
const Time &operator -=(
const struct timespec &_tv);
217 public:
Time operator -(
const Time &_time)
const;
222 public:
const Time &operator -=(
const Time &_time);
227 public:
Time operator *(
const struct timeval &_tv)
const;
232 public:
const Time &operator *=(
const struct timeval &_tv);
237 public:
Time operator *(
const struct timespec &_tv)
const;
242 public:
const Time &operator *=(
const struct timespec &_tv);
247 public:
Time operator *(
const Time &_time)
const;
252 public:
const Time &operator *=(
const Time &_time);
257 public:
Time operator /(
const struct timeval &_tv)
const;
262 public:
const Time &operator /=(
const struct timeval &_tv);
267 public:
Time operator /(
const struct timespec &_tv)
const;
272 public:
const Time &operator /=(
const struct timespec &_tv);
277 public:
Time operator /(
const Time &_time)
const;
282 public:
const Time &operator /=(
const Time &time);
287 public:
bool operator ==(
const struct timeval &_tv)
const;
292 public:
bool operator ==(
const struct timespec &_tv)
const;
297 public:
bool operator ==(
const Time &_time)
const;
302 public:
bool operator ==(
double _time)
const;
307 public:
bool operator!=(
const struct timeval &_tv)
const;
312 public:
bool operator!=(
const struct timespec &_tv)
const;
317 public:
bool operator!=(
const Time &_time)
const;
322 public:
bool operator!=(
double _time)
const;
327 public:
bool operator<(
const struct timeval &_tv)
const;
332 public:
bool operator<(
const struct timespec &_tv)
const;
337 public:
bool operator<(
const Time &_time)
const;
342 public:
bool operator<(
double _time)
const;
347 public:
bool operator<=(
const struct timeval &_tv)
const;
352 public:
bool operator<=(
const struct timespec &_tv)
const;
357 public:
bool operator<=(
const Time &_time)
const;
362 public:
bool operator<=(
double _time)
const;
367 public:
bool operator>(
const struct timeval &_tv)
const;
372 public:
bool operator>(
const struct timespec &_tv)
const;
377 public:
bool operator>(
const Time &_time)
const;
382 public:
bool operator>(
double _time)
const;
387 public:
bool operator>=(
const struct timeval &_tv)
const;
392 public:
bool operator>=(
const struct timespec &_tv)
const;
397 public:
bool operator>=(
const Time &_time)
const;
402 public:
bool operator>=(
double _time)
const;
408 {
return _sec * 1e9;}
429 _out << _time.
sec <<
" " << _time.
nsec;
441 _in.setf(std::ios_base::skipws);
442 _in >> _time.
sec >> _time.
nsec;
460 private:
static Time wallTime;
463 private:
static std::string wallTimeISO;
467 private:
inline void Correct()
470 if (this->sec > 0 && this->nsec < 0)
472 int32_t n = abs(this->nsec / this->nsInSec) + 1;
474 this->nsec += n * this->nsInSec;
476 if (this->sec < 0 && this->nsec > 0)
478 int32_t n = abs(this->nsec / this->nsInSec) + 1;
480 this->nsec -= n * this->nsInSec;
484 this->sec += this->nsec / this->nsInSec;
485 this->nsec = this->nsec % this->nsInSec;
488 private:
static struct timespec clockResolution;
static const int32_t nsInSec
Constant multiplier to convert from nanoseconds to seconds.
Definition: Time.hh:453
Forward declarations for the common classes.
Definition: Animation.hh:33
int32_t nsec
Nanoseconds.
Definition: Time.hh:450
static const Time Hour
A static time variable set to an hour: common::Time(3600, 0).
Definition: Time.hh:53
int32_t sec
Seconds.
Definition: Time.hh:447
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Time &_time)
Stream insertion operator.
Definition: Time.hh:426
static const int32_t nsInMs
Constant multiplier to convert from nanoseconds to milliseconds.
Definition: Time.hh:457
static double MilToNano(double _ms)
Convert milliseconds to nanoseconds.
Definition: Time.hh:413
FormatOption
Definition: Time.hh:57
static double MicToNano(double _ms)
Convert microseconds to nanoseconds.
Definition: Time.hh:419
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
static double SecToNano(double _sec)
Convert seconds to nanoseconds.
Definition: Time.hh:407
friend std::istream & operator>>(std::istream &_in, gazebo::common::Time &_time)
Stream extraction operator.
Definition: Time.hh:437
static const Time Second
A static time variable set to a second: common::Time(1, 0).
Definition: Time.hh:50
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: Time.hh:47
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44