Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
IntervalTimer.h
Go to the documentation of this file.
1#pragma once
2
3#include <misc/gen/TimeSpec.h>
4#include <misc/global.h>
5
6namespace sf
7{
14{
15 public:
21 IntervalTimer() = default;
22
26 explicit inline IntervalTimer(const timespec& t);
27
31 explicit IntervalTimer(int usec);
32
36 explicit IntervalTimer(double sec);
37
43 void set(const timespec& t);
44
50 [[nodiscard]] bool active() const;
51
58 [[nodiscard]] bool active(const timespec& t) const;
59
63 inline void enable();
64
68 inline void disable();
69
75 [[nodiscard]] inline bool isEnabled() const;
76
82 [[nodiscard]] inline const TimeSpec& getInterval() const;
88 [[nodiscard]] inline const TimeSpec& getTarget() const;
89
95 [[nodiscard]] TimeSpec getTimeLeft() const;
96
103 [[nodiscard]] TimeSpec getTimeLeft(const timespec& t) const;
104
110 [[nodiscard]] TimeSpec getTimeOver() const;
111
118 [[nodiscard]] TimeSpec getTimeOver(const timespec& t) const;
119
125 explicit inline operator bool() const;
126
133 inline bool operator()(const timespec& t) const;
134
135 private:
139 TimeSpec _interval{0, 0};
143 TimeSpec _target{0, 0};
147 bool _enabled{false};
148};
149
150inline IntervalTimer::IntervalTimer(const timespec& t)
151{
152 set(t);
153}
154
156{
157 _enabled = true;
158}
159
161{
162 _enabled = false;
163}
164
165inline bool IntervalTimer::isEnabled() const
166{
167 return _enabled;
168}
169
171{
172 return _interval;
173}
174
176{
177 return _target;
178}
179
180inline IntervalTimer::operator bool() const
181{
182 return active();
183}
184
185inline bool IntervalTimer::operator()(const timespec& t) const
186{
187 return active(t);
188}
189
190}// namespace sf
Timer class that has fixed time intervals at which it becomes true.
Definition IntervalTimer.h:14
bool active(const timespec &t) const
Allows passing timespec value our self to reduce overhead in case of multiple timers.
TimeSpec getTimeOver(const timespec &t) const
Same as time left, but it also gives the time passed the target time and before that as a negative va...
IntervalTimer()=default
Default constructor.
const TimeSpec & getTarget() const
Gets the set interval time in TimeSpec format.
Definition IntervalTimer.h:175
IntervalTimer(int usec)
Initializing constructor setting the elapse time in usec.
IntervalTimer(double sec)
Initializing constructor setting the elapse time in seconds and fraction using a double.
void enable()
Enables the timer with the current interval time.
Definition IntervalTimer.h:155
bool active() const
Tests if the timer is active if it is active it returns non-zero and resets the timer to a new event.
bool isEnabled() const
Gets timer enabled.
Definition IntervalTimer.h:165
TimeSpec getTimeOver() const
Same as time left, but it also gives the time passed the target time and before that as a negative va...
const TimeSpec & getInterval() const
Gets the set interval time in TimeSpec format.
Definition IntervalTimer.h:170
TimeSpec getTimeLeft(const timespec &t) const
Gets the time left in TimeSpec format before function active becomes true.
void disable()
Disables the timer.
Definition IntervalTimer.h:160
void set(const timespec &t)
Sets the timers interval time.
bool operator()(const timespec &t) const
Definition IntervalTimer.h:185
TimeSpec getTimeLeft() const
Gets the time left in msec before function active becomes true.
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
Class wrapper for timespec structure to modify.
Definition TimeSpec.h:12