18 #ifndef _GAZEBO_COMMON_TIME_HH_
19 #define _GAZEBO_COMMON_TIME_HH_
75 public:
Time(
const struct timeval &_tv);
79 public:
Time(
const struct timespec &_tv);
84 public:
Time(int32_t _sec, int32_t _nsec);
88 public:
Time(
double _time);
91 public:
virtual ~
Time();
95 public:
static const Time &GetWallTime();
99 public:
static const std::string &GetWallTimeAsISOString();
102 public:
void SetToWallTime();
107 public:
void Set(int32_t _sec, int32_t _nsec);
111 public:
void Set(
double _seconds);
115 public:
double Double()
const;
119 public:
float Float()
const;
126 public: std::string FormattedString(FormatOption _start = DAYS,
127 FormatOption _end = MILLISECONDS)
const;
137 public:
static Time MSleep(
unsigned int _ms);
142 public:
static Time NSleep(
unsigned int _ns);
147 public:
Time &operator =(
const struct timeval &_tv);
152 public:
Time &operator =(
const struct timespec &_tv);
157 public:
Time &operator =(
const Time &_time);
162 public:
Time operator +(
const struct timeval &_tv)
const;
167 public:
Time operator +(
const struct timespec &_tv)
const;
172 public:
const Time &operator +=(
const struct timeval &_tv);
177 public:
const Time &operator +=(
const struct timespec &_tv);
182 public:
Time operator +(
const Time &_time)
const;
187 public:
const Time &operator +=(
const Time &_time);
192 public:
Time operator -(
const struct timeval &_tv)
const;
197 public:
const Time &operator -=(
const struct timeval &_tv);
202 public:
Time operator -(
const struct timespec &_tv)
const;
207 public:
const Time &operator -=(
const struct timespec &_tv);
212 public:
Time operator -(
const Time &_time)
const;
217 public:
const Time &operator -=(
const Time &_time);
222 public:
Time operator *(
const struct timeval &_tv)
const;
227 public:
const Time &operator *=(
const struct timeval &_tv);
232 public:
Time operator *(
const struct timespec &_tv)
const;
237 public:
const Time &operator *=(
const struct timespec &_tv);
242 public:
Time operator *(
const Time &_time)
const;
247 public:
const Time &operator *=(
const Time &_time);
252 public:
Time operator /(
const struct timeval &_tv)
const;
257 public:
const Time &operator /=(
const struct timeval &_tv);
262 public:
Time operator /(
const struct timespec &_tv)
const;
267 public:
const Time &operator /=(
const struct timespec &_tv);
272 public:
Time operator /(
const Time &_time)
const;
277 public:
const Time &operator /=(
const Time &time);
282 public:
bool operator ==(
const struct timeval &_tv)
const;
287 public:
bool operator ==(
const struct timespec &_tv)
const;
292 public:
bool operator ==(
const Time &_time)
const;
297 public:
bool operator ==(
double _time)
const;
302 public:
bool operator!=(
const struct timeval &_tv)
const;
307 public:
bool operator!=(
const struct timespec &_tv)
const;
312 public:
bool operator!=(
const Time &_time)
const;
317 public:
bool operator!=(
double _time)
const;
322 public:
bool operator<(
const struct timeval &_tv)
const;
327 public:
bool operator<(
const struct timespec &_tv)
const;
332 public:
bool operator<(
const Time &_time)
const;
337 public:
bool operator<(
double _time)
const;
342 public:
bool operator<=(
const struct timeval &_tv)
const;
347 public:
bool operator<=(
const struct timespec &_tv)
const;
352 public:
bool operator<=(
const Time &_time)
const;
357 public:
bool operator<=(
double _time)
const;
362 public:
bool operator>(
const struct timeval &_tv)
const;
367 public:
bool operator>(
const struct timespec &_tv)
const;
372 public:
bool operator>(
const Time &_time)
const;
377 public:
bool operator>(
double _time)
const;
382 public:
bool operator>=(
const struct timeval &_tv)
const;
387 public:
bool operator>=(
const struct timespec &_tv)
const;
392 public:
bool operator>=(
const Time &_time)
const;
397 public:
bool operator>=(
double _time)
const;
403 {
return _sec * 1e9;}
424 _out << _time.
sec <<
" " << _time.
nsec;
436 _in.setf(std::ios_base::skipws);
437 _in >> _time.
sec >> _time.
nsec;
448 private:
static Time wallTime;
451 private:
static std::string wallTimeISO;
455 private:
inline void Correct()
458 if (this->sec > 0 && this->nsec < 0)
460 int32_t n = abs(this->nsec / this->nsInSec) + 1;
462 this->nsec += n * this->nsInSec;
464 if (this->sec < 0 && this->nsec > 0)
466 int32_t n = abs(this->nsec / this->nsInSec) + 1;
468 this->nsec -= n * this->nsInSec;
472 this->sec += this->nsec / this->nsInSec;
473 this->nsec = this->nsec % this->nsInSec;
476 private:
static struct timespec clockResolution;
479 private:
static const int32_t nsInSec;
483 private:
static const int32_t nsInMs;
int32_t nsec
Nanoseconds.
Definition: Time.hh:445
static const Time Hour
A static time variable set to an hour: common::Time(3600, 0).
Definition: Time.hh:48
static double MilToNano(double _ms)
Convert milliseconds to nanoseconds.
Definition: Time.hh:408
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Time &_time)
Stream insertion operator.
Definition: Time.hh:421
#define GZ_COMMON_VISIBLE
Definition: system.hh:91
FormatOption
Definition: Time.hh:52
static const Time Second
A static time variable set to a second: common::Time(1, 0).
Definition: Time.hh:45
static double MicToNano(double _ms)
Convert microseconds to nanoseconds.
Definition: Time.hh:414
int32_t sec
Seconds.
Definition: Time.hh:442
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: Time.hh:42
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
friend std::istream & operator>>(std::istream &_in, gazebo::common::Time &_time)
Stream extraction operator.
Definition: Time.hh:432
static double SecToNano(double _sec)
Convert seconds to nanoseconds.
Definition: Time.hh:402
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:39