Class timer

Synopsis

#include "breeze/time/timer.hpp"

template< class Device >
class timer

Description

A policy-based timer class (class template).

A policy-based timer which allows the user to retrieve the amount of time elapsed from its start (i.e. a "stopwatch").

Device is a policy modeling the "clock device" concept: this can be a hardware device, a network time provider, a GPS system or pretty much anything else. It must be DefaultConstructible and provide the member functions:

  • start(), which must start or restart the Device
  • elapsed(), which must return the amount of time elapsed from the last call to start()
  • resolution(), which must return the resolution of the Device or an estimate of it; note that the resolution is the smallest amount of time that the Device can measure and doesn't, in itself, tell anything about the accuracy

and the typedef:

  • duration_type, which is the return type of elapsed() and resolution(); it must be a std::chrono::duration

Methods

timer overloadDeleted copy constructor.
timer overloadInitializes the underlying device by calling the default constructor and, if (and only if) mode == auto_start , calls start().
elapsedReturns: The result of calling elapsed() on the underlying Device.
operator=Deleted copy assignment operator.
resolutionReturns: The result of calling Device::resolution().
startCalls Device::start().

Source

Lines 52-103 in breeze/time/timer.hpp.

template< class Device >
class timer
{
public:
    //!     Deleted copy constructor.
    //!
    //!     \par Rationale
    //!
    //!     Specifying copy semantics for a timer is a bit difficult
    //!     and, although it can probably be done, it's not worth it, as
    //!     who would copy a timer or a timer policy, anyway? (A timer
    //!     will, in practice, always be used like a Python context.)
    // -----------------------------------------------------------------------
                        timer(      timer const & ) = delete ;

    //!     Deleted copy assignment operator.
    //!
    //!     See the documentation of the (deleted) copy constructor for
    //!     the rationale.
    // -----------------------------------------------------------------------

    timer &             operator =( timer const & ) = delete ;

    typedef typename Device::duration_type
                        duration_type ;

    enum start_mode { auto_start, manual_start } ;

    //!     Initializes the underlying device by calling the default
    //!     constructor and, if (and only if) <code>mode == auto_start
    //!     </code>, calls start().
    // -----------------------------------------------------------------------
    explicit            timer( start_mode mode = auto_start ) ;

    //!     Calls \c Device::start().
    // -----------------------------------------------------------------------
    void                start() ;

    //!     \return
    //!         The result of calling %elapsed() on the underlying \c
    //!         Device.
    // -----------------------------------------------------------------------
    duration_type       elapsed() const ;

    //!     \return
    //!         The result of calling \c Device::resolution().
    // -----------------------------------------------------------------------
    duration_type       resolution() const ;

private:
    Device              m_device ;
} ;