libcosmos
Linux C++ System Programming Library
Loading...
Searching...
No Matches
cosmos::StopWatch< CLOCK > Class Template Reference

A type to measure elapsed time based on a given clock type. More...

#include <StopWatch.hxx>

Public Types

using InitialMark = NamedBool<struct mark_t, false>
 

Public Member Functions

 StopWatch (const InitialMark do_mark=InitialMark{})
 Construct and optionally set an initial mark().
 
void mark ()
 Set a new stop mark to compare against.
 
size_t elapsedMs () const
 Returns the elapsed milliseconds since the active mark.
 
std::chrono::milliseconds elapsed () const
 
TimeSpec< CLOCK > currentMark () const
 Returns the currently set mark (undefined if mark() was never called!).
 

Protected Attributes

TimeSpec< CLOCK > m_mark
 
Clock< CLOCK > m_clock
 

Detailed Description

template<ClockType CLOCK>
class cosmos::StopWatch< CLOCK >

A type to measure elapsed time based on a given clock type.

Definition at line 10 of file StopWatch.hxx.

Member Typedef Documentation

◆ InitialMark

template<ClockType CLOCK>
using cosmos::StopWatch< CLOCK >::InitialMark = NamedBool<struct mark_t, false>

Definition at line 13 of file StopWatch.hxx.

Constructor & Destructor Documentation

◆ StopWatch()

template<ClockType CLOCK>
cosmos::StopWatch< CLOCK >::StopWatch ( const InitialMark do_mark = InitialMark{})
inlineexplicit

Construct and optionally set an initial mark().

Definition at line 18 of file StopWatch.hxx.

18 {}) {
19 if (do_mark)
20 mark();
21 }
void mark()
Set a new stop mark to compare against.
Definition StopWatch.hxx:24

Member Function Documentation

◆ currentMark()

template<ClockType CLOCK>
TimeSpec< CLOCK > cosmos::StopWatch< CLOCK >::currentMark ( ) const
inline

Returns the currently set mark (undefined if mark() was never called!).

Definition at line 38 of file StopWatch.hxx.

38 {
39 return m_mark;
40 }

◆ elapsed()

template<ClockType CLOCK>
std::chrono::milliseconds cosmos::StopWatch< CLOCK >::elapsed ( ) const
inline

Definition at line 33 of file StopWatch.hxx.

33 {
34 return static_cast<std::chrono::milliseconds>(m_clock.now() - m_mark);
35 }

◆ elapsedMs()

template<ClockType CLOCK>
size_t cosmos::StopWatch< CLOCK >::elapsedMs ( ) const
inline

Returns the elapsed milliseconds since the active mark.

Definition at line 29 of file StopWatch.hxx.

29 {
30 return (m_clock.now() - m_mark).toMilliseconds();
31 }

◆ mark()

template<ClockType CLOCK>
void cosmos::StopWatch< CLOCK >::mark ( )
inline

Set a new stop mark to compare against.

Definition at line 24 of file StopWatch.hxx.

24 {
25 m_clock.now(m_mark);
26 }

Member Data Documentation

◆ m_clock

template<ClockType CLOCK>
Clock<CLOCK> cosmos::StopWatch< CLOCK >::m_clock
protected

Definition at line 45 of file StopWatch.hxx.

◆ m_mark

template<ClockType CLOCK>
TimeSpec<CLOCK> cosmos::StopWatch< CLOCK >::m_mark
protected

Definition at line 44 of file StopWatch.hxx.


The documentation for this class was generated from the following file: