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