PIP  0.4.0_beta2
Platform-Independent Primitives
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PISystemTime Class Reference

System time. More...

Public Member Functions

 PISystemTime ()
 Contructs system time with s = ns = 0.
 
 PISystemTime (long s, long ns)
 Contructs system time with s = "s" and ns = "ns".
 
 PISystemTime (const PISystemTime &t)
 Contructs system time from another.
 
double toSeconds () const
 Returns stored system time value in seconds.
 
double toMilliseconds () const
 Returns stored system time value in milliseconds.
 
double toMicroseconds () const
 Returns stored system time value in microseconds.
 
double toNanoseconds () const
 Returns stored system time value in nanoseconds.
 
PISystemTimeaddSeconds (double v)
 Add to stored system time "v" seconds.
 
PISystemTimeaddMilliseconds (double v)
 Add to stored system time "v" milliseconds.
 
PISystemTimeaddMicroseconds (double v)
 Add to stored system time "v" microseconds.
 
PISystemTimeaddNanoseconds (double v)
 Add to stored system time "v" nanoseconds.
 
void sleep ()
 
PISystemTime abs () const
 Returns copy of this system time with absolutely values of s and ns.
 
PISystemTime operator+ (const PISystemTime &t)
 Returns sum of this system time with "t".
 
PISystemTime operator- (const PISystemTime &t)
 Returns difference between this system time and "t".
 
PISystemTimeoperator+= (const PISystemTime &t)
 Add to stored value system time "t".
 
PISystemTimeoperator-= (const PISystemTime &t)
 Subtract from stored value system time "t".
 
bool operator== (const PISystemTime &t)
 Compare system times.
 
bool operator!= (const PISystemTime &t)
 Compare system times.
 
bool operator> (const PISystemTime &t)
 Compare system times.
 
bool operator< (const PISystemTime &t)
 Compare system times.
 
bool operator>= (const PISystemTime &t)
 Compare system times.
 
bool operator<= (const PISystemTime &t)
 Compare system times.
 

Static Public Member Functions

static PISystemTime fromSeconds (double v)
 Contructs system time from seconds "v".
 
static PISystemTime fromMilliseconds (double v)
 Contructs system time from milliseconds "v".
 
static PISystemTime fromMicroseconds (double v)
 Contructs system time from microseconds "v".
 
static PISystemTime fromNanoseconds (double v)
 Contructs system time from nanoseconds "v".
 
static PISystemTime current ()
 Returns current system time.
 

Public Attributes

long seconds
 Seconds of stored system time.
 
long nanoseconds
 Nanoseconds of stored system time.
 

Related Functions

(Note that these are not member functions.)

PISystemTime currentSystemTime ()
 Returns current system time.
 

Detailed Description

System time.

Synopsis

This class provide arithmetic functions for POSIX system time. This time represents as seconds and nanosecons in integer formats. You can take current system time with function currentSystemTime(), compare times, sum or subtract two times, convert time to/from seconds, milliseconds, microseconds or nanoseconds.

Example

int main() {
PISystemTime t0; // s = ns = 0
t0.addMilliseconds(200); // s = 0, ns = 200000000
t0.addMilliseconds(900); // s = 1, ns = 100000000
t0 -= PISystemTime::fromSeconds(0.1); // s = 1, ns = 0
t0.sleep(); // sleep for 1 second
piMSleep(500);
(t1 - t0).sleep(); // sleep for 500 milliseconds
return 0;
};

Member Function Documentation

void PISystemTime::sleep ( )
inline

Sleep for stored value.

Warning
Use this function to sleep for difference of system times or constructs system time. If you call this function on system time returned from currentSystemTime() thread will be sleep almost forever.