00001 /* 00002 * timeint.h 00003 * 00004 * Millisecond resolution time interval class (uses 64 bit integers). 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-1998 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Portions are Copyright (C) 1993 Free Software Foundation, Inc. 00025 * All Rights Reserved. 00026 * 00027 * Contributor(s): ______________________________________. 00028 * 00029 * $Log: timeint.h,v $ 00030 * Revision 1.30 2004/04/18 04:33:36 rjongbloed 00031 * Changed all operators that return BOOL to return standard type bool. This is primarily 00032 * for improved compatibility with std STL usage removing many warnings. 00033 * 00034 * Revision 1.29 2003/09/17 05:41:59 csoutheren 00035 * Removed recursive includes 00036 * 00037 * Revision 1.28 2003/09/17 01:18:02 csoutheren 00038 * Removed recursive include file system and removed all references 00039 * to deprecated coooperative threading support 00040 * 00041 * Revision 1.27 2002/09/16 01:08:59 robertj 00042 * Added #define so can select if #pragma interface/implementation is used on 00043 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00044 * 00045 * Revision 1.26 2002/05/28 13:05:26 robertj 00046 * Fixed PTimer::SetInterval so it restarts timer as per operator=() 00047 * 00048 * Revision 1.25 2001/10/16 07:44:06 robertj 00049 * Added AsString() function to PTimeInterval. 00050 * 00051 * Revision 1.24 2001/07/10 02:55:16 robertj 00052 * Added unary minus operator 00053 * 00054 * Revision 1.23 2001/05/22 12:49:32 robertj 00055 * Did some seriously wierd rewrite of platform headers to eliminate the 00056 * stupid GNU compiler warning about braces not matching. 00057 * 00058 * Revision 1.22 2000/10/05 23:36:26 robertj 00059 * Fixed compiler ambiguities in PTimeInterval constructor. 00060 * 00061 * Revision 1.21 2000/03/06 04:09:23 robertj 00062 * Added constructor to do PString conversion to PTimeInterval 00063 * 00064 * Revision 1.20 1999/07/06 04:46:00 robertj 00065 * Fixed being able to case an unsigned to a PTimeInterval. 00066 * Improved resolution of PTimer::Tick() to be millisecond accurate. 00067 * 00068 * Revision 1.19 1999/03/09 02:59:51 robertj 00069 * Changed comments to doc++ compatible documentation. 00070 * 00071 * Revision 1.18 1999/02/16 08:11:17 robertj 00072 * MSVC 6.0 compatibility changes. 00073 * 00074 * Revision 1.17 1998/09/23 06:21:43 robertj 00075 * Added open source copyright license. 00076 * 00077 * Revision 1.16 1998/01/26 00:49:53 robertj 00078 * Added multiply and divide operators to PTimeInterval. 00079 * 00080 * Revision 1.15 1996/05/15 10:19:29 robertj 00081 * Changed millisecond access functions to get 64 bit integer. 00082 * 00083 * Revision 1.14 1996/05/09 12:22:09 robertj 00084 * Resolved C++ problems with 64 bit PTimeInterval for Mac platform. 00085 * 00086 * Revision 1.13 1996/03/17 05:52:02 robertj 00087 * Changed PTimeInterval to 64 bit integer. 00088 * 00089 * Revision 1.12 1995/03/14 12:42:50 robertj 00090 * Updated documentation to use HTML codes. 00091 * 00092 * Revision 1.11 1995/01/18 09:01:32 robertj 00093 * Documentation. 00094 * 00095 * Revision 1.10 1995/01/09 12:29:41 robertj 00096 * Removed unnecesary return value from I/O functions. 00097 * 00098 * Revision 1.9 1994/08/23 11:32:52 robertj 00099 * Oops 00100 * 00101 * Revision 1.8 1994/08/22 00:46:48 robertj 00102 * Added pragma fro GNU C++ compiler. 00103 * 00104 * Revision 1.7 1994/07/02 03:03:49 robertj 00105 * Timer redesign consequences and ability to compare a time interval against 00106 * ordinary integer milliseconds. 00107 * 00108 * Revision 1.6 1994/06/25 11:55:15 robertj 00109 * Unix version synchronisation. 00110 * 00111 * Revision 1.5 1994/01/03 04:42:23 robertj 00112 * Mass changes to common container classes and interactors etc etc etc. 00113 * 00114 * Revision 1.4 1993/08/31 03:38:02 robertj 00115 * Added copy constructor and assignement oeprator due to G++ strangeness. 00116 * 00117 * Revision 1.3 1993/08/27 18:17:47 robertj 00118 * Added function to set the interval of a PTieInterval object. 00119 * Used a common type for number of milliseconds. 00120 * 00121 * Revision 1.2 1993/07/14 12:49:16 robertj 00122 * Fixed RCS keywords. 00123 * 00124 */ 00125 00126 #ifndef _PTIMEINTERVAL 00127 #define _PTIMEINTERVAL 00128 00129 #ifdef P_USE_PRAGMA 00130 #pragma interface 00131 #endif 00132 00133 00135 // Difference between two system times 00136 00147 class PTimeInterval : public PObject 00148 { 00149 PCLASSINFO(PTimeInterval, PObject); 00150 00151 public: 00165 PTimeInterval( 00166 PInt64 millisecs = 0 00167 ); 00168 PTimeInterval( 00169 long millisecs, 00170 long seconds, 00171 long minutes = 0, 00172 long hours = 0, 00173 int days = 0 00174 ); 00175 PTimeInterval( 00176 const PString & str 00177 ); 00179 00188 PObject * Clone() const; 00189 00197 virtual Comparison Compare( 00198 const PObject & obj 00199 ) const; 00200 00204 virtual void PrintOn( 00205 ostream & strm 00206 ) const; 00207 00211 virtual void ReadFrom( 00212 istream & strm 00213 ); 00215 00218 enum Formats { 00219 NormalFormat, 00220 IncludeDays, 00221 SecondsOnly 00222 }; 00223 00224 PString AsString( 00225 int decimals = 3, 00226 Formats format = NormalFormat, 00227 int width = 1 00228 ) const; 00230 00238 PInt64 GetMilliSeconds() const; 00239 00245 long GetSeconds() const; 00246 00252 long GetMinutes() const; 00253 00259 int GetHours() const; 00260 00266 int GetDays() const; 00267 00273 DWORD GetInterval() const; 00274 00286 virtual void SetInterval( 00287 PInt64 milliseconds = 0, 00288 long seconds = 0, 00289 long minutes = 0, 00290 long hours = 0, 00291 int days = 0 00292 ); 00294 00302 PTimeInterval operator-() const; 00303 00309 PTimeInterval operator+( 00310 const PTimeInterval & interval 00311 ) const; 00312 00318 PTimeInterval & operator+=( 00319 const PTimeInterval & interval 00320 ); 00321 00327 PTimeInterval operator-( 00328 const PTimeInterval & interval 00329 ) const; 00330 00336 PTimeInterval & operator-=( 00337 const PTimeInterval & interval 00338 ); 00339 00345 PTimeInterval operator*( 00346 int factor 00347 ) const; 00348 00354 PTimeInterval & operator*=( 00355 int factor 00356 ); 00357 00363 PTimeInterval operator/( 00364 int factor 00365 ) const; 00366 00372 PTimeInterval & operator/=( 00373 int factor 00374 ); 00376 00386 bool operator==( 00387 const PTimeInterval & interval 00388 ) const; 00389 bool operator==( 00390 long msecs 00391 ) const; 00392 00400 bool operator!=( 00401 const PTimeInterval & interval 00402 ) const; 00403 bool operator!=( 00404 long msecs 00405 ) const; 00406 00414 bool operator> ( 00415 const PTimeInterval & interval 00416 ) const; 00417 bool operator> ( 00418 long msecs 00419 ) const; 00420 00428 bool operator>=( 00429 const PTimeInterval & interval 00430 ) const; 00431 bool operator>=( 00432 long msecs 00433 ) const; 00434 00442 bool operator< ( 00443 const PTimeInterval & interval 00444 ) const; 00445 bool operator< ( 00446 long msecs 00447 ) const; 00448 00456 bool operator<=( 00457 const PTimeInterval & interval 00458 ) const; 00459 bool operator<=( 00460 long msecs 00461 ) const; 00463 00464 protected: 00465 // Member variables 00467 PInt64 milliseconds; 00468 00469 00470 // Include platform dependent part of class 00471 #ifdef _WIN32 00472 #include "msos/ptlib/timeint.h" 00473 #else 00474 #include "unix/ptlib/timeint.h" 00475 #endif 00476 }; 00477 00478 #endif 00479 00480 00481 // End Of File ///////////////////////////////////////////////////////////////