comparison liboctave/system/oct-time.h @ 31607:aac27ad79be6 stable

maint: Re-indent code after switch to using namespace macros. * build-env.h, build-env.in.cc, Cell.h, __betainc__.cc, __eigs__.cc, __ftp__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __magick_read__.cc, __pchip_deriv__.cc, amd.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, dasrt.cc, data.cc, debug.cc, defaults.cc, defaults.h, det.cc, display.cc, display.h, dlmread.cc, dynamic-ld.cc, dynamic-ld.h, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, gsvd.cc, gtk-manager.cc, gtk-manager.h, help.cc, help.h, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mexproto.h, mxarray.h, mxtypes.in.h, oct-errno.in.cc, oct-hdf5-types.cc, oct-hist.cc, oct-hist.h, oct-map.cc, oct-map.h, oct-opengl.h, oct-prcstrm.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h, octave-default-image.h, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-output.cc, psi.cc, qr.cc, quadcc.cc, rand.cc, regexp.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xpow.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfns.cc, svd.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, __delaunayn__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audioread.cc, convhulln.cc, gzip.cc, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.h, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-java.cc, ov-lazy-idx.cc, ov-legacy-range.cc, ov-magic-int.cc, ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.h, octave.cc, octave.h, op-b-sbm.cc, op-bm-sbm.cc, op-cs-scm.cc, op-fm-fcm.cc, op-fs-fcm.cc, op-s-scm.cc, op-scm-cs.cc, op-scm-s.cc, op-sm-cs.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, oct-lvalue.cc, oct-lvalue.h, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h: Re-indent code after switch to using namespace macros.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 18:02:15 -0800
parents e88a07dec498
children 597f3ee61a48
comparison
equal deleted inserted replaced
31605:e88a07dec498 31607:aac27ad79be6
43 43
44 OCTAVE_BEGIN_NAMESPACE(octave) 44 OCTAVE_BEGIN_NAMESPACE(octave)
45 45
46 OCTAVE_BEGIN_NAMESPACE(sys) 46 OCTAVE_BEGIN_NAMESPACE(sys)
47 47
48 class base_tm; 48 class base_tm;
49 49
50 class 50 class
51 time 51 time
52 { 52 {
53 public: 53 public:
54 54
55 time (void) 55 time (void)
56 : m_ot_unix_time (0), m_ot_usec (0) { stamp (); } 56 : m_ot_unix_time (0), m_ot_usec (0) { stamp (); }
57 57
58 time (OCTAVE_TIME_T t) 58 time (OCTAVE_TIME_T t)
59 : m_ot_unix_time (t), m_ot_usec (0) { } 59 : m_ot_unix_time (t), m_ot_usec (0) { }
60 60
61 time (OCTAVE_TIME_T t, long us) 61 time (OCTAVE_TIME_T t, long us)
62 : m_ot_unix_time (t), m_ot_usec () 62 : m_ot_unix_time (t), m_ot_usec ()
63 {
64 long rem, extra;
65
66 if (us >= 0)
63 { 67 {
64 long rem, extra; 68 rem = us % 1000000;
65 69 extra = (us - rem) / 1000000;
66 if (us >= 0)
67 {
68 rem = us % 1000000;
69 extra = (us - rem) / 1000000;
70 }
71 else
72 {
73 us = -us;
74 rem = us % 1000000;
75 extra = - (1 + (us - rem) / 1000000);
76 rem = 1000000 - us % 1000000;
77 }
78
79 m_ot_usec = rem;
80 m_ot_unix_time += extra;
81 } 70 }
82 71 else
83 OCTAVE_API time (double d);
84
85 OCTAVE_API time (const base_tm& tm);
86
87 time (const time& ot)
88 : m_ot_unix_time (ot.m_ot_unix_time), m_ot_usec (ot.m_ot_usec) { }
89
90 time& operator = (const time& ot)
91 { 72 {
92 if (this != &ot) 73 us = -us;
93 { 74 rem = us % 1000000;
94 m_ot_unix_time = ot.m_ot_unix_time; 75 extra = - (1 + (us - rem) / 1000000);
95 m_ot_usec = ot.m_ot_usec; 76 rem = 1000000 - us % 1000000;
96 }
97
98 return *this;
99 } 77 }
100 78
101 ~time (void) = default; 79 m_ot_usec = rem;
102 80 m_ot_unix_time += extra;
103 OCTAVE_API void stamp (void); 81 }
104 82
105 double double_value (void) const 83 OCTAVE_API time (double d);
84
85 OCTAVE_API time (const base_tm& tm);
86
87 time (const time& ot)
88 : m_ot_unix_time (ot.m_ot_unix_time), m_ot_usec (ot.m_ot_usec) { }
89
90 time& operator = (const time& ot)
91 {
92 if (this != &ot)
106 { 93 {
107 return as_double (m_ot_unix_time, m_ot_usec); 94 m_ot_unix_time = ot.m_ot_unix_time;
95 m_ot_usec = ot.m_ot_usec;
108 } 96 }
109 97
110 OCTAVE_TIME_T unix_time (void) const { return m_ot_unix_time; } 98 return *this;
111 99 }
112 long usec (void) const { return m_ot_usec; } 100
113 101 ~time (void) = default;
114 OCTAVE_API std::string ctime (void) const; 102
115 103 OCTAVE_API void stamp (void);
116 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const time& ot); 104
117 105 double double_value (void) const
118 private: 106 {
119 107 return as_double (m_ot_unix_time, m_ot_usec);
120 // Seconds since the epoch. 108 }
121 OCTAVE_TIME_T m_ot_unix_time; 109
122 110 OCTAVE_TIME_T unix_time (void) const { return m_ot_unix_time; }
123 // Additional microseconds. 111
124 long m_ot_usec; 112 long usec (void) const { return m_ot_usec; }
125 }; 113
126 114 OCTAVE_API std::string ctime (void) const;
127 inline bool 115
128 operator == (const time& t1, const time& t2) 116 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const time& ot);
129 { 117
130 return (t1.unix_time () == t2.unix_time () && t1.usec () == t2.usec ()); 118 private:
131 } 119
132 120 // Seconds since the epoch.
133 inline bool 121 OCTAVE_TIME_T m_ot_unix_time;
134 operator != (const time& t1, const time& t2) 122
135 { 123 // Additional microseconds.
136 return ! (t1 == t2); 124 long m_ot_usec;
137 } 125 };
138 126
139 inline bool 127 inline bool
140 operator < (const time& t1, const time& t2) 128 operator == (const time& t1, const time& t2)
141 { 129 {
142 if (t1.unix_time () < t2.unix_time ()) 130 return (t1.unix_time () == t2.unix_time () && t1.usec () == t2.usec ());
143 return true; 131 }
144 else if (t1.unix_time () > t2.unix_time ()) 132
145 return false; 133 inline bool
146 else if (t1.usec () < t2.usec ()) 134 operator != (const time& t1, const time& t2)
147 return true; 135 {
148 else 136 return ! (t1 == t2);
149 return false; 137 }
150 } 138
151 139 inline bool
152 inline bool 140 operator < (const time& t1, const time& t2)
153 operator <= (const time& t1, const time& t2) 141 {
154 { 142 if (t1.unix_time () < t2.unix_time ())
155 return (t1 < t2 || t1 == t2); 143 return true;
156 } 144 else if (t1.unix_time () > t2.unix_time ())
157 145 return false;
158 inline bool 146 else if (t1.usec () < t2.usec ())
159 operator > (const time& t1, const time& t2) 147 return true;
160 { 148 else
161 if (t1.unix_time () > t2.unix_time ()) 149 return false;
162 return true; 150 }
163 else if (t1.unix_time () < t2.unix_time ()) 151
164 return false; 152 inline bool
165 else if (t1.usec () > t2.usec ()) 153 operator <= (const time& t1, const time& t2)
166 return true; 154 {
167 else 155 return (t1 < t2 || t1 == t2);
168 return false; 156 }
169 } 157
170 158 inline bool
171 inline bool 159 operator > (const time& t1, const time& t2)
172 operator >= (const time& t1, const time& t2) 160 {
173 { 161 if (t1.unix_time () > t2.unix_time ())
174 return (t1 > t2 || t1 == t2); 162 return true;
175 } 163 else if (t1.unix_time () < t2.unix_time ())
176 164 return false;
177 inline time 165 else if (t1.usec () > t2.usec ())
178 operator + (const time& t1, const time& t2) 166 return true;
179 { 167 else
180 return time (t1.unix_time () + t2.unix_time (), 168 return false;
181 t1.usec () + t2.usec ()); 169 }
182 } 170
183 171 inline bool
184 class 172 operator >= (const time& t1, const time& t2)
185 base_tm 173 {
186 { 174 return (t1 > t2 || t1 == t2);
187 public: 175 }
188 176
189 base_tm (void) 177 inline time
190 : m_usec (0), m_sec (0), m_min (0), m_hour (0), 178 operator + (const time& t1, const time& t2)
191 m_mday (0), m_mon (0), m_year (0), m_wday (0), 179 {
192 m_yday (0), m_isdst (0), m_gmtoff (0), m_zone ("unknown") 180 return time (t1.unix_time () + t2.unix_time (),
193 { } 181 t1.usec () + t2.usec ());
194 182 }
195 base_tm (const base_tm& tm) 183
196 : m_usec (tm.m_usec), m_sec (tm.m_sec), m_min (tm.m_min), 184 class
197 m_hour (tm.m_hour), m_mday (tm.m_mday), m_mon (tm.m_mon), 185 base_tm
198 m_year (tm.m_year), m_wday (tm.m_wday), m_yday (tm.m_yday), 186 {
199 m_isdst (tm.m_isdst), m_gmtoff (tm.m_gmtoff), m_zone (tm.m_zone) 187 public:
200 { } 188
201 189 base_tm (void)
202 base_tm& operator = (const base_tm& tm) 190 : m_usec (0), m_sec (0), m_min (0), m_hour (0),
191 m_mday (0), m_mon (0), m_year (0), m_wday (0),
192 m_yday (0), m_isdst (0), m_gmtoff (0), m_zone ("unknown")
193 { }
194
195 base_tm (const base_tm& tm)
196 : m_usec (tm.m_usec), m_sec (tm.m_sec), m_min (tm.m_min),
197 m_hour (tm.m_hour), m_mday (tm.m_mday), m_mon (tm.m_mon),
198 m_year (tm.m_year), m_wday (tm.m_wday), m_yday (tm.m_yday),
199 m_isdst (tm.m_isdst), m_gmtoff (tm.m_gmtoff), m_zone (tm.m_zone)
200 { }
201
202 base_tm& operator = (const base_tm& tm)
203 {
204 if (this != &tm)
203 { 205 {
204 if (this != &tm) 206 m_usec = tm.m_usec;
205 { 207 m_sec = tm.m_sec;
206 m_usec = tm.m_usec; 208 m_min = tm.m_min;
207 m_sec = tm.m_sec; 209 m_hour = tm.m_hour;
208 m_min = tm.m_min; 210 m_mday = tm.m_mday;
209 m_hour = tm.m_hour; 211 m_mon = tm.m_mon;
210 m_mday = tm.m_mday; 212 m_year = tm.m_year;
211 m_mon = tm.m_mon; 213 m_wday = tm.m_wday;
212 m_year = tm.m_year; 214 m_yday = tm.m_yday;
213 m_wday = tm.m_wday; 215 m_isdst = tm.m_isdst;
214 m_yday = tm.m_yday; 216 m_gmtoff = tm.m_gmtoff;
215 m_isdst = tm.m_isdst; 217 m_zone = tm.m_zone;
216 m_gmtoff = tm.m_gmtoff;
217 m_zone = tm.m_zone;
218 }
219
220 return *this;
221 } 218 }
222 219
223 virtual ~base_tm (void) = default; 220 return *this;
224 221 }
225 int usec (void) const { return m_usec; } 222
226 int sec (void) const { return m_sec; } 223 virtual ~base_tm (void) = default;
227 int min (void) const { return m_min; } 224
228 int hour (void) const { return m_hour; } 225 int usec (void) const { return m_usec; }
229 int mday (void) const { return m_mday; } 226 int sec (void) const { return m_sec; }
230 int mon (void) const { return m_mon; } 227 int min (void) const { return m_min; }
231 int year (void) const { return m_year; } 228 int hour (void) const { return m_hour; }
232 int wday (void) const { return m_wday; } 229 int mday (void) const { return m_mday; }
233 int yday (void) const { return m_yday; } 230 int mon (void) const { return m_mon; }
234 int isdst (void) const { return m_isdst; } 231 int year (void) const { return m_year; }
235 long gmtoff (void) const { return m_gmtoff; } 232 int wday (void) const { return m_wday; }
236 std::string zone (void) const { return m_zone; } 233 int yday (void) const { return m_yday; }
237 234 int isdst (void) const { return m_isdst; }
238 OCTAVE_API base_tm& usec (int v); 235 long gmtoff (void) const { return m_gmtoff; }
239 OCTAVE_API base_tm& sec (int v); 236 std::string zone (void) const { return m_zone; }
240 OCTAVE_API base_tm& min (int v); 237
241 OCTAVE_API base_tm& hour (int v); 238 OCTAVE_API base_tm& usec (int v);
242 OCTAVE_API base_tm& mday (int v); 239 OCTAVE_API base_tm& sec (int v);
243 OCTAVE_API base_tm& mon (int v); 240 OCTAVE_API base_tm& min (int v);
244 OCTAVE_API base_tm& year (int v); 241 OCTAVE_API base_tm& hour (int v);
245 OCTAVE_API base_tm& wday (int v); 242 OCTAVE_API base_tm& mday (int v);
246 OCTAVE_API base_tm& yday (int v); 243 OCTAVE_API base_tm& mon (int v);
247 OCTAVE_API base_tm& isdst (int v); 244 OCTAVE_API base_tm& year (int v);
248 OCTAVE_API base_tm& gmtoff (long v); 245 OCTAVE_API base_tm& wday (int v);
249 OCTAVE_API base_tm& zone (const std::string& s); 246 OCTAVE_API base_tm& yday (int v);
250 247 OCTAVE_API base_tm& isdst (int v);
251 OCTAVE_API std::string strftime (const std::string& fmt) const; 248 OCTAVE_API base_tm& gmtoff (long v);
252 249 OCTAVE_API base_tm& zone (const std::string& s);
253 std::string asctime (void) const 250
254 { return strftime ("%a %b %d %H:%M:%S %Y\n"); } 251 OCTAVE_API std::string strftime (const std::string& fmt) const;
255 252
256 protected: 253 std::string asctime (void) const
257 254 { return strftime ("%a %b %d %H:%M:%S %Y\n"); }
258 // Microseconds after the second (0, 999999). 255
259 int m_usec; 256 protected:
260 257
261 // Seconds after the minute (0, 61). 258 // Microseconds after the second (0, 999999).
262 int m_sec; 259 int m_usec;
263 260
264 // Minutes after the hour (0, 59). 261 // Seconds after the minute (0, 61).
265 int m_min; 262 int m_sec;
266 263
267 // Hours since midnight (0, 23). 264 // Minutes after the hour (0, 59).
268 int m_hour; 265 int m_min;
269 266
270 // Day of the month (1, 31). 267 // Hours since midnight (0, 23).
271 int m_mday; 268 int m_hour;
272 269
273 // Months since January (0, 11). 270 // Day of the month (1, 31).
274 int m_mon; 271 int m_mday;
275 272
276 // Years since 1900. 273 // Months since January (0, 11).
277 int m_year; 274 int m_mon;
278 275
279 // Days since Sunday (0, 6). 276 // Years since 1900.
280 int m_wday; 277 int m_year;
281 278
282 // Days since January 1 (0, 365). 279 // Days since Sunday (0, 6).
283 int m_yday; 280 int m_wday;
284 281
285 // Daylight saving time flag. 282 // Days since January 1 (0, 365).
286 int m_isdst; 283 int m_yday;
287 284
288 // Time zone. 285 // Daylight saving time flag.
289 long m_gmtoff; 286 int m_isdst;
290 287
291 // Time zone. 288 // Time zone.
292 std::string m_zone; 289 long m_gmtoff;
293 290
294 OCTAVE_API void init (void *p); 291 // Time zone.
295 }; 292 std::string m_zone;
296 293
297 class 294 OCTAVE_API void init (void *p);
298 localtime : public base_tm 295 };
299 { 296
300 public: 297 class
301 298 localtime : public base_tm
302 localtime (void) 299 {
303 : base_tm () { init (time ()); } 300 public:
304 301
305 localtime (const time& ot) 302 localtime (void)
306 : base_tm () { init (ot); } 303 : base_tm () { init (time ()); }
307 304
308 localtime (const localtime& t) 305 localtime (const time& ot)
309 : base_tm (t) { } 306 : base_tm () { init (ot); }
310 307
311 localtime& operator = (const localtime& t) 308 localtime (const localtime& t)
309 : base_tm (t) { }
310
311 localtime& operator = (const localtime& t)
312 {
313 base_tm::operator = (t);
314 return *this;
315 }
316
317 ~localtime (void) = default;
318
319 private:
320
321 OCTAVE_API void init (const time& ot);
322 };
323
324 class
325 gmtime : public base_tm
326 {
327 public:
328
329 gmtime (void)
330 : base_tm () { init (time ()); }
331
332 gmtime (const time& ot)
333 : base_tm () { init (ot); }
334
335 gmtime& operator = (const gmtime& t)
336 {
337 base_tm::operator = (t);
338 return *this;
339 }
340
341 ~gmtime (void) = default;
342
343 private:
344
345 OCTAVE_API void init (const time& ot);
346 };
347
348 class
349 strptime : public base_tm
350 {
351 public:
352
353 strptime (const std::string& str, const std::string& fmt)
354 : base_tm (), m_nchars (0)
355 {
356 init (str, fmt);
357 }
358
359 strptime (const strptime& s)
360 : base_tm (s), m_nchars (s.m_nchars) { }
361
362 strptime& operator = (const strptime& s)
363 {
364 base_tm::operator = (s);
365 m_nchars = s.m_nchars;
366 return *this;
367 }
368
369 int characters_converted (void) const { return m_nchars; }
370
371 ~strptime (void) = default;
372
373 private:
374
375 int m_nchars;
376
377 OCTAVE_API void init (const std::string& str, const std::string& fmt);
378 };
379
380 class
381 cpu_time
382 {
383 public:
384
385 friend class resource_usage;
386
387 cpu_time (void)
388 : m_usr_sec (0), m_sys_sec (0), m_usr_usec (0), m_sys_usec (0)
389 {
390 stamp ();
391 }
392
393 cpu_time (const cpu_time& tm)
394 : m_usr_sec (tm.m_usr_sec), m_sys_sec (tm.m_sys_sec),
395 m_usr_usec (tm.m_usr_usec), m_sys_usec (tm.m_sys_usec)
396 { }
397
398 cpu_time& operator = (const cpu_time& tm)
399 {
400 if (&tm != this)
312 { 401 {
313 base_tm::operator = (t); 402 m_usr_sec = tm.m_usr_sec;
314 return *this; 403 m_sys_sec = tm.m_sys_sec;
404 m_usr_usec = tm.m_usr_usec;
405 m_sys_usec = tm.m_sys_usec;
315 } 406 }
316 407
317 ~localtime (void) = default; 408 return *this;
318 409 }
319 private: 410
320 411 OCTAVE_API void stamp (void);
321 OCTAVE_API void init (const time& ot); 412
322 }; 413 double user (void) const
323 414 {
324 class 415 return as_double (m_usr_sec, m_usr_usec);
325 gmtime : public base_tm 416 }
326 { 417
327 public: 418 double system (void) const
328 419 {
329 gmtime (void) 420 return as_double (m_sys_sec, m_sys_usec);
330 : base_tm () { init (time ()); } 421 }
331 422
332 gmtime (const time& ot) 423 OCTAVE_TIME_T user_sec (void) const { return m_usr_sec; }
333 : base_tm () { init (ot); } 424 long user_usec (void) const { return m_usr_usec; }
334 425
335 gmtime& operator = (const gmtime& t) 426 OCTAVE_TIME_T system_sec (void) const { return m_sys_sec; }
427 long system_usec (void) const { return m_sys_usec; }
428
429 private:
430
431 OCTAVE_TIME_T m_usr_sec;
432 OCTAVE_TIME_T m_sys_sec;
433
434 long m_usr_usec;
435 long m_sys_usec;
436
437 cpu_time (OCTAVE_TIME_T usr_sec, OCTAVE_TIME_T sys_sec, long usr_usec, long sys_usec)
438 : m_usr_sec (usr_sec), m_sys_sec (sys_sec),
439 m_usr_usec (usr_usec), m_sys_usec (sys_usec)
440 { }
441 };
442
443 class
444 resource_usage
445 {
446 public:
447
448 resource_usage (void)
449 : m_cpu (), m_maxrss (0), m_ixrss (0), m_idrss (0),
450 m_isrss (0), m_minflt (0), m_majflt (0), m_nswap (0),
451 m_inblock (0), m_oublock (0), m_msgsnd (0), m_msgrcv (0),
452 m_nsignals (0), m_nvcsw (0), m_nivcsw (0)
453 {
454 stamp ();
455 }
456
457 resource_usage (const resource_usage& ru)
458 : m_cpu (ru.m_cpu), m_maxrss (ru.m_maxrss),
459 m_ixrss (ru.m_ixrss), m_idrss (ru.m_idrss),
460 m_isrss (ru.m_isrss), m_minflt (ru.m_minflt),
461 m_majflt (ru.m_majflt), m_nswap (ru.m_nswap),
462 m_inblock (ru.m_inblock), m_oublock (ru.m_oublock),
463 m_msgsnd (ru.m_msgsnd), m_msgrcv (ru.m_msgrcv),
464 m_nsignals (ru.m_nsignals), m_nvcsw (ru.m_nvcsw),
465 m_nivcsw (ru.m_nivcsw)
466 { }
467
468 resource_usage& operator = (const resource_usage& ru)
469 {
470 if (&ru != this)
336 { 471 {
337 base_tm::operator = (t); 472 m_cpu = ru.m_cpu;
338 return *this; 473
474 m_maxrss = ru.m_maxrss;
475 m_ixrss = ru.m_ixrss;
476 m_idrss = ru.m_idrss;
477 m_isrss = ru.m_isrss;
478 m_minflt = ru.m_minflt;
479 m_majflt = ru.m_majflt;
480 m_nswap = ru.m_nswap;
481 m_inblock = ru.m_inblock;
482 m_oublock = ru.m_oublock;
483 m_msgsnd = ru.m_msgsnd;
484 m_msgrcv = ru.m_msgrcv;
485 m_nsignals = ru.m_nsignals;
486 m_nvcsw = ru.m_nvcsw;
487 m_nivcsw = ru.m_nivcsw;
339 } 488 }
340 489
341 ~gmtime (void) = default; 490 return *this;
342 491 }
343 private: 492
344 493 OCTAVE_API void stamp (void);
345 OCTAVE_API void init (const time& ot); 494
346 }; 495 cpu_time cpu (void) const { return m_cpu; }
347 496
348 class 497 long maxrss (void) const { return m_maxrss; }
349 strptime : public base_tm 498 long ixrss (void) const { return m_ixrss; }
350 { 499 long idrss (void) const { return m_idrss; }
351 public: 500 long isrss (void) const { return m_isrss; }
352 501 long minflt (void) const { return m_minflt; }
353 strptime (const std::string& str, const std::string& fmt) 502 long majflt (void) const { return m_majflt; }
354 : base_tm (), m_nchars (0) 503 long nswap (void) const { return m_nswap; }
355 { 504 long inblock (void) const { return m_inblock; }
356 init (str, fmt); 505 long oublock (void) const { return m_oublock; }
357 } 506 long msgsnd (void) const { return m_msgsnd; }
358 507 long msgrcv (void) const { return m_msgrcv; }
359 strptime (const strptime& s) 508 long nsignals (void) const { return m_nsignals; }
360 : base_tm (s), m_nchars (s.m_nchars) { } 509 long nvcsw (void) const { return m_nvcsw; }
361 510 long nivcsw (void) const { return m_nivcsw; }
362 strptime& operator = (const strptime& s) 511
363 { 512 private:
364 base_tm::operator = (s); 513
365 m_nchars = s.m_nchars; 514 cpu_time m_cpu;
366 return *this; 515
367 } 516 long m_maxrss;
368 517 long m_ixrss;
369 int characters_converted (void) const { return m_nchars; } 518 long m_idrss;
370 519 long m_isrss;
371 ~strptime (void) = default; 520 long m_minflt;
372 521 long m_majflt;
373 private: 522 long m_nswap;
374 523 long m_inblock;
375 int m_nchars; 524 long m_oublock;
376 525 long m_msgsnd;
377 OCTAVE_API void init (const std::string& str, const std::string& fmt); 526 long m_msgrcv;
378 }; 527 long m_nsignals;
379 528 long m_nvcsw;
380 class 529 long m_nivcsw;
381 cpu_time 530 };
382 {
383 public:
384
385 friend class resource_usage;
386
387 cpu_time (void)
388 : m_usr_sec (0), m_sys_sec (0), m_usr_usec (0), m_sys_usec (0)
389 {
390 stamp ();
391 }
392
393 cpu_time (const cpu_time& tm)
394 : m_usr_sec (tm.m_usr_sec), m_sys_sec (tm.m_sys_sec),
395 m_usr_usec (tm.m_usr_usec), m_sys_usec (tm.m_sys_usec)
396 { }
397
398 cpu_time& operator = (const cpu_time& tm)
399 {
400 if (&tm != this)
401 {
402 m_usr_sec = tm.m_usr_sec;
403 m_sys_sec = tm.m_sys_sec;
404 m_usr_usec = tm.m_usr_usec;
405 m_sys_usec = tm.m_sys_usec;
406 }
407
408 return *this;
409 }
410
411 OCTAVE_API void stamp (void);
412
413 double user (void) const
414 {
415 return as_double (m_usr_sec, m_usr_usec);
416 }
417
418 double system (void) const
419 {
420 return as_double (m_sys_sec, m_sys_usec);
421 }
422
423 OCTAVE_TIME_T user_sec (void) const { return m_usr_sec; }
424 long user_usec (void) const { return m_usr_usec; }
425
426 OCTAVE_TIME_T system_sec (void) const { return m_sys_sec; }
427 long system_usec (void) const { return m_sys_usec; }
428
429 private:
430
431 OCTAVE_TIME_T m_usr_sec;
432 OCTAVE_TIME_T m_sys_sec;
433
434 long m_usr_usec;
435 long m_sys_usec;
436
437 cpu_time (OCTAVE_TIME_T usr_sec, OCTAVE_TIME_T sys_sec, long usr_usec, long sys_usec)
438 : m_usr_sec (usr_sec), m_sys_sec (sys_sec),
439 m_usr_usec (usr_usec), m_sys_usec (sys_usec)
440 { }
441 };
442
443 class
444 resource_usage
445 {
446 public:
447
448 resource_usage (void)
449 : m_cpu (), m_maxrss (0), m_ixrss (0), m_idrss (0),
450 m_isrss (0), m_minflt (0), m_majflt (0), m_nswap (0),
451 m_inblock (0), m_oublock (0), m_msgsnd (0), m_msgrcv (0),
452 m_nsignals (0), m_nvcsw (0), m_nivcsw (0)
453 {
454 stamp ();
455 }
456
457 resource_usage (const resource_usage& ru)
458 : m_cpu (ru.m_cpu), m_maxrss (ru.m_maxrss),
459 m_ixrss (ru.m_ixrss), m_idrss (ru.m_idrss),
460 m_isrss (ru.m_isrss), m_minflt (ru.m_minflt),
461 m_majflt (ru.m_majflt), m_nswap (ru.m_nswap),
462 m_inblock (ru.m_inblock), m_oublock (ru.m_oublock),
463 m_msgsnd (ru.m_msgsnd), m_msgrcv (ru.m_msgrcv),
464 m_nsignals (ru.m_nsignals), m_nvcsw (ru.m_nvcsw),
465 m_nivcsw (ru.m_nivcsw)
466 { }
467
468 resource_usage& operator = (const resource_usage& ru)
469 {
470 if (&ru != this)
471 {
472 m_cpu = ru.m_cpu;
473
474 m_maxrss = ru.m_maxrss;
475 m_ixrss = ru.m_ixrss;
476 m_idrss = ru.m_idrss;
477 m_isrss = ru.m_isrss;
478 m_minflt = ru.m_minflt;
479 m_majflt = ru.m_majflt;
480 m_nswap = ru.m_nswap;
481 m_inblock = ru.m_inblock;
482 m_oublock = ru.m_oublock;
483 m_msgsnd = ru.m_msgsnd;
484 m_msgrcv = ru.m_msgrcv;
485 m_nsignals = ru.m_nsignals;
486 m_nvcsw = ru.m_nvcsw;
487 m_nivcsw = ru.m_nivcsw;
488 }
489
490 return *this;
491 }
492
493 OCTAVE_API void stamp (void);
494
495 cpu_time cpu (void) const { return m_cpu; }
496
497 long maxrss (void) const { return m_maxrss; }
498 long ixrss (void) const { return m_ixrss; }
499 long idrss (void) const { return m_idrss; }
500 long isrss (void) const { return m_isrss; }
501 long minflt (void) const { return m_minflt; }
502 long majflt (void) const { return m_majflt; }
503 long nswap (void) const { return m_nswap; }
504 long inblock (void) const { return m_inblock; }
505 long oublock (void) const { return m_oublock; }
506 long msgsnd (void) const { return m_msgsnd; }
507 long msgrcv (void) const { return m_msgrcv; }
508 long nsignals (void) const { return m_nsignals; }
509 long nvcsw (void) const { return m_nvcsw; }
510 long nivcsw (void) const { return m_nivcsw; }
511
512 private:
513
514 cpu_time m_cpu;
515
516 long m_maxrss;
517 long m_ixrss;
518 long m_idrss;
519 long m_isrss;
520 long m_minflt;
521 long m_majflt;
522 long m_nswap;
523 long m_inblock;
524 long m_oublock;
525 long m_msgsnd;
526 long m_msgrcv;
527 long m_nsignals;
528 long m_nvcsw;
529 long m_nivcsw;
530 };
531 531
532 OCTAVE_END_NAMESPACE(sys) 532 OCTAVE_END_NAMESPACE(sys)
533 OCTAVE_END_NAMESPACE(octave) 533 OCTAVE_END_NAMESPACE(octave)
534 534
535 #endif 535 #endif