rippled
abstract_clock.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of Beast: https://github.com/vinniefalco/Beast
4  Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef BEAST_CHRONO_ABSTRACT_CLOCK_H_INCLUDED
21 #define BEAST_CHRONO_ABSTRACT_CLOCK_H_INCLUDED
22 
23 #include <chrono>
24 #include <string>
25 
26 namespace beast {
27 
56 template <class Clock>
58 {
59 public:
60  using rep = typename Clock::rep;
61  using period = typename Clock::period;
62  using duration = typename Clock::duration;
63  using time_point = typename Clock::time_point;
64  using clock_type = Clock;
65 
66  static bool const is_steady = Clock::is_steady;
67 
68  virtual ~abstract_clock() = default;
69  abstract_clock() = default;
70  abstract_clock(abstract_clock const&) = default;
71 
73  virtual time_point
74  now() const = 0;
75 };
76 
77 //------------------------------------------------------------------------------
78 
79 namespace detail {
80 
81 template <class Facade, class Clock>
82 struct abstract_clock_wrapper : public abstract_clock<Facade>
83 {
84  explicit abstract_clock_wrapper() = default;
85 
86  using typename abstract_clock<Facade>::duration;
88 
90  now() const override
91  {
92  return Clock::now();
93  }
94 };
95 
96 } // namespace detail
97 
98 //------------------------------------------------------------------------------
99 
105 template <class Facade, class Clock = Facade>
106 abstract_clock<Facade>&
108 {
110  return clock;
111 }
112 
113 } // namespace beast
114 
115 #endif
beast::abstract_clock::is_steady
static const bool is_steady
Definition: abstract_clock.h:66
std::chrono::system_clock
beast::abstract_clock< std::chrono::system_clock >::period
typename std::chrono::system_clock ::period period
Definition: abstract_clock.h:61
beast::abstract_clock::now
virtual time_point now() const =0
Returns the current time.
beast::abstract_clock::abstract_clock
abstract_clock()=default
chrono
beast::get_abstract_clock
abstract_clock< Facade > & get_abstract_clock()
Returns a global instance of an abstract clock.
Definition: abstract_clock.h:107
beast::abstract_clock
Abstract interface to a clock.
Definition: abstract_clock.h:57
beast::detail::abstract_clock_wrapper
Definition: abstract_clock.h:82
beast::detail::abstract_clock_wrapper::now
time_point now() const override
Definition: abstract_clock.h:90
beast::abstract_clock< std::chrono::system_clock >::rep
typename std::chrono::system_clock ::rep rep
Definition: abstract_clock.h:60
beast::detail::abstract_clock_wrapper::abstract_clock_wrapper
abstract_clock_wrapper()=default
beast::abstract_clock::~abstract_clock
virtual ~abstract_clock()=default
beast::abstract_clock< std::chrono::system_clock >::time_point
typename std::chrono::system_clock ::time_point time_point
Definition: abstract_clock.h:63
beast::abstract_clock< std::chrono::system_clock >::duration
typename std::chrono::system_clock ::duration duration
Definition: abstract_clock.h:62
beast
Definition: base_uint.h:641
string