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(!Clock::is_steady || when >= now_, "beast::manual_clock::set(time_point) : forward input");
46 now_ = when;
47 }
48
50 template <class Integer>
51 void
52 set(Integer seconds_from_epoch)
53 {
54 set(time_point(duration(std::chrono::seconds(seconds_from_epoch))));
55 }
56
58 template <class Rep, class Period>
59 void
61 {
62 XRPL_ASSERT(
63 !Clock::is_steady || (now_ + elapsed) >= now_, "beast::manual_clock::advance(duration) : forward input");
64 now_ += elapsed;
65 }
66
70 {
72 return *this;
73 }
74};
75
76} // 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)))