Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_chronometer.hpp
1#pragma once
2
3#include "structure/system/time/spk_duration.hpp"
4#include "structure/system/time/spk_timestamp.hpp"
5
6#include <iostream>
7
8namespace spk
9{
23 {
24 public:
28 enum class State
29 {
30 Idle,
31 Running,
32 Paused
33 };
34
35 private:
36 State _state;
37 Timestamp _startTime;
38 Duration _accumulatedTime;
39
40 public:
45
49 void start();
53 void stop();
57 void pause();
61 void resume();
65 void restart();
66
71 Duration elapsedTime() const;
72
77 State state() const
78 {
79 return _state;
80 }
81
82 private:
83 Duration _currentRunDuration() const;
84 };
85
86 inline const char *toString(Chronometer::State p_state);
87 inline const wchar_t *toWstring(Chronometer::State p_state);
88}
89
90std::ostream &operator<<(std::ostream &p_os, spk::Chronometer::State p_state);
91std::wostream &operator<<(std::wostream &p_wos, spk::Chronometer::State p_state);
void stop()
Stops the chronometer and resets accumulated duration.
Definition spk_chronometer.cpp:23
void pause()
Pauses ongoing measurement without clearing accumulated time.
Definition spk_chronometer.cpp:30
Duration elapsedTime() const
Returns the total measured duration including paused segments.
Definition spk_chronometer.cpp:55
void restart()
Convenience to stop and immediately start a new measurement.
Definition spk_chronometer.cpp:48
State
States representing the current stopwatch lifecycle.
Definition spk_chronometer.hpp:29
Chronometer()
Builds a chronometer in the idle state with zeroed counters.
Definition spk_chronometer.cpp:7
State state() const
Retrieves the current state of the chronometer.
Definition spk_chronometer.hpp:77
void resume()
Resumes measurement after a pause.
Definition spk_chronometer.cpp:39
void start()
Starts measuring time if idle or resets accumulation after stop.
Definition spk_chronometer.cpp:14
Strongly-typed time span with cached conversions between ns/ms/s.
Definition spk_duration.hpp:15
Point in time with conversion helpers and arithmetic with Duration.
Definition spk_timestamp.hpp:16