rippled
Loading...
Searching...
No Matches
manual_clock.h
1#pragma once
2
3#include <xrpl/beast/clock/abstract_clock.h>
4#include <xrpl/beast/utility/instrumentation.h>
5
6#include <chrono>
7
8namespace beast {
9
19template <class Clock>
20class manual_clock : public abstract_clock<Clock>
21{
22public:
23 using typename abstract_clock<Clock>::rep;
26
27private:
29
30public:
32 {
33 }
34
36 now() const override
37 {
38 return now_;
39 }
40
42 void
43 set(time_point const& when)
44 {
45 XRPL_ASSERT(
46 !Clock::is_steady || when >= now_,
47 "beast::manual_clock::set(time_point) : forward input");
48 now_ = when;
49 }
50
52 template <class Integer>
53 void
54 set(Integer seconds_from_epoch)
55 {
56 set(time_point(duration(std::chrono::seconds(seconds_from_epoch))));
57 }
58
60 template <class Rep, class Period>
61 void
63 {
64 XRPL_ASSERT(
65 !Clock::is_steady || (now_ + elapsed) >= now_,
66 "beast::manual_clock::advance(duration) : forward input");
67 now_ += elapsed;
68 }
69
73 {
75 return *this;
76 }
77};
78
79} // namespace beast
Abstract interface to a clock.
typename Clock::rep rep
typename Clock::time_point time_point
typename Clock::duration duration
Manual clock implementation.
manual_clock & operator++()
Convenience for advancing the clock by one second.
void set(Integer seconds_from_epoch)
Convenience for setting the time in seconds from epoch.
void advance(std::chrono::duration< Rep, Period > const &elapsed)
Advance the clock by a duration.
time_point now() const override
Returns the current time.
void set(time_point const &when)
Set the current time of the manual clock.
manual_clock(time_point const &now=time_point(duration(0)))