Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <limits>
7 : #include <ostream>
8 :
9 : #include "Time/Time.hpp"
10 :
11 : /// \ingroup TimeGroup
12 : /// Time-like interface to a double for use with dense output
13 1 : struct ApproximateTime {
14 0 : double time = std::numeric_limits<double>::signaling_NaN();
15 0 : double value() const { return time; }
16 : };
17 :
18 : /// \ingroup TimeGroup
19 : /// TimeDelta-like interface to a double for use with dense output
20 1 : struct ApproximateTimeDelta {
21 0 : double delta = std::numeric_limits<double>::signaling_NaN();
22 0 : double value() const { return delta; }
23 0 : bool is_positive() const { return delta > 0.; }
24 : };
25 :
26 : // Duplicate most of the interface for Time and TimeDelta. Leave out
27 : // the mutation functions, as these are only supposed to be used for
28 : // temporary calculations.
29 :
30 0 : #define DECLARE_OP(lprefix, rprefix, ret, op, lhs, rhs) \
31 : ret operator op(const lprefix##lhs& a, const rprefix##rhs& b);
32 :
33 0 : #define DECLARE_ALL_OPS(lprefix, rprefix) \
34 : DECLARE_OP(lprefix, rprefix, bool, ==, Time, Time) \
35 : DECLARE_OP(lprefix, rprefix, bool, !=, Time, Time) \
36 : DECLARE_OP(lprefix, rprefix, bool, <, Time, Time) \
37 : DECLARE_OP(lprefix, rprefix, bool, >, Time, Time) \
38 : DECLARE_OP(lprefix, rprefix, bool, <=, Time, Time) \
39 : DECLARE_OP(lprefix, rprefix, bool, >=, Time, Time) \
40 : DECLARE_OP(lprefix, rprefix, bool, ==, TimeDelta, TimeDelta) \
41 : DECLARE_OP(lprefix, rprefix, bool, !=, TimeDelta, TimeDelta) \
42 : DECLARE_OP(lprefix, rprefix, bool, <, TimeDelta, TimeDelta) \
43 : DECLARE_OP(lprefix, rprefix, bool, >, TimeDelta, TimeDelta) \
44 : DECLARE_OP(lprefix, rprefix, bool, <=, TimeDelta, TimeDelta) \
45 : DECLARE_OP(lprefix, rprefix, bool, >=, TimeDelta, TimeDelta) \
46 : DECLARE_OP(lprefix, rprefix, ApproximateTimeDelta, -, Time, Time) \
47 : DECLARE_OP(lprefix, rprefix, ApproximateTime, +, Time, TimeDelta) \
48 : DECLARE_OP(lprefix, rprefix, ApproximateTime, +, TimeDelta, Time) \
49 : DECLARE_OP(lprefix, rprefix, ApproximateTime, -, Time, TimeDelta) \
50 : DECLARE_OP(lprefix, rprefix, ApproximateTimeDelta, +, TimeDelta, TimeDelta) \
51 : DECLARE_OP(lprefix, rprefix, ApproximateTimeDelta, -, TimeDelta, TimeDelta) \
52 : DECLARE_OP(lprefix, rprefix, double, /, TimeDelta, TimeDelta)
53 :
54 : DECLARE_ALL_OPS(Approximate, )
55 : DECLARE_ALL_OPS(, Approximate)
56 : DECLARE_ALL_OPS(Approximate, Approximate)
57 :
58 : #undef DECLARE_ALL_OPS
59 : #undef DECLARE_OP
60 :
61 0 : ApproximateTimeDelta operator+(const ApproximateTimeDelta& a);
62 0 : ApproximateTimeDelta operator-(const ApproximateTimeDelta& a);
63 :
64 0 : ApproximateTimeDelta operator*(const ApproximateTimeDelta& a,
65 : const TimeDelta::rational_t& b);
66 0 : ApproximateTimeDelta operator*(const TimeDelta::rational_t& a,
67 : const ApproximateTimeDelta& b);
68 0 : ApproximateTimeDelta operator/(const ApproximateTimeDelta& a,
69 : const TimeDelta::rational_t& b);
70 :
71 0 : std::ostream& operator<<(std::ostream& os, const ApproximateTime& t);
72 :
73 0 : ApproximateTimeDelta abs(const ApproximateTimeDelta& t);
74 :
75 0 : std::ostream& operator<<(std::ostream& os, const ApproximateTimeDelta& dt);
|