Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JGeometry3D/JTime.hh
Go to the documentation of this file.
1#ifndef __JTIME1__
2#define __JTIME1__
3
4#include <istream>
5#include <ostream>
6
8#include "JLang/JManip.hh"
9
10
11/**
12 * \author mdejong
13 */
14
15namespace JGEOMETRY3D {}
16namespace JPP { using namespace JGEOMETRY3D; }
17
18namespace JGEOMETRY3D {
19
20 using JIO::JReader;
21 using JIO::JWriter;
22
23
24 /**
25 * Time.
26 */
27 class JTime
28 {
29 public:
30 /**
31 * Default constructor.
32 */
34 __t(0.0)
35 {}
36
37
38 /**
39 * Constructor.
40 *
41 * \param t time
42 */
43 JTime(const double t) :
44 __t(t)
45 {}
46
47
48 /**
49 * Prefix unary minus.
50 *
51 * \return time
52 */
54 {
55 __t = -__t;
56
57 return *this;
58 }
59
60
61 /**
62 * Addition operator.
63 *
64 * \param value time
65 * \return time
66 */
67 JTime& add(const JTime& value)
68 {
69 __t += value.getT();
70
71 return *this;
72 }
73
74
75 /**
76 * Subtraction operator.
77 *
78 * \param value time
79 * \return time
80 */
81 JTime& sub(const JTime& value)
82 {
83 __t -= value.getT();
84
85 return *this;
86 }
87
88
89 /**
90 * Multiplication operator.
91 *
92 * \param value multiplication factor
93 * \return time
94 */
95 JTime& mul(const double value)
96 {
97 __t *= value;
98
99 return *this;
100 }
101
102
103 /**
104 * Division operator.
105 *
106 * \param value multiplication factor
107 * \return time
108 */
109 JTime& div(const double value)
110 {
111 __t /= value;
112
113 return *this;
114 }
115
116
117 /**
118 * Set time.
119 *
120 * \param time
121 */
122 inline void setT(const double time)
123 {
124 __t = time;
125 }
126
127
128 /**
129 * Get time.
130 *
131 * \return time
132 */
133 inline double getT() const
134 {
135 return __t;
136 }
137
138
139 /**
140 * Read time from input.
141 *
142 * \param in input stream
143 * \param time time
144 * \return input stream
145 */
146 friend inline std::istream& operator>>(std::istream& in, JTime& time)
147 {
148 in >> time.__t;
149
150 return in;
151 }
152
153
154 /**
155 * Write time to output.
156 *
157 * \param out output stream
158 * \param time time
159 * \return output stream
160 */
161 friend inline std::ostream& operator<<(std::ostream& out, const JTime& time)
162 {
163 const JFormat format(out, getFormat<JTime>(JFormat_t(9, 3, std::ios::fixed | std::ios::showpos)));
164
165 out << time.__t;
166
167 return out;
168 }
169
170
171 /**
172 * Read time from input.
173 *
174 * \param in reader
175 * \param time time
176 * \return reader
177 */
178 friend inline JReader& operator>>(JReader& in, JTime& time)
179 {
180 in >> time.__t;
181
182 return in;
183 }
184
185
186 /**
187 * Write time to output.
188 *
189 * \param out writer
190 * \param time time
191 * \return writer
192 */
193 friend inline JWriter& operator<<(JWriter& out, const JTime& time)
194 {
195 out << time.__t;
196
197 return out;
198 }
199
200
201 protected:
202 double __t;
203 };
204}
205
206#endif
I/O manipulators.
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
void setT(const double time)
Set time.
JTime(const double t)
Constructor.
JTime & div(const double value)
Division operator.
JTime()
Default constructor.
JTime & add(const JTime &value)
Addition operator.
friend std::istream & operator>>(std::istream &in, JTime &time)
Read time from input.
friend JWriter & operator<<(JWriter &out, const JTime &time)
Write time to output.
friend JReader & operator>>(JReader &in, JTime &time)
Read time from input.
JTime & negate()
Prefix unary minus.
double getT() const
Get time.
JTime & mul(const double value)
Multiplication operator.
JTime & sub(const JTime &value)
Subtraction operator.
friend std::ostream & operator<<(std::ostream &out, const JTime &time)
Write time to output.
Interface for binary input.
Interface for binary output.
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636