Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
PLMD::Stopwatch Class Reference

#include <Stopwatch.h>

Classes

class  Handler
 Auxiliary class for handling exception-safe start/pause and start/stop. More...
 
class  Watch
 Class to store a single stopwatch. More...
 

Public Member Functions

 Stopwatch ()=default
 
 Stopwatch (Log &log)
 
 ~Stopwatch ()
 
Stopwatchpause (const std::string &name=emptyString())
 Pause timer named "name". More...
 
Stopwatchstart (const std::string &name=emptyString())
 Start timer named "name". More...
 
Handler startPause (const std::string &name=emptyString())
 Start with exception safety, then pause. More...
 
Handler startStop (const std::string &name=emptyString())
 Start with exception safety, then stop. More...
 
Stopwatchstop (const std::string &name=emptyString())
 Stop timer named "name". More...
 

Private Member Functions

std::ostream & log (std::ostream &os) const
 Log over stream os. More...
 

Static Private Member Functions

static const std::string & emptyString ()
 Simple function returning an empty string. More...
 

Private Attributes

Logmylog =nullptr
 Pointer to a log file. More...
 
std::unordered_map< std::string, Watchwatches
 List of watches. More...
 

Friends

std::ostream & operator<< (std::ostream &, const Stopwatch &)
 Dump all timers on an ostream. More...
 

Constructor & Destructor Documentation

◆ Stopwatch() [1/2]

PLMD::Stopwatch::Stopwatch ( )
explicitdefault

◆ Stopwatch() [2/2]

PLMD::Stopwatch::Stopwatch ( Log log)
inlineexplicit

◆ ~Stopwatch()

PLMD::Stopwatch::~Stopwatch ( )

Member Function Documentation

◆ emptyString()

static const std::string& PLMD::Stopwatch::emptyString ( )
inlinestaticprivate

Simple function returning an empty string.

Used to simplify Stopwatch interface.

◆ log()

std::ostream & PLMD::Stopwatch::log ( std::ostream &  os) const
private

Log over stream os.

◆ pause()

Stopwatch & PLMD::Stopwatch::pause ( const std::string &  name = emptyString())
inline

Pause timer named "name".

◆ start()

Stopwatch & PLMD::Stopwatch::start ( const std::string &  name = emptyString())
inline

Start timer named "name".

◆ startPause()

Stopwatch::Handler PLMD::Stopwatch::startPause ( const std::string &  name = emptyString())
inline

Start with exception safety, then pause.

Starts the Stopwatch and returns an object that, when goes out of scope, pauses the watch. This allows Stopwatch to be started and paused in an exception safe manner.

◆ startStop()

Stopwatch::Handler PLMD::Stopwatch::startStop ( const std::string &  name = emptyString())
inline

Start with exception safety, then stop.

Starts the Stopwatch and returns an object that, when goes out of scope, stops the watch. This allows Stopwatch to be started and stopped in an exception safe manner.

◆ stop()

Stopwatch & PLMD::Stopwatch::stop ( const std::string &  name = emptyString())
inline

Stop timer named "name".

Friends And Related Function Documentation

◆ operator<<

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

Dump all timers on an ostream.

Member Data Documentation

◆ mylog

Log* PLMD::Stopwatch::mylog =nullptr
private

Pointer to a log file.

If set, the stopwatch is logged in its destructor.

◆ watches

std::unordered_map<std::string,Watch> PLMD::Stopwatch::watches
private

List of watches.

Each watch is labeled with a string.


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