10 StopWatch::StopWatch() : StateMachine(
"stopwatch") {
15 add_transition(
"start/stop", off, on);
16 add_transition(
"reset", off, off);
17 add_transition(
"start/stop", on, off);
18 add_transition(
"lap", on, on);
25 if ( current().name() ==
"on" ) {
26 return high_resolution_clock::now() - _start_time + _elapsed;
33 _start_time = high_resolution_clock::now();
37 _elapsed = high_resolution_clock::duration::zero();
42 _elapsed += high_resolution_clock::now() - _start_time;
46 _laps.insert(_laps.begin(),
value());
void stop()
Stop the stopwatch.
void begin()
Start the stopwatch.
void lap()
Add a lap time to the list of lap times.
high_resolution_clock::duration value()
Get the time stored by the stopwatch.
void reset()
Reset the stopwatch to zero and erase laps.