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 81 public:
Time(
const struct timeval &_tv);
86 public:
Time(
const struct timespec &_tv);
91 public:
Time(int32_t _sec, int32_t _nsec);
96 public:
Time(
double _time);
99 public:
virtual ~
Time();
105 public:
static Time Maximum();
109 public:
static const Time &GetWallTime();
113 public:
static const std::string &GetWallTimeAsISOString();
116 public:
void SetToWallTime();
121 public:
void Set(int32_t _sec, int32_t _nsec);
125 public:
void Set(
double _seconds);
129 public:
double Double()
const;
133 public:
float Float()
const;
140 public: std::string FormattedString(
FormatOption _start = DAYS,
151 public:
static Time MSleep(
unsigned int _ms);
156 public:
static Time NSleep(
unsigned int _ns);
161 public:
Time &operator =(
const struct timeval &_tv);
166 public:
Time &operator =(
const struct timespec &_tv);
171 public:
Time &operator =(
const Time &_time);
176 public:
Time operator +(
const struct timeval &_tv)
const;
181 public:
Time operator +(
const struct timespec &_tv)
const;
186 public:
const Time &operator +=(
const struct timeval &_tv);
191 public:
const Time &operator +=(
const struct timespec &_tv);
196 public:
Time operator +(
const Time &_time)
const;
201 public:
const Time &operator +=(
const Time &_time);
206 public:
Time operator -(
const struct timeval &_tv)
const;
211 public:
const Time &operator -=(
const struct timeval &_tv);
216 public:
Time operator -(
const struct timespec &_tv)
const;
221 public:
const Time &operator -=(
const struct timespec &_tv);
226 public:
Time operator -(
const Time &_time)
const;
231 public:
const Time &operator -=(
const Time &_time);
236 public:
Time operator *(
const struct timeval &_tv)
const;
241 public:
const Time &operator *=(
const struct timeval &_tv);
246 public:
Time operator *(
const struct timespec &_tv)
const;
251 public:
const Time &operator *=(
const struct timespec &_tv);
256 public:
Time operator *(
const Time &_time)
const;
261 public:
const Time &operator *=(
const Time &_time);
266 public:
Time operator /(
const struct timeval &_tv)
const;
271 public:
const Time &operator /=(
const struct timeval &_tv);
276 public:
Time operator /(
const struct timespec &_tv)
const;
281 public:
const Time &operator /=(
const struct timespec &_tv);
286 public:
Time operator /(
const Time &_time)
const;
291 public:
const Time &operator /=(
const Time &time);
296 public:
bool operator ==(
const struct timeval &_tv)
const;
301 public:
bool operator ==(
const struct timespec &_tv)
const;
306 public:
bool operator ==(
const Time &_time)
const;
311 public:
bool operator ==(
double _time)
const;
316 public:
bool operator!=(
const struct timeval &_tv)
const;
321 public:
bool operator!=(
const struct timespec &_tv)
const;
326 public:
bool operator!=(
const Time &_time)
const;
331 public:
bool operator!=(
double _time)
const;
336 public:
bool operator<(
const struct timeval &_tv)
const;
341 public:
bool operator<(
const struct timespec &_tv)
const;
346 public:
bool operator<(
const Time &_time)
const;
351 public:
bool operator<(
double _time)
const;
356 public:
bool operator<=(
const struct timeval &_tv)
const;
361 public:
bool operator<=(
const struct timespec &_tv)
const;
366 public:
bool operator<=(
const Time &_time)
const;
371 public:
bool operator<=(
double _time)
const;
376 public:
bool operator>(
const struct timeval &_tv)
const;
381 public:
bool operator>(
const struct timespec &_tv)
const;
386 public:
bool operator>(
const Time &_time)
const;
391 public:
bool operator>(
double _time)
const;
396 public:
bool operator>=(
const struct timeval &_tv)
const;
401 public:
bool operator>=(
const struct timespec &_tv)
const;
406 public:
bool operator>=(
const Time &_time)
const;
411 public:
bool operator>=(
double _time)
const;
417 {
return _sec * 1e9;}
438 _out << _time.
sec <<
" " << _time.
nsec;
450 _in.setf(std::ios_base::skipws);
451 _in >> _time.
sec >> _time.
nsec;
469 private:
static Time wallTime;
472 private:
static std::string wallTimeISO;
476 private:
inline void Correct()
479 if (this->sec > 0 && this->nsec < 0)
481 int32_t n = abs(this->nsec / this->nsInSec) + 1;
483 this->nsec += n * this->nsInSec;
485 if (this->sec < 0 && this->nsec > 0)
487 int32_t n = abs(this->nsec / this->nsInSec) + 1;
489 this->nsec -= n * this->nsInSec;
493 this->sec += this->nsec / this->nsInSec;
494 this->nsec = this->nsec % this->nsInSec;
497 private:
static struct timespec clockResolution;
static const int32_t nsInSec
Constant multiplier to convert from nanoseconds to seconds.
Definition: Time.hh:462
Forward declarations for the common classes.
Definition: Animation.hh:26
int32_t nsec
Nanoseconds.
Definition: Time.hh:459
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:456
friend std::ostream & operator<<(std::ostream &_out, const gazebo::common::Time &_time)
Stream insertion operator.
Definition: Time.hh:435
static const int32_t nsInMs
Constant multiplier to convert from nanoseconds to milliseconds.
Definition: Time.hh:466
static double MilToNano(double _ms)
Convert milliseconds to nanoseconds.
Definition: Time.hh:422
FormatOption
Definition: Time.hh:57
static double MicToNano(double _ms)
Convert microseconds to nanoseconds.
Definition: Time.hh:428
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:416
friend std::istream & operator>>(std::istream &_in, gazebo::common::Time &_time)
Stream extraction operator.
Definition: Time.hh:446
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