Go to the documentation of this file.
25 #ifndef SRC_CORE_INCLUDE_CORBO_CORE_TIME_H_
26 #define SRC_CORE_INCLUDE_CORBO_CORE_TIME_H_
38 #undef min // this macro conflicts with std::min
39 #undef max // this macro conflicts with std::max
49 struct is_chrono_duration
51 static constexpr
bool value =
false;
54 template <
typename Rep,
typename Period>
55 struct is_chrono_duration<
std::chrono::duration<Rep, Period>>
57 static constexpr
bool value =
true;
61 struct is_chrono_timepoint
63 static constexpr
bool value =
false;
66 template <
typename Clock>
67 struct is_chrono_timepoint<
std::chrono::time_point<Clock>>
69 static constexpr
bool value =
true;
131 template <
typename ChronoDuration>
132 explicit Duration(
const ChronoDuration& duration)
138 double toSec()
const {
return std::chrono::duration_cast<std::chrono::duration<double>>(
_duration).count(); }
140 void fromSec(
double t) {
_duration = std::chrono::duration_cast<DurationType>(std::chrono::duration<double>(t)); }
143 template <
typename ChronoDuration>
144 void fromChrono(
const ChronoDuration& duration)
147 "Template parameter ChronoDuration must be of type std::chrono::duration");
148 _duration = std::chrono::duration_cast<DurationType>(duration);
163 template <
typename DurType = std::chrono::duration<
double>>
188 return *
static_cast<Duration*
>(
this);
193 return *
static_cast<Duration*
>(
this);
198 return *
static_cast<Duration*
>(
this);
258 explicit Time(
int t) {
fromSec(
static_cast<double>(t)); }
268 template <
typename ChronoTimePo
int>
269 explicit Time(
const ChronoTimePoint& timepoint)
281 double toSec()
const {
return std::chrono::duration_cast<std::chrono::duration<double>>(
_timepoint.time_since_epoch()).count(); }
283 void fromSec(
double t) {
_timepoint =
TimePoint(std::chrono::duration_cast<TimePoint::duration>(std::chrono::duration<double>(t))); }
286 template <
typename ChronoTimePo
int>
287 void fromChrono(
const ChronoTimePoint& timepoint)
290 "Template parameter ChronoTimePoint must be of type std::chrono::time_point");
291 _timepoint = std::chrono::time_point_cast<Clock::duration>(timepoint);
301 return *
static_cast<Time*
>(
this);
306 return *
static_cast<Time*
>(
this);
315 friend std::ostream&
operator<<(std::ostream& os,
const Time& rhs)
324 using Clock = std::chrono::high_resolution_clock;
378 #endif // SRC_CORE_INCLUDE_CORBO_CORE_TIME_H_
bool operator==(const Time &rhs) const
static Time now()
Retrieve current system time.
bool operator<(const Duration &rhs) const
void fromSec(double t)
Set duration from seconds (see Duration(double t))
Duration lastCycleTime() const
Return actual execution time of the last cycle.
Duration & operator*=(double scale)
Duration & operator+=(const Duration &rhs)
bool operator>(const Time &rhs) const
Rate(double frequency)
Construct rate object from frequency [1/s].
void updateCycleTime(const Duration &dt)
Update cycle time without resetting start time.
Time operator+(const Duration &rhs) const
std::chrono::nanoseconds DurationType
bool operator>=(const Time &rhs) const
bool operator<=(const Time &rhs) const
Duration operator*(double scale) const
bool operator<=(const Duration &rhs) const
void fromSec(double t)
Set time stamp from seconds.
bool operator>(const Duration &rhs) const
Duration & operator-=(const Duration &rhs)
friend std::ostream & operator<<(std::ostream &os, const Time &rhs)
bool operator!=(const Duration &rhs) const
Duration operator-() const
bool sleep()
Sleep for the remaining duration to met the desired frequency (w.r.t previous sleep call)
bool operator<(const Time &rhs) const
static constexpr bool value
double toSec() const
Cast time stamp to seconds.
Time & operator-=(const Duration &rhs)
Representation of time durations.
static constexpr bool value
void sleep()
Sleep (current thread) for the specified duration.
bool operator>=(const Duration &rhs) const
Clock::time_point TimePoint
Datatype for the timepoint.
Duration()
Default constructor.
Time()
Default constructor.
void fromChrono(const ChronoTimePoint &timepoint)
Set time stamp from std::chrono::time_stamp type.
DurType toChrono()
Convert duration to std::chrono::duration object.
void fromChrono(const ChronoDuration &duration)
Set duration from std::chrono::duration object (see Duration(const ChronoDuration& duration))
Time toTime(double basis_time=0)
std::chrono::high_resolution_clock Clock
Datatype for the clock.
Time & operator+=(const Duration &rhs)
Duration operator-(const Time &rhs) const
bool operator!=(const Time &rhs) const
double toSec() const
Return duration in seconds.
Duration _last_cycle_time
Representation of time stamps.
bool operator==(const Duration &rhs) const
friend std::ostream & operator<<(std::ostream &os, const Duration &rhs)
Duration operator+(const Duration &rhs) const
static void sleepUntil(const Time &time)
Sleep (current thread) until the specified timestamp.
Rate objects can be used to run loops at a desired rate.
control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:07:06