# timeint.h

Go to the documentation of this file.

    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  * $Revision: 24177 $
    00030  * $Author: rjongbloed $
    00031  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
    00032  */
    00033
    00034 #ifndef PTLIB_TIMEINTERVAL_H
    00035 #define PTLIB_TIMEINTERVAL_H
    00036
    00037 #ifdef P_USE_PRAGMA
    00038 #pragma interface
    00039 #endif
    00040
    00041
    00043 // Difference between two system times
    00044
    00055 class PTimeInterval : public PObject
    00056 {
    00057   PCLASSINFO(PTimeInterval, PObject);
    00058
    00059   public:
    00073     PTimeInterval(
    00074       PInt64 millisecs = 0
    00075     );
    00076     PTimeInterval(
    00077       long millisecs,
    00078       long seconds,
    00079       long minutes = 0,
    00080       long hours = 0,
    00081       int days = 0
    00082     );
    00083     PTimeInterval(
    00084       const PString & str
    00085     );
    00087
    00096     PObject * Clone() const;
    00097
    00105     virtual Comparison Compare(
    00106       const PObject & obj
    00107     ) const;
    00108
    00112     virtual void PrintOn(
    00113       ostream & strm
    00114     ) const;
    00115
    00119     virtual void ReadFrom(
    00120       istream & strm
    00121     );
    00123
    00126     enum Formats {
    00127       NormalFormat,
    00128       IncludeDays,
    00129       SecondsOnly
    00130     };
    00131
    00132     PString AsString(
    00133       int decimals = 3,
    00134       Formats format = NormalFormat,
    00135       int width = 1
    00136     ) const;
    00138
    00146     virtual PInt64 GetMilliSeconds() const;
    00147
    00150     virtual void SetMilliSeconds(PInt64 msecs);
    00151
    00157     long GetSeconds() const;
    00158
    00164     long GetMinutes() const;
    00165
    00171     int GetHours() const;
    00172
    00178     int GetDays() const;
    00179
    00185     DWORD GetInterval() const;
    00186
    00198     virtual void SetInterval(
    00199       PInt64 milliseconds = 0,
    00200       long seconds = 0,
    00201       long minutes = 0,
    00202       long hours = 0,
    00203       int days = 0
    00204     );
    00206
    00214     PTimeInterval operator-() const;
    00215
    00221     PTimeInterval operator+(
    00222       const PTimeInterval & interval
    00223     ) const;
    00224
    00230     PTimeInterval & operator+=(
    00231       const PTimeInterval & interval
    00232     );
    00233
    00239     PTimeInterval operator-(
    00240       const PTimeInterval & interval
    00241     ) const;
    00242
    00248     PTimeInterval & operator-=(
    00249       const PTimeInterval & interval
    00250     );
    00251
    00257     PTimeInterval operator*(
    00258       int factor
    00259     ) const;
    00260
    00266     PTimeInterval & operator*=(
    00267       int factor
    00268     );
    00269
    00275     int operator/(
    00276       const PTimeInterval & smaller
    00277     ) const;
    00278
    00284     PTimeInterval operator/(
    00285       int factor
    00286     ) const;
    00287
    00293     PTimeInterval & operator/=(
    00294       int factor
    00295     );
    00297
    00307     bool operator==(
    00308       const PTimeInterval & interval
    00309     ) const;
    00310     bool operator==(
    00311       long msecs
    00312     ) const;
    00313
    00321     bool operator!=(
    00322       const PTimeInterval & interval
    00323     ) const;
    00324     bool operator!=(
    00325       long msecs
    00326     ) const;
    00327
    00335     bool operator> (
    00336       const PTimeInterval & interval
    00337     ) const;
    00338     bool operator> (
    00339       long msecs
    00340     ) const;
    00341
    00349     bool operator>=(
    00350       const PTimeInterval & interval
    00351     ) const;
    00352     bool operator>=(
    00353       long msecs
    00354     ) const;
    00355
    00363     bool operator< (
    00364       const PTimeInterval & interval
    00365     ) const;
    00366     bool operator< (
    00367       long msecs
    00368     ) const;
    00369
    00377     bool operator<=(
    00378       const PTimeInterval & interval
    00379     ) const;
    00380     bool operator<=(
    00381       long msecs
    00382     ) const;
    00384
    00385   private:
    00386   // Member variables
    00388     PInt64 m_milliseconds;
    00389
    00390
    00391 // Include platform dependent part of class
    00392 #ifdef _WIN32
    00393 #include "msos/ptlib/timeint.h"
    00394 #else
    00395 #include "unix/ptlib/timeint.h"
    00396 #endif
    00397 };
    00398
    00399 #endif // PTLIB_TIMEINTERVAL_H
    00400
    00401
    00402 // End Of File ///////////////////////////////////////////////////////////////