OpenDDS  Snapshot(2023/04/28-20:55)
TimePoint_T.h
Go to the documentation of this file.
1 #ifndef OPENDDS_DCPS_TIMEPOINT_T_H
2 #define OPENDDS_DCPS_TIMEPOINT_T_H
3 
4 #include "TimeDuration.h"
5 #include "SafeBool_T.h"
6 
7 #include <dds/DdsDcpsInfoUtilsC.h>
8 
9 #include <ace/Time_Value_T.h>
10 
11 #if !defined (ACE_LACKS_PRAGMA_ONCE)
12 # pragma once
13 #endif /* ACE_LACKS_PRAGMA_ONCE */
14 
16 
17 namespace OpenDDS {
18 namespace DCPS {
19 
20 /**
21  * Represents a specific time in reference to a ACE_Time_Policy and is based on
22  * C++11 std::chrono::time_point.
23  *
24  * This wraps an ACE_Time_Value, but is designed to enforce the logic that this
25  * represents a specific point in time. For example, you can't directly add two
26  * TimePoints like you can add two ACE_Time_Values, because that wouldn't make
27  * sense. Following this theme, all the constructors are to be explicit to
28  * avoid careless implicit conversions.
29  *
30  * See https://opendds.readthedocs.io/en/master/internal/dev_guidelines.html#time
31  * (or docs/internal/dev_guidelines.rst) for background and reasoning for this
32  * class.
33  */
34 template<typename AceClock>
35 class TimePoint_T : public SafeBool_T<TimePoint_T<AceClock> > {
36 public:
37  typedef AceClock ClockType;
39 
42 
43  /**
44  * Set to zero_value, which is equal to the epoch (the starting point) of the
45  * AceClock.
46  */
47  TimePoint_T();
48 
49  /**
50  * Assign the value directly to the inner value doing conversions as
51  * necessary.
52  *
53  * \warning Use these carefully. Make sure ACE_Time_Value is a point in time
54  * and of the right clock type. DDS::Time_t should be in system clock time
55  * and so shouldn't be used with MonotonicTimePoint.
56  */
57  ///@{
58  explicit TimePoint_T(const ACE_Time_Value& ace_time_value);
59  explicit TimePoint_T(const ACE_Time_Value_T<AceClock>& ace_time_value);
60  explicit TimePoint_T(const DDS::Time_t& dds_time);
61  ///@}
62 
63  /**
64  * Get a TimePoint representing the current time of the AceClock.
65  */
66  static TimePoint_T<AceClock> now();
67 
68  /**
69  * Get and set the inner ACE_Time_Value based value. Use value() to pass this
70  * into ACE code that requires a point in time matching this ones clock
71  * type.
72  */
73  ///@{
74  const ACE_Time_Value_T<AceClock>& value() const;
75  void value(const ACE_Time_Value_T<AceClock>& ace_time_value);
76  ///@}
77 
78  /**
79  * Is the object equal to zero_value?
80  */
81  bool is_zero() const;
82 
83  bool boolean_test() const
84  {
85  return *this != zero_value;
86  }
87 
88  /**
89  * Is the object equal to the maximum possible value, max_value?
90  */
91  bool is_max() const;
92 
93  /**
94  * Set the value to the current time of the AceClock Type.
95  */
96  void set_to_now();
97 
98  /**
99  * Convert to DDS::Time_t. This is probably only desirable for the system
100  * time version of this template class, SystemTimePoint.
101  */
102  DDS::Time_t to_dds_time() const;
103 
104  /**
105  * Convert to OpenDDS::DCPS::MonotonicTime_t.
106  */
108 
111 
112 protected:
113  /**
114  * Strangely, ACE_Time_Policy must be objects to get their time values, so
115  * keep a static object.
116  */
117  static ClockType clock;
118 
119  ValueType value_;
120 };
121 
122 template<typename AceClock>
124 
125 template<typename AceClock>
127 
128 template<typename AceClock>
130 
131 template<typename AceClock>
133 
134 template<typename AceClock>
135 bool operator<(const TimePoint_T<AceClock>& x, const TimePoint_T<AceClock>& y);
136 
137 template<typename AceClock>
138 bool operator>(const TimePoint_T<AceClock>& x, const TimePoint_T<AceClock>& y);
139 
140 template<typename AceClock>
141 bool operator<=(const TimePoint_T<AceClock>& x, const TimePoint_T<AceClock>& y);
142 
143 template<typename AceClock>
145 
146 template<typename AceClock>
148 
149 template<typename AceClock>
151 
152 } // namespace DCPS
153 } // namespace OpenDDS
154 
156 
157 #if defined (__ACE_INLINE__)
158 # include "TimePoint_T.inl"
159 #endif /* __ACE_INLINE__ */
160 
161 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
162 # include "TimePoint_T.cpp"
163 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
164 
165 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
166 # pragma implementation ("TimePoint_T.cpp")
167 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
168 
169 #endif
DDS::Time_t to_dds_time() const
Definition: TimePoint_T.inl:89
ACE_INLINE OpenDDS_Dcps_Export DDS::Duration_t operator-(const DDS::Time_t &t1, const DDS::Time_t &t2)
ACE_INLINE OpenDDS_Dcps_Export bool operator>(const DDS::Duration_t &t1, const DDS::Duration_t &t2)
Definition: Time_Helper.inl:65
bool operator==(const DisjointSequence::OrderedRanges< T > &a, const DisjointSequence::OrderedRanges< T > &b)
static TimePoint_T< AceClock > now()
Definition: TimePoint_T.inl:41
static const TimePoint_T< AceClock > zero_value
Definition: TimePoint_T.h:40
static const TimePoint_T< AceClock > max_value
Definition: TimePoint_T.h:41
bool operator>=(const LogLevel &ll, LogLevel::Value value)
Definition: debug.h:61
static ClockType clock
Definition: TimePoint_T.h:117
SequenceNumber operator+(const SequenceNumber &lhs, int rhs)
bool operator!=(const GUID_t &lhs, const GUID_t &rhs)
Definition: GuidUtils.h:125
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
MonotonicTime_t to_monotonic_time() const
Definition: TimePoint_T.inl:97
const ACE_Time_Value_T< AceClock > & value() const
Definition: TimePoint_T.inl:49
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
ACE_Time_Value_T< AceClock > ValueType
Definition: TimePoint_T.h:38
TimePoint_T< AceClock > & operator-=(const TimeDuration &td)
TimePoint_T< AceClock > & operator+=(const TimeDuration &td)