Plaquette
 
Loading...
Searching...
No Matches
AbstractChronometer.h
1/*
2 * AbstractChronometer.h
3 *
4 * (c) 2025 Sofian Audry :: info(@)sofianaudry(.)com
5 * (c) 2018 Thomas O Fredericks :: tof(@)t-o-f(.)info
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PQ_ABSTRACT_CHRONOMETER_H_
22#define PQ_ABSTRACT_CHRONOMETER_H_
23
24#include "PqCore.h"
25#include "Timeable.h"
26
27namespace pq {
28
30public:
33 virtual ~AbstractChronometer() {}
34
36 virtual void pause();
37
39 virtual void resume();
40
42 virtual float elapsed() const { return _elapsedTime; }
43
45 virtual bool hasPassed(float timeout) const;
46
48 virtual void setTime(float time);
49
51 virtual void addTime(float time);
52
58 [[deprecated("Use hasPassed(float) followed by start() instead.")]]
59 virtual bool hasPassed(float timeout, bool restartIfPassed);
60
62 virtual bool isRunning() const { return _isRunning; }
63
65 [[deprecated("Use isRunning() instead.")]]
66 bool isStarted() const { return isRunning(); }
67
68protected:
69 // Updates elapsed time.
70 virtual void update();
71
72 // Returns current absolute time (in seconds).
73 virtual float _time() const = 0;
74
75 // Sets running state.
76 virtual void _setRunning(bool isRunning) { _isRunning = isRunning; }
77
78 // The starting time (in seconds).
79 float _startTime;
80
81 // The offset time
82 float _offsetTime;
83
84 // The current elapsed time.
85 float _elapsedTime;
86
87 // Is the chrono currently started.
88 bool _isRunning;
89};
90
91}
92
93#endif
Definition AbstractChronometer.h:29
virtual void addTime(float time)
Adds/subtracts time to the chronometer.
Definition AbstractChronometer.cpp:64
virtual bool hasPassed(float timeout) const
Returns true iff elapsed time has passed given timeout.
Definition AbstractChronometer.cpp:43
bool isStarted() const
Definition AbstractChronometer.h:66
virtual void pause()
Interrupts the chronometer.
Definition AbstractChronometer.cpp:29
virtual bool isRunning() const
Returns true iff the chronometer is currently running.
Definition AbstractChronometer.h:62
virtual void setTime(float time)
Forces current time (in seconds).
Definition AbstractChronometer.cpp:59
virtual void resume()
Resumes process.
Definition AbstractChronometer.cpp:36
AbstractChronometer()
Constructor.
Definition AbstractChronometer.cpp:25
virtual float elapsed() const
The time currently elapsed by the chronometer (in seconds).
Definition AbstractChronometer.h:42
Abstract class for time-based objects.
Definition Timeable.h:27