rippled
Loading...
Searching...
No Matches
manual_clock.h
1#ifndef BEAST_CHRONO_MANUAL_CLOCK_H_INCLUDED
2#define BEAST_CHRONO_MANUAL_CLOCK_H_INCLUDED
3
4#include <xrpl/beast/clock/abstract_clock.h>
5#include <xrpl/beast/utility/instrumentation.h>
6
7#include <chrono>
8
9namespace beast {
10
20template <class Clock>
21class manual_clock : public abstract_clock<Clock>
22{
23public:
24 using typename abstract_clock<Clock>::rep;
27
28private:
30
31public:
33 : now_(now)
34 {
35 }
36
38 now() const override
39 {
40 return now_;
41 }
42
44 void
45 set(time_point const& when)
46 {
47 XRPL_ASSERT(
48 !Clock::is_steady || when >= now_,
49 "beast::manual_clock::set(time_point) : forward input");
50 now_ = when;
51 }
52
54 template <class Integer>
55 void
56 set(Integer seconds_from_epoch)
57 {
58 set(time_point(duration(std::chrono::seconds(seconds_from_epoch))));
59 }
60
62 template <class Rep, class Period>
63 void
65 {
66 XRPL_ASSERT(
67 !Clock::is_steady || (now_ + elapsed) >= now_,
68 "beast::manual_clock::advance(duration) : forward input");
69 now_ += elapsed;
70 }
71
75 {
77 return *this;
78 }
79};
80
81} // namespace beast
82
83#endif
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)))