PTLib  Version 2.10.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timeint.h
Go to the documentation of this file.
1 /*
2  * timeint.h
3  *
4  * Millisecond resolution time interval class (uses 64 bit integers).
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 #ifndef PTLIB_TIMEINTERVAL_H
35 #define PTLIB_TIMEINTERVAL_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 
43 // Difference between two system times
44 
55 class PTimeInterval : public PObject
56 {
57  PCLASSINFO(PTimeInterval, PObject);
58 
59  public:
74  PInt64 millisecs = 0
75  );
77  long millisecs,
78  long seconds,
79  long minutes = 0,
80  long hours = 0,
81  int days = 0
82  );
84  const PString & str
85  );
87 
96  PObject * Clone() const;
97 
105  virtual Comparison Compare(
106  const PObject & obj
107  ) const;
108 
112  virtual void PrintOn(
113  ostream & strm
114  ) const;
115 
119  virtual void ReadFrom(
120  istream & strm
121  );
123 
126  enum Formats {
130  };
131 
133  int decimals = 3,
134  Formats format = NormalFormat,
135  int width = 1
136  ) const;
138 
146  virtual PInt64 GetMilliSeconds() const;
147 
150  virtual void SetMilliSeconds(PInt64 msecs);
151 
157  long GetSeconds() const;
158 
164  long GetMinutes() const;
165 
171  int GetHours() const;
172 
178  int GetDays() const;
179 
185  DWORD GetInterval() const;
186 
198  virtual void SetInterval(
199  PInt64 milliseconds = 0,
200  long seconds = 0,
201  long minutes = 0,
202  long hours = 0,
203  int days = 0
204  );
206 
214  PTimeInterval operator-() const;
215 
222  const PTimeInterval & interval
223  ) const;
224 
231  const PTimeInterval & interval
232  );
233 
240  const PTimeInterval & interval
241  ) const;
242 
249  const PTimeInterval & interval
250  );
251 
258  int factor
259  ) const;
260 
267  int factor
268  );
269 
275  int operator/(
276  const PTimeInterval & smaller
277  ) const;
278 
285  int factor
286  ) const;
287 
294  int factor
295  );
297 
307  bool operator==(
308  const PTimeInterval & interval
309  ) const;
310  bool operator==(
311  long msecs
312  ) const;
313 
321  bool operator!=(
322  const PTimeInterval & interval
323  ) const;
324  bool operator!=(
325  long msecs
326  ) const;
327 
335  bool operator> (
336  const PTimeInterval & interval
337  ) const;
338  bool operator> (
339  long msecs
340  ) const;
341 
349  bool operator>=(
350  const PTimeInterval & interval
351  ) const;
352  bool operator>=(
353  long msecs
354  ) const;
355 
363  bool operator< (
364  const PTimeInterval & interval
365  ) const;
366  bool operator< (
367  long msecs
368  ) const;
369 
377  bool operator<=(
378  const PTimeInterval & interval
379  ) const;
380  bool operator<=(
381  long msecs
382  ) const;
384 
385  private:
386  // Member variables
388  PInt64 m_milliseconds;
389 
390 
391 // Include platform dependent part of class
392 #ifdef _WIN32
393 #include "msos/ptlib/timeint.h"
394 #else
395 #include "unix/ptlib/timeint.h"
396 #endif
397 };
398 
399 #endif // PTLIB_TIMEINTERVAL_H
400 
401 
402 // End Of File ///////////////////////////////////////////////////////////////
Definition: timeint.h:127
PTimeInterval operator-() const
Unary minus, get negative of time interval.
PTimeInterval operator+(const PTimeInterval &interval) const
Add the two time intervals yielding a third time interval.
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
PTimeInterval operator*(int factor) const
Multiply the time interval by a factor yielding a third time interval.
virtual void ReadFrom(istream &strm)
Input the time interval from the I/O stream.
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
bool operator<=(const PTimeInterval &interval) const
Compare to the two time intervals.
virtual Comparison Compare(const PObject &obj) const
Rank the two time intervals.
PTimeInterval & operator-=(const PTimeInterval &interval)
Subtract the second time interval from the first time interval.
bool operator!=(const PTimeInterval &interval) const
Compare to the two time intervals.
Formats
Definition: timeint.h:126
virtual PInt64 GetMilliSeconds() const
Get the number of milliseconds for the time interval.
bool operator==(const PTimeInterval &interval) const
Compare to the two time intervals.
PTimeInterval(PInt64 millisecs=0)
Create a new time interval object.
PTimeInterval & operator/=(int factor)
Divide the time interval by a factor.
virtual void SetMilliSeconds(PInt64 msecs)
Set the number of milliseconds for the time interval.
PTimeInterval & operator+=(const PTimeInterval &interval)
Add the second time interval to the first time interval.
The character string class.
Definition: pstring.h:108
Definition: timeint.h:129
virtual void PrintOn(ostream &strm) const
Output the time interval to the I/O stream.
virtual void SetInterval(PInt64 milliseconds=0, long seconds=0, long minutes=0, long hours=0, int days=0)
Set the value of the time interval.
bool operator>(const PTimeInterval &interval) const
Compare to the two time intervals.
Definition: timeint.h:128
DWORD GetInterval() const
Get the number of milliseconds for the time interval.
long GetMinutes() const
Get the number of whole minutes for the time interval.
bool operator>=(const PTimeInterval &interval) const
Compare to the two time intervals.
long GetSeconds() const
Get the number of whole seconds for the time interval.
bool operator<(const PTimeInterval &interval) const
Compare to the two time intervals.
int operator/(const PTimeInterval &smaller) const
Divide the time interval by another interval yielding a count.
int GetDays() const
Get the number of whole days for the time interval.
int GetHours() const
Get the number of whole hours for the time interval.
PObject * Clone() const
Create a new copy of the time interval.
PTimeInterval & operator*=(int factor)
Multiply the time interval by a factor.
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PString AsString(int decimals=3, Formats format=NormalFormat, int width=1) const