The Battle for Wesnoth  1.19.0-dev
Public Types | Public Member Functions | Private Attributes | List of all members
util::optimer< ResolutionType, ClockType > Struct Template Reference

Reports time elapsed at the end of an object scope. More...

#include <optimer.hpp>

Public Types

using clock = ClockType
 
using resolution = ResolutionType
 
using point = typename clock::time_point
 
using interval = typename clock::duration
 
using report_callback = std::function< void(const optimer &)>
 

Public Member Functions

 optimer (report_callback f=report_callback{})
 Constructor, which starts the timer. More...
 
 ~optimer ()
 Destructor, which invokes the report callback. More...
 
void reset ()
 Resets the timer back to zero. More...
 
point start () const
 Returns the start time point. More...
 
interval elapsed () const
 Returns the elapsed time value. More...
 

Private Attributes

point start_
 
report_callback repf_
 

Detailed Description

template<typename ResolutionType, typename ClockType = std::chrono::steady_clock>
struct util::optimer< ResolutionType, ClockType >

Reports time elapsed at the end of an object scope.

The constructor accepts a callable that takes the optimer as its only argument, which can then be used to write the elapsed time to a stream, variable, or anything else that's desirable for a particular use case.

Template Parameters
ResolutionTypeClock resolution – milliseconds, microseconds, etc.
ClockTypeClock type – a monotonic clock by default.

Definition at line 35 of file optimer.hpp.

Member Typedef Documentation

◆ clock

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
using util::optimer< ResolutionType, ClockType >::clock = ClockType

Definition at line 37 of file optimer.hpp.

◆ interval

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
using util::optimer< ResolutionType, ClockType >::interval = typename clock::duration

Definition at line 40 of file optimer.hpp.

◆ point

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
using util::optimer< ResolutionType, ClockType >::point = typename clock::time_point

Definition at line 39 of file optimer.hpp.

◆ report_callback

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
using util::optimer< ResolutionType, ClockType >::report_callback = std::function<void(const optimer&)>

Definition at line 41 of file optimer.hpp.

◆ resolution

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
using util::optimer< ResolutionType, ClockType >::resolution = ResolutionType

Definition at line 38 of file optimer.hpp.

Constructor & Destructor Documentation

◆ optimer()

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
util::optimer< ResolutionType, ClockType >::optimer ( report_callback  f = report_callback{})
inlineexplicit

Constructor, which starts the timer.

The report callback may be an empty object, in which case the destructor will not do anything. This may be useful in order to obtain and keep track of elapsed time manually for other purposes than console printing.

Definition at line 50 of file optimer.hpp.

◆ ~optimer()

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
util::optimer< ResolutionType, ClockType >::~optimer ( )
inline

Destructor, which invokes the report callback.

Definition at line 60 of file optimer.hpp.

References util::optimer< ResolutionType, ClockType >::repf_.

Member Function Documentation

◆ elapsed()

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
interval util::optimer< ResolutionType, ClockType >::elapsed ( ) const
inline

Returns the elapsed time value.

Definition at line 80 of file optimer.hpp.

References util::optimer< ResolutionType, ClockType >::start_.

◆ reset()

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
void util::optimer< ResolutionType, ClockType >::reset ( )
inline

Resets the timer back to zero.

Definition at line 68 of file optimer.hpp.

References util::optimer< ResolutionType, ClockType >::start_.

◆ start()

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
point util::optimer< ResolutionType, ClockType >::start ( ) const
inline

Returns the start time point.

Definition at line 74 of file optimer.hpp.

References util::optimer< ResolutionType, ClockType >::start_.

Member Data Documentation

◆ repf_

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
report_callback util::optimer< ResolutionType, ClockType >::repf_
private

Definition at line 87 of file optimer.hpp.

Referenced by util::optimer< ResolutionType, ClockType >::~optimer().

◆ start_

template<typename ResolutionType , typename ClockType = std::chrono::steady_clock>
point util::optimer< ResolutionType, ClockType >::start_
private

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