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.31 2005/11/25 03:43:47 csoutheren 00031 * Fixed function argument comments to be compatible with Doxygen 00032 * 00033 * Revision 1.30 2004/04/18 04:33:36 rjongbloed 00034 * Changed all operators that return BOOL to return standard type bool. This is primarily 00035 * for improved compatibility with std STL usage removing many warnings. 00036 * 00037 * Revision 1.29 2003/09/17 05:41:59 csoutheren 00038 * Removed recursive includes 00039 * 00040 * Revision 1.28 2003/09/17 01:18:02 csoutheren 00041 * Removed recursive include file system and removed all references 00042 * to deprecated coooperative threading support 00043 * 00044 * Revision 1.27 2002/09/16 01:08:59 robertj 00045 * Added #define so can select if #pragma interface/implementation is used on 00046 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00047 * 00048 * Revision 1.26 2002/05/28 13:05:26 robertj 00049 * Fixed PTimer::SetInterval so it restarts timer as per operator=() 00050 * 00051 * Revision 1.25 2001/10/16 07:44:06 robertj 00052 * Added AsString() function to PTimeInterval. 00053 * 00054 * Revision 1.24 2001/07/10 02:55:16 robertj 00055 * Added unary minus operator 00056 * 00057 * Revision 1.23 2001/05/22 12:49:32 robertj 00058 * Did some seriously wierd rewrite of platform headers to eliminate the 00059 * stupid GNU compiler warning about braces not matching. 00060 * 00061 * Revision 1.22 2000/10/05 23:36:26 robertj 00062 * Fixed compiler ambiguities in PTimeInterval constructor. 00063 * 00064 * Revision 1.21 2000/03/06 04:09:23 robertj 00065 * Added constructor to do PString conversion to PTimeInterval 00066 * 00067 * Revision 1.20 1999/07/06 04:46:00 robertj 00068 * Fixed being able to case an unsigned to a PTimeInterval. 00069 * Improved resolution of PTimer::Tick() to be millisecond accurate. 00070 * 00071 * Revision 1.19 1999/03/09 02:59:51 robertj 00072 * Changed comments to doc++ compatible documentation. 00073 * 00074 * Revision 1.18 1999/02/16 08:11:17 robertj 00075 * MSVC 6.0 compatibility changes. 00076 * 00077 * Revision 1.17 1998/09/23 06:21:43 robertj 00078 * Added open source copyright license. 00079 * 00080 * Revision 1.16 1998/01/26 00:49:53 robertj 00081 * Added multiply and divide operators to PTimeInterval. 00082 * 00083 * Revision 1.15 1996/05/15 10:19:29 robertj 00084 * Changed millisecond access functions to get 64 bit integer. 00085 * 00086 * Revision 1.14 1996/05/09 12:22:09 robertj 00087 * Resolved C++ problems with 64 bit PTimeInterval for Mac platform. 00088 * 00089 * Revision 1.13 1996/03/17 05:52:02 robertj 00090 * Changed PTimeInterval to 64 bit integer. 00091 * 00092 * Revision 1.12 1995/03/14 12:42:50 robertj 00093 * Updated documentation to use HTML codes. 00094 * 00095 * Revision 1.11 1995/01/18 09:01:32 robertj 00096 * Documentation. 00097 * 00098 * Revision 1.10 1995/01/09 12:29:41 robertj 00099 * Removed unnecesary return value from I/O functions. 00100 * 00101 * Revision 1.9 1994/08/23 11:32:52 robertj 00102 * Oops 00103 * 00104 * Revision 1.8 1994/08/22 00:46:48 robertj 00105 * Added pragma fro GNU C++ compiler. 00106 * 00107 * Revision 1.7 1994/07/02 03:03:49 robertj 00108 * Timer redesign consequences and ability to compare a time interval against 00109 * ordinary integer milliseconds. 00110 * 00111 * Revision 1.6 1994/06/25 11:55:15 robertj 00112 * Unix version synchronisation. 00113 * 00114 * Revision 1.5 1994/01/03 04:42:23 robertj 00115 * Mass changes to common container classes and interactors etc etc etc. 00116 * 00117 * Revision 1.4 1993/08/31 03:38:02 robertj 00118 * Added copy constructor and assignement oeprator due to G++ strangeness. 00119 * 00120 * Revision 1.3 1993/08/27 18:17:47 robertj 00121 * Added function to set the interval of a PTieInterval object. 00122 * Used a common type for number of milliseconds. 00123 * 00124 * Revision 1.2 1993/07/14 12:49:16 robertj 00125 * Fixed RCS keywords. 00126 * 00127 */ 00128 00129 #ifndef _PTIMEINTERVAL 00130 #define _PTIMEINTERVAL 00131 00132 #ifdef P_USE_PRAGMA 00133 #pragma interface 00134 #endif 00135 00136 00138 // Difference between two system times 00139 00150 class PTimeInterval : public PObject 00151 { 00152 PCLASSINFO(PTimeInterval, PObject); 00153 00154 public: 00168 PTimeInterval( 00169 PInt64 millisecs = 0 00170 ); 00171 PTimeInterval( 00172 long millisecs, 00173 long seconds, 00174 long minutes = 0, 00175 long hours = 0, 00176 int days = 0 00177 ); 00178 PTimeInterval( 00179 const PString & str 00180 ); 00182 00191 PObject * Clone() const; 00192 00200 virtual Comparison Compare( 00201 const PObject & obj 00202 ) const; 00203 00207 virtual void PrintOn( 00208 ostream & strm 00209 ) const; 00210 00214 virtual void ReadFrom( 00215 istream & strm 00216 ); 00218 00221 enum Formats { 00222 NormalFormat, 00223 IncludeDays, 00224 SecondsOnly 00225 }; 00226 00227 PString AsString( 00228 int decimals = 3, 00229 Formats format = NormalFormat, 00230 int width = 1 00231 ) const; 00233 00241 PInt64 GetMilliSeconds() const; 00242 00248 long GetSeconds() const; 00249 00255 long GetMinutes() const; 00256 00262 int GetHours() const; 00263 00269 int GetDays() const; 00270 00276 DWORD GetInterval() const; 00277 00289 virtual void SetInterval( 00290 PInt64 milliseconds = 0, 00291 long seconds = 0, 00292 long minutes = 0, 00293 long hours = 0, 00294 int days = 0 00295 ); 00297 00305 PTimeInterval operator-() const; 00306 00312 PTimeInterval operator+( 00313 const PTimeInterval & interval 00314 ) const; 00315 00321 PTimeInterval & operator+=( 00322 const PTimeInterval & interval 00323 ); 00324 00330 PTimeInterval operator-( 00331 const PTimeInterval & interval 00332 ) const; 00333 00339 PTimeInterval & operator-=( 00340 const PTimeInterval & interval 00341 ); 00342 00348 PTimeInterval operator*( 00349 int factor 00350 ) const; 00351 00357 PTimeInterval & operator*=( 00358 int factor 00359 ); 00360 00366 PTimeInterval operator/( 00367 int factor 00368 ) const; 00369 00375 PTimeInterval & operator/=( 00376 int factor 00377 ); 00379 00389 bool operator==( 00390 const PTimeInterval & interval 00391 ) const; 00392 bool operator==( 00393 long msecs 00394 ) const; 00395 00403 bool operator!=( 00404 const PTimeInterval & interval 00405 ) const; 00406 bool operator!=( 00407 long msecs 00408 ) const; 00409 00417 bool operator> ( 00418 const PTimeInterval & interval 00419 ) const; 00420 bool operator> ( 00421 long msecs 00422 ) const; 00423 00431 bool operator>=( 00432 const PTimeInterval & interval 00433 ) const; 00434 bool operator>=( 00435 long msecs 00436 ) const; 00437 00445 bool operator< ( 00446 const PTimeInterval & interval 00447 ) const; 00448 bool operator< ( 00449 long msecs 00450 ) const; 00451 00459 bool operator<=( 00460 const PTimeInterval & interval 00461 ) const; 00462 bool operator<=( 00463 long msecs 00464 ) const; 00466 00467 protected: 00468 // Member variables 00470 PInt64 milliseconds; 00471 00472 00473 // Include platform dependent part of class 00474 #ifdef _WIN32 00475 #include "msos/ptlib/timeint.h" 00476 #else 00477 #include "unix/ptlib/timeint.h" 00478 #endif 00479 }; 00480 00481 #endif 00482 00483 00484 // End Of File ///////////////////////////////////////////////////////////////