timeint.h
Go to the documentation of this file.
/*
* timeint.h
*
* Millisecond resolution time interval class (uses 64 bit integers).
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_TIMEINTERVAL_H
#define PTLIB_TIMEINTERVAL_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
// Difference between two system times
class PTimeInterval : public PObject
{
PCLASSINFO(PTimeInterval, PObject);
public:
PTimeInterval(
PInt64 millisecs = 0
);
PTimeInterval(
long millisecs,
long seconds,
long minutes = 0,
long hours = 0,
int days = 0
);
PTimeInterval(
const PString & str
);
PObject * Clone() const;
virtual Comparison Compare(
const PObject & obj
) const;
virtual void PrintOn(
ostream & strm
) const;
virtual void ReadFrom(
istream & strm
);
enum Formats {
NormalFormat,
IncludeDays,
SecondsOnly
};
PString AsString(
int decimals = 3,
Formats format = NormalFormat,
int width = 1
) const;
virtual PInt64 GetMilliSeconds() const;
virtual void SetMilliSeconds(PInt64 msecs);
long GetSeconds() const;
long GetMinutes() const;
int GetHours() const;
int GetDays() const;
DWORD GetInterval() const;
virtual void SetInterval(
PInt64 milliseconds = 0,
long seconds = 0,
long minutes = 0,
long hours = 0,
int days = 0
);
PTimeInterval operator-() const;
PTimeInterval operator+(
const PTimeInterval & interval
) const;
PTimeInterval & operator+=(
const PTimeInterval & interval
);
PTimeInterval operator-(
const PTimeInterval & interval
) const;
PTimeInterval & operator-=(
const PTimeInterval & interval
);
PTimeInterval operator*(
int factor
) const;
PTimeInterval & operator*=(
int factor
);
int operator/(
const PTimeInterval & smaller
) const;
PTimeInterval operator/(
int factor
) const;
PTimeInterval & operator/=(
int factor
);
bool operator==(
const PTimeInterval & interval
) const;
bool operator==(
long msecs
) const;
bool operator!=(
const PTimeInterval & interval
) const;
bool operator!=(
long msecs
) const;
bool operator> (
const PTimeInterval & interval
) const;
bool operator> (
long msecs
) const;
bool operator>=(
const PTimeInterval & interval
) const;
bool operator>=(
long msecs
) const;
bool operator< (
const PTimeInterval & interval
) const;
bool operator< (
long msecs
) const;
bool operator<=(
const PTimeInterval & interval
) const;
bool operator<=(
long msecs
) const;
private:
// Member variables
PInt64 m_milliseconds;
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/timeint.h"
#else
#include "unix/ptlib/timeint.h"
#endif
};
#endif // PTLIB_TIMEINTERVAL_H
// End Of File ///////////////////////////////////////////////////////////////
PTimeInterval::NormalFormat
Definition: timeint.h:127
PTimeInterval::operator-
PTimeInterval operator-() const
Unary minus, get negative of time interval.
PTimeInterval::operator+
PTimeInterval operator+(const PTimeInterval &interval) const
Add the two time intervals yielding a third time interval.
PTimeInterval
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
PTimeInterval::operator*
PTimeInterval operator*(int factor) const
Multiply the time interval by a factor yielding a third time interval.
PTimeInterval::ReadFrom
virtual void ReadFrom(istream &strm)
Input the time interval from the I/O stream.
PObject::Comparison
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
PTimeInterval::operator<=
bool operator<=(const PTimeInterval &interval) const
Compare to the two time intervals.
PTimeInterval::Compare
virtual Comparison Compare(const PObject &obj) const
Rank the two time intervals.
PTimeInterval::operator-=
PTimeInterval & operator-=(const PTimeInterval &interval)
Subtract the second time interval from the first time interval.
PTimeInterval::operator!=
bool operator!=(const PTimeInterval &interval) const
Compare to the two time intervals.
PTimeInterval::Formats
Formats
Definition: timeint.h:126
PTimeInterval::GetMilliSeconds
virtual PInt64 GetMilliSeconds() const
Get the number of milliseconds for the time interval.
PTimeInterval::operator==
bool operator==(const PTimeInterval &interval) const
Compare to the two time intervals.
PTimeInterval::PTimeInterval
PTimeInterval(PInt64 millisecs=0)
Create a new time interval object.
PTimeInterval::operator/=
PTimeInterval & operator/=(int factor)
Divide the time interval by a factor.
PTimeInterval::SetMilliSeconds
virtual void SetMilliSeconds(PInt64 msecs)
Set the number of milliseconds for the time interval.
PTimeInterval::operator+=
PTimeInterval & operator+=(const PTimeInterval &interval)
Add the second time interval to the first time interval.
PString
The character string class.
Definition: pstring.h:108
PTimeInterval::SecondsOnly
Definition: timeint.h:129
PTimeInterval::PrintOn
virtual void PrintOn(ostream &strm) const
Output the time interval to the I/O stream.
PTimeInterval::SetInterval
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.
PTimeInterval::operator>
bool operator>(const PTimeInterval &interval) const
Compare to the two time intervals.
PTimeInterval::IncludeDays
Definition: timeint.h:128
PTimeInterval::GetInterval
DWORD GetInterval() const
Get the number of milliseconds for the time interval.
PTimeInterval::GetMinutes
long GetMinutes() const
Get the number of whole minutes for the time interval.
PTimeInterval::operator>=
bool operator>=(const PTimeInterval &interval) const
Compare to the two time intervals.
PTimeInterval::GetSeconds
long GetSeconds() const
Get the number of whole seconds for the time interval.
PTimeInterval::operator<
bool operator<(const PTimeInterval &interval) const
Compare to the two time intervals.
PTimeInterval::operator/
int operator/(const PTimeInterval &smaller) const
Divide the time interval by another interval yielding a count.
PTimeInterval::GetDays
int GetDays() const
Get the number of whole days for the time interval.
PTimeInterval::GetHours
int GetHours() const
Get the number of whole hours for the time interval.
PTimeInterval::Clone
PObject * Clone() const
Create a new copy of the time interval.
PTimeInterval::operator*=
PTimeInterval & operator*=(int factor)
Multiply the time interval by a factor.
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PTimeInterval::AsString
PString AsString(int decimals=3, Formats format=NormalFormat, int width=1) const