# OpenGraph DrawingFramework

v. 2022.02 (Dogwood)

ogdf::Stopwatch Class Referenceabstract

Realizes a stopwatch for measuring elapsed time. More...

#include <ogdf/basic/Stopwatch.h>

Inheritance diagram for ogdf::Stopwatch:

## Public Member Functions

Stopwatch ()
Initializes a stop watch with total time 0. More...

Stopwatch (int64_t milliSecs)
Initializes a stopwatch and sets its total time to milliSecs. More...

virtual ~Stopwatch ()

Adds centiSeconds to total time. More...

int64_t centiSeconds () const
Returns the currently elapsed time in 1/100-seconds. More...

bool exceeds (int64_t maxSeconds) const
Returns true iff the currently elapsed time exceeds maxSeconds. More...

int64_t hours () const
Returns the currently elapsed time in hours. More...

int64_t milliSeconds () const
Returns the currently elapsed time in milliseconds. More...

int64_t minutes () const
Returns the currently elapsed time in minutes. More...

void reset ()
Stops the stopwatch and sets its total time to 0. More...

bool running () const
Returns true if the stopwatch is running, false otherwise. More...

int64_t seconds () const
Returns the currently elapsed time in seconds. More...

void start (bool reset=false)
Starts the stopwatch. More...

void stop ()
Stops the stopwatch and adds the difference between the current time and the starting time to the total time. More...

## Protected Member Functions

virtual int64_t theTime () const =0
Returns the current time in milliseconds (from some fixed starting point). More...

## Private Attributes

bool m_running
true, if the timer is running. More...

int64_t m_startTime
The start time of the timer in milliseconds. More...

int64_t m_totalTime
The total time in milliseconds. More...

## Friends

std::ostream & operator<< (std::ostream &os, const Stopwatch &stopwatch)
Writes the currently elapsed time in the format hh:mm:ss.sec/100 to output stream os. More...

## Detailed Description

Realizes a stopwatch for measuring elapsed time.

Definition at line 43 of file Stopwatch.h.

## ◆ Stopwatch() [1/2]

 ogdf::Stopwatch::Stopwatch ( )
inline

Initializes a stop watch with total time 0.

After creation the stopwatch is not running, i.e., it has to be started explicitly for measuring time.

Definition at line 55 of file Stopwatch.h.

## ◆ Stopwatch() [2/2]

 ogdf::Stopwatch::Stopwatch ( int64_t milliSecs )
inlineexplicit

Initializes a stopwatch and sets its total time to milliSecs.

After creation the stopwatch is not running, i.e., it has to be started explicitly for measuring time.

Parameters
 milliSecs The intial value of the total time in milliseconds.

Definition at line 64 of file Stopwatch.h.

## ◆ ~Stopwatch()

 virtual ogdf::Stopwatch::~Stopwatch ( )
inlinevirtual

Definition at line 67 of file Stopwatch.h.

## Member Function Documentation

 void ogdf::Stopwatch::addCentiSeconds ( int64_t centiSeconds )
inline

Adds centiSeconds to total time.

Parameters
 centiSeconds The number of centiseconds to be added.

Definition at line 140 of file Stopwatch.h.

## ◆ centiSeconds()

 int64_t ogdf::Stopwatch::centiSeconds ( ) const
inline

Returns the currently elapsed time in 1/100-seconds.

It is not necessary to stop the timer to get the correct time.

Definition at line 107 of file Stopwatch.h.

## ◆ exceeds()

 bool ogdf::Stopwatch::exceeds ( int64_t maxSeconds ) const
inline

Returns true iff the currently elapsed time exceeds maxSeconds.

Definition at line 132 of file Stopwatch.h.

## ◆ hours()

 int64_t ogdf::Stopwatch::hours ( ) const
inline

Returns the currently elapsed time in hours.

It is not necessary to stop the timer to get the correct time. The result is rounded down to the next integer value.

Definition at line 128 of file Stopwatch.h.

## ◆ milliSeconds()

 int64_t ogdf::Stopwatch::milliSeconds ( ) const
inline

Returns the currently elapsed time in milliseconds.

It is not necessary to stop the timer to get the correct time.

Definition at line 99 of file Stopwatch.h.

## ◆ minutes()

 int64_t ogdf::Stopwatch::minutes ( ) const
inline

Returns the currently elapsed time in minutes.

It is not necessary to stop the timer to get the correct time. The result is rounded down to the next integer value.

Definition at line 121 of file Stopwatch.h.

## ◆ reset()

 void ogdf::Stopwatch::reset ( )
inline

Stops the stopwatch and sets its total time to 0.

Definition at line 85 of file Stopwatch.h.

## ◆ running()

 bool ogdf::Stopwatch::running ( ) const
inline

Returns true if the stopwatch is running, false otherwise.

Definition at line 92 of file Stopwatch.h.

## ◆ seconds()

 int64_t ogdf::Stopwatch::seconds ( ) const
inline

Returns the currently elapsed time in seconds.

It is not necessary to stop the timer to get the correct time. The result is rounded down to the next integer value.

Definition at line 114 of file Stopwatch.h.

## ◆ start()

 void ogdf::Stopwatch::start ( bool reset = false )

Starts the stopwatch.

For safety reasons starting a running timer is an error.

Parameters
 reset If this flag is set to true, the stopwatch is reset before it is started.

## ◆ stop()

 void ogdf::Stopwatch::stop ( )

Stops the stopwatch and adds the difference between the current time and the starting time to the total time.

Stopping a non-running stopwatch is an error.

## ◆ theTime()

 virtual int64_t ogdf::Stopwatch::theTime ( ) const
protectedpure virtual

Returns the current time in milliseconds (from some fixed starting point).

This pure virtual function is used for measuring time differences. It must be implemented in derived classes.

Returns
The time since some starting point (e.g., the program start) in milliseconds.

Implemented in ogdf::StopwatchWallClock, and ogdf::StopwatchCPU.

## ◆ operator<<

 std::ostream& operator<< ( std::ostream & os, const Stopwatch & stopwatch )
friend

Writes the currently elapsed time in the format hh:mm:ss.sec/100 to output stream os.

Parameters
 os The output stream. stopwatch The stopwatch whose elapsed time shall be written.
Returns
A reference to the output stream os.

## ◆ m_running

 bool ogdf::Stopwatch::m_running
private

true, if the timer is running.

Definition at line 47 of file Stopwatch.h.

## ◆ m_startTime

 int64_t ogdf::Stopwatch::m_startTime
private

The start time of the timer in milliseconds.

Definition at line 45 of file Stopwatch.h.

## ◆ m_totalTime

 int64_t ogdf::Stopwatch::m_totalTime
private

The total time in milliseconds.

Definition at line 46 of file Stopwatch.h.

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