class Poco::Clock

Overview

A Clock stores a monotonic* clock value with (theoretical) microseconds resolution. More…

#include <Clock.h>

class Clock
{
public:
    // typedefs

    typedef Int64 ClockVal;
    typedef Int64 ClockDiff;

    // fields

    static const ClockVal CLOCKVAL_MIN;
    static const ClockVal CLOCKVAL_MAX;

    // construction

    Clock();
    Clock(ClockVal tv);
    Clock(const Clock& other);

    // methods

    Clock&
    operator=(const Clock& other);

    Clock&
    operator=(ClockVal tv);

    void
    swap(Clock& clock);

    void
    update();

    bool
    operator==(const Clock& ts) const;

    bool
    operator!=(const Clock& ts) const;

    bool
    operator>(const Clock& ts) const;

    bool
    operator>=(const Clock& ts) const;

    bool
    operator<(const Clock& ts) const;

    bool
    operator<=(const Clock& ts) const;

    Clock
    operator+(ClockDiff d) const;

    Clock
    operator-(ClockDiff d) const;

    ClockDiff
    operator-(const Clock& ts) const;

    Clock&
    operator+=(ClockDiff d);

    Clock&
    operator-=(ClockDiff d);

    ClockVal
    microseconds() const;

    ClockVal
    raw() const;

    ClockDiff
    elapsed() const;

    bool
    isElapsed(ClockDiff interval) const;

    static
    ClockDiff
    resolution();

    static
    ClockDiff
    accuracy();

    static
    bool
    monotonic();
};

Detailed Documentation

A Clock stores a monotonic* clock value with (theoretical) microseconds resolution.

Clocks can be compared with each other and simple arithmetics are supported.

[*] Note that Clock values are only monotonic if the operating system provides a monotonic clock. The monotonic() function can be used to check whether the system’s clock is monotonic.

Monotonic Clock is available on Windows, Linux, OS X and on POSIX platforms supporting clock_gettime() with CLOCK_MONOTONIC.

Clock values are relative to a system-dependent epoch time (usually the system’s startup time) and have no relation to the time of day.

Typedefs

typedef Int64 ClockVal

Monotonic clock value in microsecond resolution.

typedef Int64 ClockDiff

Difference between two ClockVal values in microseconds.

Fields

static const ClockVal CLOCKVAL_MIN

Minimum clock value.

static const ClockVal CLOCKVAL_MAX

Maximum clock value.

Construction

Clock()

Creates a Clock with the current system clock value.

Clock(ClockVal tv)

Creates a Clock from the given clock value.

Clock(const Clock& other)

Copy constructor.

Methods

void
swap(Clock& clock)

Swaps the Clock with another one.

void
update()

Updates the Clock with the current system clock.

ClockVal
microseconds() const

Returns the clock value expressed in microseconds since the system-specific epoch time (usually system startup).

ClockVal
raw() const

Returns the clock value expressed in microseconds since the system-specific epoch time (usually system startup).

Same as microseconds().

ClockDiff
elapsed() const

Returns the time elapsed since the time denoted by the Clock instance.

Equivalent to Clock() - *this.

bool
isElapsed(ClockDiff interval) const

Returns true iff the given interval has passed since the time denoted by the Clock instance.

static
ClockDiff
resolution()

Returns the resolution in units per second.

Since the Clock clas has microsecond resolution, the returned value is always 1000000.

static
ClockDiff
accuracy()

Returns the system’s clock accuracy in microseconds.

static
bool
monotonic()

Returns true iff the system’s clock is monotonic.