xrpld
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
20template <class Clock>
21class ManualClock : public AbstractClock<Clock>
22{
23public:
24 using typename AbstractClock<Clock>::rep;
25 using typename AbstractClock<Clock>::duration;
27
28private:
30
31public:
33 {
34 }
35
36 [[nodiscard]] time_point
37 now() const override
38 {
39 return now_;
40 }
41
45 void
46 set(time_point const& when)
47 {
48 XRPL_ASSERT(
49 !Clock::is_steady || when >= now_,
50 "beast::ManualClock::set(time_point) : forward input");
51 now_ = when;
52 }
53
57 template <class Integer>
58 void
59 set(Integer secondsFromEpoch)
60 {
61 set(time_point(duration(std::chrono::seconds(secondsFromEpoch))));
62 }
63
67 template <class Rep, class Period>
68 void
70 {
71 XRPL_ASSERT(
72 !Clock::is_steady || (now_ + elapsed) >= now_,
73 "beast::ManualClock::advance(duration) : forward input");
74 now_ += elapsed;
75 }
76
82 {
84 return *this;
85 }
86};
87
88} // namespace beast
Clock::duration duration
Clock::time_point time_point
Manual clock implementation.
void set(Integer secondsFromEpoch)
Convenience for setting the time in seconds from epoch.
ManualClock(time_point const &now=time_point(duration(0)))
void set(time_point const &when)
Set the current time of the manual clock.
void advance(std::chrono::duration< Rep, Period > const &elapsed)
Advance the clock by a duration.
ManualClock & operator++()
Convenience for advancing the clock by one second.