File indexing completed on 2025-01-18 09:29:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #ifndef BOOST_CHRONO_TIME_POINT_HPP
0031 #define BOOST_CHRONO_TIME_POINT_HPP
0032
0033 #include <boost/chrono/duration.hpp>
0034
0035 #ifndef BOOST_CHRONO_HEADER_ONLY
0036
0037 #include <boost/config/abi_prefix.hpp> // must be the last #include
0038 #endif
0039
0040
0041
0042
0043
0044
0045
0046
0047 namespace boost {
0048 namespace chrono {
0049
0050 template <class Clock, class Duration = typename Clock::duration>
0051 class time_point;
0052
0053
0054 }
0055
0056
0057
0058
0059 template <class Clock, class Duration1, class Duration2>
0060 struct common_type<chrono::time_point<Clock, Duration1>,
0061 chrono::time_point<Clock, Duration2> >;
0062
0063
0064
0065
0066
0067
0068
0069 template <class Clock, class Duration1, class Duration2>
0070 struct common_type<chrono::time_point<Clock, Duration1>,
0071 chrono::time_point<Clock, Duration2> >
0072 {
0073 typedef chrono::time_point<Clock,
0074 typename common_type<Duration1, Duration2>::type> type;
0075 };
0076
0077
0078
0079 namespace chrono {
0080
0081
0082 template <class Clock, class Duration1, class Rep2, class Period2>
0083 inline BOOST_CONSTEXPR
0084 time_point<Clock,
0085 typename common_type<Duration1, duration<Rep2, Period2> >::type>
0086 operator+(
0087 const time_point<Clock, Duration1>& lhs,
0088 const duration<Rep2, Period2>& rhs);
0089 template <class Rep1, class Period1, class Clock, class Duration2>
0090 inline BOOST_CONSTEXPR
0091 time_point<Clock,
0092 typename common_type<duration<Rep1, Period1>, Duration2>::type>
0093 operator+(
0094 const duration<Rep1, Period1>& lhs,
0095 const time_point<Clock, Duration2>& rhs);
0096 template <class Clock, class Duration1, class Rep2, class Period2>
0097 inline BOOST_CONSTEXPR
0098 time_point<Clock,
0099 typename common_type<Duration1, duration<Rep2, Period2> >::type>
0100 operator-(
0101 const time_point<Clock, Duration1>& lhs,
0102 const duration<Rep2, Period2>& rhs);
0103 template <class Clock, class Duration1, class Duration2>
0104 inline BOOST_CONSTEXPR
0105 typename common_type<Duration1, Duration2>::type
0106 operator-(
0107 const time_point<Clock, Duration1>& lhs,
0108 const time_point<Clock,
0109 Duration2>& rhs);
0110
0111
0112 template <class Clock, class Duration1, class Duration2>
0113 inline BOOST_CONSTEXPR
0114 bool operator==(
0115 const time_point<Clock, Duration1>& lhs,
0116 const time_point<Clock, Duration2>& rhs);
0117 template <class Clock, class Duration1, class Duration2>
0118 inline BOOST_CONSTEXPR
0119 bool operator!=(
0120 const time_point<Clock, Duration1>& lhs,
0121 const time_point<Clock, Duration2>& rhs);
0122 template <class Clock, class Duration1, class Duration2>
0123 inline BOOST_CONSTEXPR
0124 bool operator< (
0125 const time_point<Clock, Duration1>& lhs,
0126 const time_point<Clock, Duration2>& rhs);
0127 template <class Clock, class Duration1, class Duration2>
0128 inline BOOST_CONSTEXPR
0129 bool operator<=(
0130 const time_point<Clock, Duration1>& lhs,
0131 const time_point<Clock, Duration2>& rhs);
0132 template <class Clock, class Duration1, class Duration2>
0133 inline BOOST_CONSTEXPR
0134 bool operator> (
0135 const time_point<Clock, Duration1>& lhs,
0136 const time_point<Clock, Duration2>& rhs);
0137 template <class Clock, class Duration1, class Duration2>
0138 inline BOOST_CONSTEXPR
0139 bool operator>=(
0140 const time_point<Clock, Duration1>& lhs,
0141 const time_point<Clock, Duration2>& rhs);
0142
0143
0144 template <class ToDuration, class Clock, class Duration>
0145 inline BOOST_CONSTEXPR
0146 time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
0147
0148
0149
0150
0151
0152
0153
0154 template <class Clock, class Duration>
0155 class time_point
0156 {
0157 BOOST_CHRONO_STATIC_ASSERT(boost::chrono::detail::is_duration<Duration>::value,
0158 BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_TIME_POINT_MUST_BE_A_BOOST_CHRONO_DURATION, (Duration));
0159 public:
0160 typedef Clock clock;
0161 typedef Duration duration;
0162 typedef typename duration::rep rep;
0163 typedef typename duration::period period;
0164 typedef Duration difference_type;
0165
0166 private:
0167 duration d_;
0168
0169 public:
0170 BOOST_FORCEINLINE BOOST_CONSTEXPR
0171 time_point() : d_(duration::zero())
0172 {}
0173 BOOST_FORCEINLINE BOOST_CONSTEXPR
0174 explicit time_point(const duration& d)
0175 : d_(d)
0176 {}
0177
0178
0179 template <class Duration2>
0180 BOOST_FORCEINLINE BOOST_CONSTEXPR
0181 time_point(const time_point<clock, Duration2>& t
0182 , typename boost::enable_if
0183 <
0184 boost::is_convertible<Duration2, duration>
0185 >::type* = BOOST_NULLPTR
0186 )
0187 : d_(t.time_since_epoch())
0188 {
0189 }
0190
0191
0192 BOOST_CONSTEXPR
0193 duration time_since_epoch() const
0194 {
0195 return d_;
0196 }
0197
0198
0199
0200 #ifdef BOOST_CHRONO_EXTENSIONS
0201 BOOST_CONSTEXPR
0202 time_point operator+() const {return *this;}
0203 BOOST_CONSTEXPR
0204 time_point operator-() const {return time_point(-d_);}
0205 time_point& operator++() {++d_; return *this;}
0206 time_point operator++(int) {return time_point(d_++);}
0207 time_point& operator--() {--d_; return *this;}
0208 time_point operator--(int) {return time_point(d_--);}
0209
0210 time_point& operator+=(const rep& r) {d_ += duration(r); return *this;}
0211 time_point& operator-=(const rep& r) {d_ -= duration(r); return *this;}
0212
0213 #endif
0214
0215 time_point& operator+=(const duration& d) {d_ += d; return *this;}
0216 time_point& operator-=(const duration& d) {d_ -= d; return *this;}
0217
0218
0219
0220 static BOOST_CHRONO_LIB_CONSTEXPR time_point
0221 min BOOST_PREVENT_MACRO_SUBSTITUTION ()
0222 {
0223 return time_point((duration::min)());
0224 }
0225 static BOOST_CHRONO_LIB_CONSTEXPR time_point
0226 max BOOST_PREVENT_MACRO_SUBSTITUTION ()
0227 {
0228 return time_point((duration::max)());
0229 }
0230 };
0231
0232
0233
0234
0235
0236
0237
0238 template <class Clock, class Duration1, class Rep2, class Period2>
0239 inline BOOST_CONSTEXPR
0240 time_point<Clock,
0241 typename common_type<Duration1, duration<Rep2, Period2> >::type>
0242 operator+(const time_point<Clock, Duration1>& lhs,
0243 const duration<Rep2, Period2>& rhs)
0244 {
0245 typedef typename common_type<Duration1, duration<Rep2, Period2> >::type CDuration;
0246 typedef time_point<
0247 Clock,
0248 CDuration
0249 > TimeResult;
0250 return TimeResult(lhs.time_since_epoch() + CDuration(rhs));
0251 }
0252
0253
0254
0255 template <class Rep1, class Period1, class Clock, class Duration2>
0256 inline BOOST_CONSTEXPR
0257 time_point<Clock,
0258 typename common_type<duration<Rep1, Period1>, Duration2>::type>
0259 operator+(const duration<Rep1, Period1>& lhs,
0260 const time_point<Clock, Duration2>& rhs)
0261 {
0262 return rhs + lhs;
0263 }
0264
0265
0266
0267 template <class Clock, class Duration1, class Rep2, class Period2>
0268 inline BOOST_CONSTEXPR
0269 time_point<Clock,
0270 typename common_type<Duration1, duration<Rep2, Period2> >::type>
0271 operator-(const time_point<Clock, Duration1>& lhs,
0272 const duration<Rep2, Period2>& rhs)
0273 {
0274 return lhs + (-rhs);
0275 }
0276
0277
0278
0279 template <class Clock, class Duration1, class Duration2>
0280 inline BOOST_CONSTEXPR
0281 typename common_type<Duration1, Duration2>::type
0282 operator-(const time_point<Clock, Duration1>& lhs,
0283 const time_point<Clock, Duration2>& rhs)
0284 {
0285 return lhs.time_since_epoch() - rhs.time_since_epoch();
0286 }
0287
0288
0289
0290
0291
0292
0293
0294 template <class Clock, class Duration1, class Duration2>
0295 inline BOOST_CONSTEXPR
0296 bool
0297 operator==(const time_point<Clock, Duration1>& lhs,
0298 const time_point<Clock, Duration2>& rhs)
0299 {
0300 return lhs.time_since_epoch() == rhs.time_since_epoch();
0301 }
0302
0303
0304
0305 template <class Clock, class Duration1, class Duration2>
0306 inline BOOST_CONSTEXPR
0307 bool
0308 operator!=(const time_point<Clock, Duration1>& lhs,
0309 const time_point<Clock, Duration2>& rhs)
0310 {
0311 return !(lhs == rhs);
0312 }
0313
0314
0315
0316 template <class Clock, class Duration1, class Duration2>
0317 inline BOOST_CONSTEXPR
0318 bool
0319 operator<(const time_point<Clock, Duration1>& lhs,
0320 const time_point<Clock, Duration2>& rhs)
0321 {
0322 return lhs.time_since_epoch() < rhs.time_since_epoch();
0323 }
0324
0325
0326
0327 template <class Clock, class Duration1, class Duration2>
0328 inline BOOST_CONSTEXPR
0329 bool
0330 operator>(const time_point<Clock, Duration1>& lhs,
0331 const time_point<Clock, Duration2>& rhs)
0332 {
0333 return rhs < lhs;
0334 }
0335
0336
0337
0338 template <class Clock, class Duration1, class Duration2>
0339 inline BOOST_CONSTEXPR
0340 bool
0341 operator<=(const time_point<Clock, Duration1>& lhs,
0342 const time_point<Clock, Duration2>& rhs)
0343 {
0344 return !(rhs < lhs);
0345 }
0346
0347
0348
0349 template <class Clock, class Duration1, class Duration2>
0350 inline BOOST_CONSTEXPR
0351 bool
0352 operator>=(const time_point<Clock, Duration1>& lhs,
0353 const time_point<Clock, Duration2>& rhs)
0354 {
0355 return !(lhs < rhs);
0356 }
0357
0358
0359
0360
0361
0362 template <class ToDuration, class Clock, class Duration>
0363 inline BOOST_CONSTEXPR
0364 time_point<Clock, ToDuration>
0365 time_point_cast(const time_point<Clock, Duration>& t)
0366 {
0367 return time_point<Clock, ToDuration>(
0368 duration_cast<ToDuration>(t.time_since_epoch()));
0369 }
0370
0371 }
0372 }
0373
0374 #ifndef BOOST_CHRONO_HEADER_ONLY
0375
0376 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
0377 #endif
0378
0379 #endif