PTLib
Version 2.18.8
|
This class defines an arbitrary time interval to millisecond accuracy. More...
#include <timeint.h>
Public Member Functions | |
Overrides from class PObject | |
PObject * | Clone () const |
Create a new copy of the time interval. More... | |
virtual Comparison | Compare (const PObject &obj) const |
Rank the two time intervals. More... | |
virtual void | PrintOn (ostream &strm) const |
Output the time interval to the I/O stream. More... | |
virtual void | ReadFrom (istream &strm) |
Input the time interval from the I/O stream. More... | |
Comparison functions | |
bool | operator== (const PTimeInterval &interval) const |
Compare to the two time intervals. More... | |
bool | operator== (long msecs) const |
bool | operator!= (const PTimeInterval &interval) const |
Compare to the two time intervals. More... | |
bool | operator!= (long msecs) const |
bool | operator> (const PTimeInterval &interval) const |
Compare to the two time intervals. More... | |
bool | operator> (long msecs) const |
bool | operator>= (const PTimeInterval &interval) const |
Compare to the two time intervals. More... | |
bool | operator>= (long msecs) const |
bool | operator< (const PTimeInterval &interval) const |
Compare to the two time intervals. More... | |
bool | operator< (long msecs) const |
bool | operator<= (const PTimeInterval &interval) const |
Compare to the two time intervals. More... | |
bool | operator<= (long msecs) const |
![]() | |
__inline unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
__inline void | SetTraceContextIdentifier (unsigned id) |
__inline void | SetTraceContextIdentifier (const PObject &obj) |
__inline void | SetTraceContextIdentifier (const PObject *obj) |
__inline void | CopyTraceContextIdentifier (PObject &obj) const |
__inline void | CopyTraceContextIdentifier (PObject *obj) const |
virtual | ~PObject () |
__inline const char * | GetClass () const |
__inline bool | IsClass (const char *name) const |
__inline const PObject * | PTraceObjectInstance () const |
template<class CLS > | |
CLS * | CloneAs () const |
As for Clone() but converts to specified type. More... | |
virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. More... | |
bool | operator== (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator< (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator> (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. More... | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. More... | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. More... | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. More... | |
Static Public Attributes | |
static int64_t const | MicroToNano = 1000 |
static int64_t const | MilliToNano = MicroToNano*1000 |
static int64_t const | SecsToNano = MilliToNano*1000 |
static int64_t const | MinsToNano = SecsToNano*60 |
static int64_t const | HoursToNano = MinsToNano*60 |
static int64_t const | DaysToNano = HoursToNano*24 |
Protected Member Functions | |
virtual int64_t | InternalGet () const |
virtual void | InternalSet (int64_t t) |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. More... | |
Construction | |
PTimeInterval (PInt64 millisecs=0) | |
Create a new time interval object. More... | |
PTimeInterval (PInt64 millisecs, long seconds, long minutes=0, long hours=0, int days=0) | |
PTimeInterval (const PString &str) | |
PTimeInterval (const PTimeInterval &other) | |
PTimeInterval & | operator= (const PTimeInterval &other) |
static PTimeInterval | NanoSeconds (int64_t nsecs, int secs=0) |
Return a PTimeInterval in nanoseconds. More... | |
static PTimeInterval | MicroSeconds (int64_t usecs, int secs=0) |
Return a PTimeInterval in microseconds. More... | |
static PTimeInterval | Seconds (double secs) |
Return a PTimeInterval in seconds. More... | |
static PTimeInterval | Frequency (double frequency) |
Return a PTimeInterval from a frequency. More... | |
Conversion functions | |
enum | Formats { NormalFormat, IncludeDays, SecondsOnly, SecondsSI } |
PString | AsString (int decimals=3, Formats format=NormalFormat, int width=1) const |
Output the time interval as a string. More... | |
Access functions | |
typedef int | IntervalType |
PInt64 | GetNanoSeconds () const |
Get the number of nanoseconds for the time interval. More... | |
void | SetNanoSeconds (int64_t nsecs, int secs=0) |
Set the number of nanoseconds for the time interval. More... | |
PInt64 | GetMicroSeconds () const |
Get the number of microseconds for the time interval. More... | |
void | SetMicroSeconds (int64_t usecs, int secs=0) |
Set the number of microseconds for the time interval. More... | |
double | GetFrequency () const |
Get time interval as a frequency. More... | |
void | SetFrequency (double frequency) |
Set time interval from a frequency. More... | |
PInt64 | GetMilliSeconds () const |
Get the number of milliseconds for the time interval. More... | |
void | SetMilliSeconds (PInt64 msecs) |
Set the number of milliseconds for the time interval. More... | |
long | GetSeconds () const |
Get the number of whole seconds for the time interval. More... | |
double | GetSecondsAsDouble () const |
Get the number of seconds, and partial seconds, as floating point, for the time interval. More... | |
void | SetSeconds (double secs) |
Set the number of seconds for the time interval. More... | |
long | GetMinutes () const |
Get the number of whole minutes for the time interval. More... | |
int | GetHours () const |
Get the number of whole hours for the time interval. More... | |
int | GetDays () const |
Get the number of whole days for the time interval. More... | |
IntervalType | GetInterval () const |
Get the "clamped" number of milliseconds for the time interval. More... | |
void | SetInterval (PInt64 milliseconds=0, long seconds=0, long minutes=0, long hours=0, int days=0) |
Set the value of the time interval. More... | |
Operations | |
PTimeInterval | operator- () const |
Unary minus, get negative of time interval. More... | |
PTimeInterval | operator+ (const PTimeInterval &interval) const |
Add the two time intervals yielding a third time interval. More... | |
PTimeInterval & | operator+= (const PTimeInterval &interval) |
Add the second time interval to the first time interval. More... | |
PTimeInterval | operator- (const PTimeInterval &interval) const |
Subtract the two time intervals yielding a third time interval. More... | |
PTimeInterval & | operator-= (const PTimeInterval &interval) |
Subtract the second time interval from the first time interval. More... | |
PTimeInterval | operator* (int factor) const |
Multiply the time interval by a factor yielding a third time interval. More... | |
PTimeInterval & | operator*= (int factor) |
Multiply the time interval by a factor. More... | |
int | operator/ (const PTimeInterval &smaller) const |
Divide the time interval by another interval yielding a count. More... | |
PTimeInterval | operator/ (int factor) const |
Divide the time interval by a factor yielding a third time interval. More... | |
PTimeInterval & | operator/= (int factor) |
Divide the time interval by a factor. More... | |
PTimeInterval | operator+ (int64_t left, const PTimeInterval &right) |
PTimeInterval | operator- (int64_t left, const PTimeInterval &right) |
PTimeInterval | operator* (int left, const PTimeInterval &right) |
PTimeInterval | operator/ (int64_t left, const PTimeInterval &right) |
Additional Inherited Members | |
![]() | |
enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
![]() | |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
static __inline const char * | Class () |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
template<typename T > | |
static Comparison | Compare2 (T v1, T v2) |
Compare two types, returning Comparison type. More... | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
![]() | |
unsigned | m_traceContextIdentifier |
This class defines an arbitrary time interval to millisecond accuracy.
The interval can be both positive and negative.
A long int is used to store the time interval so it is limited to LONG_MAX (found in the standard C header file limits.h) milliseconds. This is approximately 596 hours for 32 bit integers.
There is a constant, PMaxTimeInterval
which defines the maximum number of milliseconds that a time interval may be.
typedef int PTimeInterval::IntervalType |
PTimeInterval::PTimeInterval | ( | PInt64 | millisecs = 0 | ) |
Create a new time interval object.
The time interval, in milliseconds, is the sum of all of the parameters. For example all of the following are equivalent:
PTimeInterval(120000)
PTimeInterval(60000, 60)
PTimeInterval(60000, 0, 1)
PTimeInterval(0, 60, 1)
PTimeInterval(0, 0, 2)
millisecs | Number of milliseconds for interval. |
PTimeInterval::PTimeInterval | ( | PInt64 | millisecs, |
long | seconds, | ||
long | minutes = 0 , |
||
long | hours = 0 , |
||
int | days = 0 |
||
) |
millisecs | Number of milliseconds for interval. |
seconds | Number of seconds for interval. |
minutes | Number of minutes for interval. |
hours | Number of hours for interval. |
days | Number of days for interval. |
PTimeInterval::PTimeInterval | ( | const PString & | str | ) |
str | String representation of time interval. |
PTimeInterval::PTimeInterval | ( | const PTimeInterval & | other | ) |
PString PTimeInterval::AsString | ( | int | decimals = 3 , |
Formats | format = NormalFormat , |
||
int | width = 1 |
||
) | const |
Output the time interval as a string.
If precision
is <= 0 and format
is NormalFormat then the format used will be IncludeDays, and the positive value for precision
is then used as number of decimals.
decimals | Decimals for milliseconds part |
format | Output format options |
width | Width of output |
|
virtual |
Create a new copy of the time interval.
It is the responsibility of the called to delete the object.
Reimplemented from PObject.
|
virtual |
Rank the two time intervals.
This ranks the intervals as you would expect for two integers.
EqualTo
, LessThan
or GreaterThan
depending on their relative rank. obj | Time interval to compare against. |
Reimplemented from PObject.
|
static |
Return a PTimeInterval from a frequency.
int PTimeInterval::GetDays | ( | ) | const |
Get the number of whole days for the time interval.
double PTimeInterval::GetFrequency | ( | ) | const |
Get time interval as a frequency.
int PTimeInterval::GetHours | ( | ) | const |
Get the number of whole hours for the time interval.
IntervalType PTimeInterval::GetInterval | ( | ) | const |
Get the "clamped" number of milliseconds for the time interval.
This returns an operating system dependent value for use in system calls. For Windows, a value of PMaxTimeInterval returns INFINITE. For unix systems, PMaxTimeInterval returns -1. In both cases a negative value returns zero.
PInt64 PTimeInterval::GetMicroSeconds | ( | ) | const |
Get the number of microseconds for the time interval.
PInt64 PTimeInterval::GetMilliSeconds | ( | ) | const |
Get the number of milliseconds for the time interval.
long PTimeInterval::GetMinutes | ( | ) | const |
Get the number of whole minutes for the time interval.
PInt64 PTimeInterval::GetNanoSeconds | ( | ) | const |
Get the number of nanoseconds for the time interval.
long PTimeInterval::GetSeconds | ( | ) | const |
Get the number of whole seconds for the time interval.
Referenced by PHTTPConnectionInfo::SetPersistenceTimeout().
double PTimeInterval::GetSecondsAsDouble | ( | ) | const |
Get the number of seconds, and partial seconds, as floating point, for the time interval.
|
protectedvirtual |
|
protectedvirtual |
|
static |
Return a PTimeInterval in microseconds.
|
static |
Return a PTimeInterval in nanoseconds.
Referenced by std::numeric_limits< PTimeInterval >::denorm_min(), std::numeric_limits< PTimeInterval >::epsilon(), std::numeric_limits< PTimeInterval >::infinity(), std::numeric_limits< PTimeInterval >::quiet_NaN(), std::numeric_limits< PTimeInterval >::round_error(), and std::numeric_limits< PTimeInterval >::signaling_NaN().
bool PTimeInterval::operator!= | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator!= | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
PTimeInterval PTimeInterval::operator* | ( | int | factor | ) | const |
Multiply the time interval by a factor yielding a third time interval.
factor | factor to multiply. |
PTimeInterval& PTimeInterval::operator*= | ( | int | factor | ) |
Multiply the time interval by a factor.
factor | factor to multiply. |
PTimeInterval PTimeInterval::operator+ | ( | const PTimeInterval & | interval | ) | const |
Add the two time intervals yielding a third time interval.
interval | Time interval to add. |
PTimeInterval& PTimeInterval::operator+= | ( | const PTimeInterval & | interval | ) |
Add the second time interval to the first time interval.
interval | Time interval to add. |
PTimeInterval PTimeInterval::operator- | ( | ) | const |
Unary minus, get negative of time interval.
PTimeInterval PTimeInterval::operator- | ( | const PTimeInterval & | interval | ) | const |
Subtract the two time intervals yielding a third time interval.
interval | Time interval to subtract. |
PTimeInterval& PTimeInterval::operator-= | ( | const PTimeInterval & | interval | ) |
Subtract the second time interval from the first time interval.
interval | Time interval to subtract. |
int PTimeInterval::operator/ | ( | const PTimeInterval & | smaller | ) | const |
Divide the time interval by another interval yielding a count.
smaller | factor to divide. |
PTimeInterval PTimeInterval::operator/ | ( | int | factor | ) | const |
Divide the time interval by a factor yielding a third time interval.
factor | factor to divide. |
PTimeInterval& PTimeInterval::operator/= | ( | int | factor | ) |
Divide the time interval by a factor.
factor | factor to divide. |
bool PTimeInterval::operator< | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator< | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator<= | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator<= | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
PTimeInterval& PTimeInterval::operator= | ( | const PTimeInterval & | other | ) |
bool PTimeInterval::operator== | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator== | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator> | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator> | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
bool PTimeInterval::operator>= | ( | const PTimeInterval & | interval | ) | const |
Compare to the two time intervals.
This is provided as an override to the default in PObject so that comparisons can be made to integer literals that represent milliseconds.
interval | Time interval to compare. |
bool PTimeInterval::operator>= | ( | long | msecs | ) | const |
msecs | Time interval as integer milliseconds to compare. |
|
virtual |
Output the time interval to the I/O stream.
The output is controlled by various stream flags: ios::scientific, ios::showbase Output if < 1 then output SI notation, e.g. "234ms", >1 is as below ios::scientific, ios::noshowbase Output as per a floating point number, e.g. -314.1592 ios::fixed, ios::noshowbase Output as hours/minutes/seconds, e.g. "12:34.567". ios::fixed, ios::showbase Output as days/hours/minutes/seconds, e.g. "2d13:25:47.312141". The strm.precision() is honoured as expected, controlling number of decimals, clamped to 9. A width() greater than needed, with fillchar('0') will also be honoured, e.g. "01:23:56.678901"
strm | I/O stream to output the time interval. |
|
virtual |
Input the time interval from the I/O stream.
This expects the input to be a signed decimal integer number.
strm | I/O stream to input the time interval from. |
|
static |
Return a PTimeInterval in seconds.
void PTimeInterval::SetFrequency | ( | double | frequency | ) |
Set time interval from a frequency.
Referenced by PFrequencyTime::PFrequencyTime().
void PTimeInterval::SetInterval | ( | PInt64 | milliseconds = 0 , |
long | seconds = 0 , |
||
long | minutes = 0 , |
||
long | hours = 0 , |
||
int | days = 0 |
||
) |
Set the value of the time interval.
The time interval, in milliseconds, is the sum of all of the parameters. For example all of the following are equivalent:
SetInterval(120000)
SetInterval(60000, 60)
SetInterval(60000, 0, 1)
SetInterval(0, 60, 1)
SetInterval(0, 0, 2)
milliseconds | Number of milliseconds for interval. |
seconds | Number of seconds for interval. |
minutes | Number of minutes for interval. |
hours | Number of hours for interval. |
days | Number of days for interval. |
void PTimeInterval::SetMicroSeconds | ( | int64_t | usecs, |
int | secs = 0 |
||
) |
Set the number of microseconds for the time interval.
Referenced by PMicroSeconds::PMicroSeconds().
void PTimeInterval::SetMilliSeconds | ( | PInt64 | msecs | ) |
Set the number of milliseconds for the time interval.
void PTimeInterval::SetNanoSeconds | ( | int64_t | nsecs, |
int | secs = 0 |
||
) |
Set the number of nanoseconds for the time interval.
Referenced by PNanoSeconds::PNanoSeconds().
void PTimeInterval::SetSeconds | ( | double | secs | ) |
Set the number of seconds for the time interval.
|
friend |
|
friend |
|
friend |
|
friend |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |