17 #ifndef IGNITION_COMMON_TIME_HH_ 18 #define IGNITION_COMMON_TIME_HH_ 23 #include <ignition/common/Export.hh> 33 class IGNITION_COMMON_VISIBLE
Time 63 public:
explicit Time(
const struct timespec &_tv);
68 public:
Time(int32_t _sec, int32_t _nsec);
72 public:
explicit Time(
double _time);
75 public:
virtual ~
Time();
79 public:
static const Time &SystemTime();
84 public:
void Set(int32_t _sec, int32_t _nsec);
88 public:
void Set(
double _seconds);
92 public:
double Double()
const;
96 public:
float Float()
const;
120 public:
Time &operator=(
const Time &_time);
125 public:
Time operator+(
const Time &_time)
const;
130 public:
const Time &operator +=(
const Time &_time);
135 public:
Time operator -(
const struct timespec &_tv)
const;
140 public:
const Time &operator -=(
const struct timespec &_tv);
145 public:
Time operator -(
const Time &_time)
const;
150 public:
const Time &operator -=(
const Time &_time);
155 public:
Time operator *(
const struct timespec &_tv)
const;
160 public:
const Time &operator *=(
const struct timespec &_tv);
165 public:
Time operator *(
const Time &_time)
const;
170 public:
const Time &operator *=(
const Time &_time);
175 public:
const Time &operator /=(
const struct timespec &_tv);
180 public:
Time operator /(
const Time &_time)
const;
185 public:
const Time &operator /=(
const Time &time);
190 public:
bool operator==(
const Time &_time)
const;
195 public:
bool operator==(
double _time)
const;
200 public:
bool operator!=(
const Time &_time)
const;
205 public:
bool operator!=(
double _time)
const;
210 public:
bool operator<(
const Time &_time)
const;
215 public:
bool operator<(
double _time)
const;
220 public:
bool operator<=(
const Time &_time)
const;
225 public:
bool operator<=(
double _time)
const;
230 public:
bool operator>(
const struct timespec &_tv)
const;
235 public:
bool operator>(
const Time &_time)
const;
240 public:
bool operator>(
double _time)
const;
245 public:
bool operator>=(
const Time &_time)
const;
250 public:
bool operator>=(
const struct timespec &_tv)
const;
255 public:
bool operator>=(
double _time)
const;
264 _out << _time.
sec <<
" " << _time.
nsec;
276 _in.
setf(std::ios_base::skipws);
277 _in >> _time.
sec >> _time.
nsec;
288 private:
static Time wallTime;
292 private:
inline void Correct()
295 if (this->sec > 0 && this->nsec < 0)
297 int32_t n = abs(this->nsec / this->nsInSec) + 1;
299 this->nsec += n * this->nsInSec;
301 if (this->sec < 0 && this->nsec > 0)
303 int32_t n = abs(this->nsec / this->nsInSec) + 1;
305 this->nsec -= n * this->nsInSec;
309 this->sec += this->nsec / this->nsInSec;
310 this->nsec = this->nsec % this->nsInSec;
314 private:
static const int32_t nsInSec;
318 private:
static const int32_t nsInMs;
320 private:
static struct timespec clockResolution;
FormatOption
Definition: Time.hh:40
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:33
int32_t sec
Seconds.
Definition: Time.hh:282
static const Time Zero
A static zero time variable set to common::Time(0, 0).
Definition: Time.hh:36
int32_t nsec
Nanoseconds.
Definition: Time.hh:285
Forward declarations for the common classes.
friend std::ostream & operator<<(std::ostream &_out, const Time &_time)
Stream insertion operator.
Definition: Time.hh:261
friend std::istream & operator>>(std::istream &_in, Time &_time)
Stream extraction operator.
Definition: Time.hh:272