algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::runner::ManualClock Class Reference

A clock for tests: wait_for advances it instead of sleeping. More...

#include <algotradelib/src/runner/clock.hpp>

Public Member Functions

 ManualClock (std::chrono::system_clock::time_point start={})
 Constructs a clock.
std::chrono::system_clock::time_point now () const noexcept
 Returns the current time.
std::chrono::steady_clock::time_point monotonic_now () const noexcept
 Returns the monotonic reading: how far wait_for and advance have moved the clock.
void wait_for (std::chrono::nanoseconds duration) noexcept
 Advances the clock by a duration instead of waiting, and counts the wait.
void advance (std::chrono::nanoseconds duration) noexcept
 Advances the clock without counting a wait: time that passed, as inside a slow call.
void jump (std::chrono::nanoseconds duration) noexcept
 Moves the wall-clock reading alone, forward or back, as an operator or NTP setting the clock does.
std::size_t waits () const noexcept
 Returns how many times wait_for was called.
std::chrono::nanoseconds waited () const noexcept
 Returns the total positive duration passed to wait_for.

Detailed Description

A clock for tests: wait_for advances it instead of sleeping.

A loop under test runs instantly while seeing whatever elapsed time the test chooses. waits() counts the waits, so a test can tell a loop that paced itself from one that spun.

Definition at line 96 of file clock.hpp.

Constructor & Destructor Documentation

◆ ManualClock()

algotradelib::runner::ManualClock::ManualClock ( std::chrono::system_clock::time_point start = {})
inlineexplicit

Constructs a clock.

Parameters
startThe time it reads.

Definition at line 102 of file clock.hpp.

Member Function Documentation

◆ advance()

void algotradelib::runner::ManualClock::advance ( std::chrono::nanoseconds duration)
inlinenoexcept

Advances the clock without counting a wait: time that passed, as inside a slow call.

Parameters
durationThe duration; zero or negative does nothing to the monotonic reading.

Definition at line 133 of file clock.hpp.

◆ jump()

void algotradelib::runner::ManualClock::jump ( std::chrono::nanoseconds duration)
inlinenoexcept

Moves the wall-clock reading alone, forward or back, as an operator or NTP setting the clock does.

Parameters
durationThe jump.

Definition at line 144 of file clock.hpp.

◆ monotonic_now()

std::chrono::steady_clock::time_point algotradelib::runner::ManualClock::monotonic_now ( ) const
inlinenoexcept

Returns the monotonic reading: how far wait_for and advance have moved the clock.

Returns
The reading; jump does not move it.

Definition at line 114 of file clock.hpp.

◆ now()

std::chrono::system_clock::time_point algotradelib::runner::ManualClock::now ( ) const
inlinenoexcept

Returns the current time.

Returns
The time the clock has been advanced to.

Definition at line 108 of file clock.hpp.

◆ wait_for()

void algotradelib::runner::ManualClock::wait_for ( std::chrono::nanoseconds duration)
inlinenoexcept

Advances the clock by a duration instead of waiting, and counts the wait.

Parameters
durationThe duration; zero or negative counts the wait without advancing.

Definition at line 120 of file clock.hpp.

◆ waited()

std::chrono::nanoseconds algotradelib::runner::ManualClock::waited ( ) const
inlinenoexcept

Returns the total positive duration passed to wait_for.

Returns
The sum.

Definition at line 158 of file clock.hpp.

◆ waits()

std::size_t algotradelib::runner::ManualClock::waits ( ) const
inlinenoexcept

Returns how many times wait_for was called.

Returns
The count.

Definition at line 152 of file clock.hpp.


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