18 #ifndef _GAZEBO_COMMON_TIME_HH_ 19 #define _GAZEBO_COMMON_TIME_HH_ 39 #define GZ_SEC_TO_HOUR(_s) ((_s) / 3600.0) 47 class GZ_COMMON_VISIBLE
Time 84 public:
Time(
const struct timeval &_tv);
89 public:
Time(
const struct timespec &_tv);
94 public:
Time(int32_t _sec, int32_t _nsec);
99 public:
Time(
double _time);
102 public:
virtual ~
Time();
108 public:
static Time Maximum();
112 public:
static const Time &GetWallTime();
116 public:
static const std::string &GetWallTimeAsISOString();
119 public:
void SetToWallTime();
124 public:
void Set(int32_t _sec, int32_t _nsec);
128 public:
void Set(
double _seconds);
132 public:
double Double()
const;
136 public:
float Float()
const;
143 public: std::string FormattedString(
FormatOption _start = DAYS,
154 public:
static Time MSleep(
unsigned int _ms);
159 public:
static Time NSleep(
unsigned int _ns);
164 public:
Time &operator =(
const struct timeval &_tv);
169 public:
Time &operator =(
const struct timespec &_tv);
174 public:
Time &operator =(
const Time &_time);
179 public:
Time operator +(
const struct timeval &_tv)
const;
184 public:
Time operator +(
const struct timespec &_tv)
const;
189 public:
const Time &operator +=(
const struct timeval &_tv);
194 public:
const Time &operator +=(
const struct timespec &_tv);
199 public:
Time operator +(
const Time &_time)
const;
204 public:
const Time &operator +=(
const Time &_time);
209 public:
Time operator -(
const struct timeval &_tv)
const;
214 public:
const Time &operator -=(
const struct timeval &_tv);
219 public:
Time operator -(
const struct timespec &_tv)
const;
224 public:
const Time &operator -=(
const struct timespec &_tv);
229 public:
Time operator -(
const Time &_time)
const;
234 public:
const Time &operator -=(
const Time &_time);
239 public:
Time operator *(
const struct timeval &_tv)
const;
244 public:
const Time &operator *=(
const struct timeval &_tv);
249 public:
Time operator *(
const struct timespec &_tv)
const;
254 public:
const Time &operator *=(
const struct timespec &_tv);
259 public:
Time operator *(
const Time &_time)
const;
264 public:
const Time &operator *=(
const Time &_time);
269 public:
Time operator /(
const struct timeval &_tv)
const;
274 public:
const Time &operator /=(
const struct timeval &_tv);
279 public:
Time operator /(
const struct timespec &_tv)
const;
284 public:
const Time &operator /=(
const struct timespec &_tv);
289 public:
Time operator /(
const Time &_time)
const;
294 public:
const Time &operator /=(
const Time &time);
299 public:
bool operator ==(
const struct timeval &_tv)
const;
304 public:
bool operator ==(
const struct timespec &_tv)
const;
309 public:
bool operator ==(
const Time &_time)
const;
314 public:
bool operator ==(
double _time)
const;
319 public:
bool operator!=(
const struct timeval &_tv)
const;
324 public:
bool operator!=(
const struct timespec &_tv)
const;
329 public:
bool operator!=(
const Time &_time)
const;
334 public:
bool operator!=(
double _time)
const;
339 public:
bool operator<(
const struct timeval &_tv)
const;
344 public:
bool operator<(
const struct timespec &_tv)
const;
349 public:
bool operator<(
const Time &_time)
const;
354 public:
bool operator<(
double _time)
const;
359 public:
bool operator<=(
const struct timeval &_tv)
const;
364 public:
bool operator<=(
const struct timespec &_tv)
const;
369 public:
bool operator<=(
const Time &_time)
const;
374 public:
bool operator<=(
double _time)
const;
379 public:
bool operator>(
const struct timeval &_tv)
const;
384 public:
bool operator>(
const struct timespec &_tv)
const;
389 public:
bool operator>(
const Time &_time)
const;
394 public:
bool operator>(
double _time)
const;
399 public:
bool operator>=(
const struct timeval &_tv)
const;
404 public:
bool operator>=(
const struct timespec &_tv)
const;
409 public:
bool operator>=(
const Time &_time)
const;
414 public:
bool operator>=(
double _time)
const;
420 {
return _sec * 1e9;}
441 _out << _time.
sec <<
" " << _time.
nsec;
453 _in.setf(std::ios_base::skipws);
454 _in >> _time.
sec >> _time.
nsec;
472 private:
static Time wallTime;
475 private:
static std::string wallTimeISO;
479 private:
inline void Correct()
482 if (this->sec > 0 && this->nsec < 0)
484 int32_t n = abs(this->nsec / this->nsInSec) + 1;
486 this->nsec += n * this->nsInSec;
488 if (this->sec < 0 && this->nsec > 0)
490 int32_t n = abs(this->nsec / this->nsInSec) + 1;
492 this->nsec -= n * this->nsInSec;
496 this->sec += this->nsec / this->nsInSec;
497 this->nsec = this->nsec % this->nsInSec;
500 private:
static struct timespec clockResolution;
static const int32_t nsInSec
Constant multiplier to convert from nanoseconds to seconds.
Definition: Time.hh:465
Forward declarations for the common classes.
Definition: Animation.hh:26
int32_t nsec
Nanoseconds.
Definition: Time.hh:462
static const Time Hour
A static time variable set to an hour: common::Time(3600, 0).
Definition: Time.hh:56
int32_t sec
Seconds.
Definition: Time.hh:459
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Time &_time)
Stream insertion operator.
Definition: Time.hh:438
static const int32_t nsInMs
Constant multiplier to convert from nanoseconds to milliseconds.
Definition: Time.hh:469
static double MilToNano(double _ms)
Convert milliseconds to nanoseconds.
Definition: Time.hh:425
FormatOption
Definition: Time.hh:60
static double MicToNano(double _ms)
Convert microseconds to nanoseconds.
Definition: Time.hh:431
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:419
common
Definition: FuelModelDatabase.hh:37
friend std::istream & operator>>(std::istream &_in, gazebo::common::Time &_time)
Stream extraction operator.
Definition: Time.hh:449
static const Time Second
A static time variable set to a second: common::Time(1, 0).
Definition: Time.hh:53
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: Time.hh:50
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:47