astrotypes  0.0
DefineClock.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
26 // that use utils::TimePoint<> objects as the time_point
27 // defined as a template class to work around OAT rules
28 // (i.e we can have a header only lib)
29 //
30 #include "TimePoint.h"
31 #include <chrono>
32 
33 #ifndef QUOTE
34 #define Q(x) #x
35 #define QUOTE(x) Q(x)
36 #endif
37 
38 #ifndef PSS_UNITS_DEFINE_CLOCK
39 #define PSS_UNITS_DEFINE_CLOCK(_name_, duration_before_epoch, _symbol_, _is_steady_) \
40 namespace detail { \
41  template<typename TimePoint> \
42  struct _name_##_implementation_t : public std::chrono::system_clock \
43  { \
44  typedef TimePoint time_point; \
45  typedef decltype(duration_before_epoch) duration; \
46  static const duration diff_from_system_epoch; \
47  static time_point now() noexcept { \
48  return time_point(std::chrono::system_clock::now()); \
49  } \
50  }; \
51  \
52  template<typename TimePoint> \
53  const typename _name_##_implementation_t<TimePoint>::duration \
54  _name_##_implementation_t<TimePoint>::diff_from_system_epoch(duration_before_epoch); \
55 } \
56  \
57 struct _name_ : public detail::_name_##_implementation_t<TimePoint<_name_, decltype(duration_before_epoch)>> \
58 { \
59  private: \
60  typedef _name_##_implementation_t<TimePoint<_name_, decltype(duration_before_epoch)>> BaseT; \
61  public: \
62  typedef typename BaseT::duration duration; \
63  typedef typename BaseT::time_point time_point; \
64  typedef duration::rep rep; \
65  typedef duration::period period; \
66  static constexpr bool is_steady = _is_steady_; \
67  static constexpr const char* symbol=QUOTE(_symbol_);\
68  \
69 }
70 
71 #endif // PSS_UNITS_DEFINE_CLOCK