1*8069771cSKrzysztof Grobelny #pragma once 2*8069771cSKrzysztof Grobelny 3*8069771cSKrzysztof Grobelny #include "interfaces/clock.hpp" 4*8069771cSKrzysztof Grobelny #include "types/duration_type.hpp" 5*8069771cSKrzysztof Grobelny 6*8069771cSKrzysztof Grobelny class ClockFake : public interfaces::Clock 7*8069771cSKrzysztof Grobelny { 8*8069771cSKrzysztof Grobelny public: 9*8069771cSKrzysztof Grobelny time_point now() const noexcept override 10*8069771cSKrzysztof Grobelny { 11*8069771cSKrzysztof Grobelny return timePoint; 12*8069771cSKrzysztof Grobelny } 13*8069771cSKrzysztof Grobelny 14*8069771cSKrzysztof Grobelny uint64_t timestamp() const noexcept override 15*8069771cSKrzysztof Grobelny { 16*8069771cSKrzysztof Grobelny return toTimestamp(now()); 17*8069771cSKrzysztof Grobelny } 18*8069771cSKrzysztof Grobelny 19*8069771cSKrzysztof Grobelny uint64_t advance(Milliseconds delta) noexcept 20*8069771cSKrzysztof Grobelny { 21*8069771cSKrzysztof Grobelny timePoint += delta; 22*8069771cSKrzysztof Grobelny return timestamp(); 23*8069771cSKrzysztof Grobelny } 24*8069771cSKrzysztof Grobelny 25*8069771cSKrzysztof Grobelny void set(Milliseconds timeSinceEpoch) noexcept 26*8069771cSKrzysztof Grobelny { 27*8069771cSKrzysztof Grobelny timePoint = time_point{timeSinceEpoch}; 28*8069771cSKrzysztof Grobelny } 29*8069771cSKrzysztof Grobelny 30*8069771cSKrzysztof Grobelny static uint64_t toTimestamp(Milliseconds time) 31*8069771cSKrzysztof Grobelny { 32*8069771cSKrzysztof Grobelny return time.count(); 33*8069771cSKrzysztof Grobelny } 34*8069771cSKrzysztof Grobelny 35*8069771cSKrzysztof Grobelny static uint64_t toTimestamp(time_point tp) 36*8069771cSKrzysztof Grobelny { 37*8069771cSKrzysztof Grobelny return std::chrono::time_point_cast<Milliseconds>(tp) 38*8069771cSKrzysztof Grobelny .time_since_epoch() 39*8069771cSKrzysztof Grobelny .count(); 40*8069771cSKrzysztof Grobelny } 41*8069771cSKrzysztof Grobelny 42*8069771cSKrzysztof Grobelny private: 43*8069771cSKrzysztof Grobelny time_point timePoint = std::chrono::steady_clock::now(); 44*8069771cSKrzysztof Grobelny }; 45