@@ -50,7 +50,7 @@ inline void piMSleep(double msecs) {piUSleep(int(msecs * 1000.));} // on !Window
//! \~russian Точно ожидает "secs" секунд
//! ~\details
//! \~english This function exec \a piUSleep (msecs * 1000000)
//! \~russianЭто т метод вызывает \a piUSleep (msecs * 1000000)
//! \~russian Этот метод вызывает \a piUSleep (msecs * 1000000)
inline void piSleep ( double secs ) { piUSleep ( int ( secs * 1000000. ) ) ; } // on !Windows consider constant "usleep" offset
//! \~english Shortest available on current system sleep
@@ -62,112 +62,147 @@ inline void piMinSleep() {piMSleep(PIP_MIN_MSLEEP);}
class PIP_EXPORT PISystemTime {
public :
//! Contructs system time with s = n s = 0
//! \~english Contructs time with seconds and nanosecond s = 0
//! \~russian Создает время с секундами и наносекундами = 0
PISystemTime ( ) { seconds = nanoseconds = 0 ; }
//! Contructs system time with s = "s" and ns = "ns"
//! \~english Contructs time with "s" seconds and "ns" nanoseconds
//! \~russian Создает время с секундами "s" и наносекундами "ns"
PISystemTime ( int s , int ns ) { seconds = s ; nanoseconds = ns ; checkOverflows ( ) ; }
//! Returns stored system time value in seconds
//! \~english Returns time value in seconds
//! \~russian Возвращает значение времени в секундах
double toSeconds ( ) const { return double ( seconds ) + nanoseconds / 1.e+9 ; }
//! Returns stored system time value in milliseconds
//! \~english Returns time value in milliseconds
//! \~russian Возвращает значение времени в миллисекундах
double toMilliseconds ( ) const { return seconds * 1.e+3 + nanoseconds / 1.e+6 ; }
//! Returns stored system time value in microseconds
//! \~english Returns time value in microseconds
//! \~russian Возвращает значение времени в микросекундах
double toMicroseconds ( ) const { return seconds * 1.e+6 + nanoseconds / 1.e+3 ; }
//! Returns stored system time value in nanoseconds
//! \~english Returns time value in nanoseconds
//! \~russian Возвращает значение времени в наносекундах
double toNanoseconds ( ) const { return seconds * 1.e+9 + double ( nanoseconds ) ; }
//! Add to stored system time "v" seconds
//! \~english Add to time "v" seconds
//! \~russian Добавляет ко времени "v" секунд
PISystemTime & addSeconds ( double v ) { * this + = fromSeconds ( v ) ; return * this ; }
//! Add to stored system time "v" milliseconds
//! \~english Add to time "v" milliseconds
//! \~russian Добавляет ко времени "v" миллисекунд
PISystemTime & addMilliseconds ( double v ) { * this + = fromMilliseconds ( v ) ; return * this ; }
//! Add to stored system time "v" microseconds
//! \~english Add to time "v" microseconds
//! \~russian Добавляет ко времени "v" микросекунд
PISystemTime & addMicroseconds ( double v ) { * this + = fromMicroseconds ( v ) ; return * this ; }
//! Add to stored system time "v" nanoseconds
//! \~english Add to time "v" nanoseconds
//! \~russian Добавляет ко времени "v" наносекунд
PISystemTime & addNanoseconds ( double v ) { * this + = fromNanoseconds ( v ) ; return * this ; }
//! 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 with \a PISystemTime::current() thread will be sleep almost forever.
//! \~english
//! \~russian
void sleep ( ) { piUSleep ( piFloord ( toMicroseconds ( ) ) ) ; } // wait self value, useful to wait some dT = (t1 - t0)
//! On U nix system assign current value to timespec struct
void toTimespec ( void * ts ) ;
//! \~english On * nix system assign current value to timespec struct
//! \~russian Н а *nix системах присваивает время к timespec структуре
void toTimespec ( void * ts ) ;
//! Returns copy of this system time with absolutely values of s and ns
//! \~english Returns copy of this time with absolutely values of s and ns
//! \~russian Возвращает копию времени с модулем значения
PISystemTime abs ( ) const ;
//! Returns sum of this system time with "t"
//! \~english Returns sum of this time with "t"
//! \~russian Возвращает сумму этого времени с "t"
PISystemTime operator + ( const PISystemTime & t ) const { PISystemTime tt ( * this ) ; tt . seconds + = t . seconds ; tt . nanoseconds + = t . nanoseconds ; tt . checkOverflows ( ) ; return tt ; }
//! Returns difference between this system time and "t"
//! \~english Returns difference between this time and "t"
//! \~russian Возвращает разницу между этим временем и "t"
PISystemTime operator - ( const PISystemTime & t ) const { PISystemTime tt ( * this ) ; tt . seconds - = t . seconds ; tt . nanoseconds - = t . nanoseconds ; tt . checkOverflows ( ) ; return tt ; }
//! Returns multiplication between this system time and "t"
//! \~english Returns multiplication between this time and "t"
//! \~russian Возвращает это временя умноженное на "t"
PISystemTime operator * ( const double & v ) const { return fromMilliseconds ( toMilliseconds ( ) * v ) ; }
//! Returns division between this system time and "t"
//! \~english Returns division between this time and "t"
//! \~russian Возвращает это временя поделённое на "t"
PISystemTime operator / ( const double & v ) const { return fromMilliseconds ( toMilliseconds ( ) / v ) ; }
//! Add to stored value system time "t"
//! \~english Add to time "t"
//! \~russian Добавляет ко времени "t"
PISystemTime & operator + = ( const PISystemTime & t ) { seconds + = t . seconds ; nanoseconds + = t . nanoseconds ; checkOverflows ( ) ; return * this ; }
//! Subtract from stored value system time "t"
//! \~english Subtract from time "t"
//! \~russian Вычитает из времени "t"
PISystemTime & operator - = ( const PISystemTime & t ) { seconds - = t . seconds ; nanoseconds - = t . nanoseconds ; checkOverflows ( ) ; return * this ; }
//! Multiply stored value system time by "v"
//! \~english Multiply time by "v"
//! \~russian Умножает время на "v"
PISystemTime & operator * = ( const double & v ) { * this = fromMilliseconds ( toMilliseconds ( ) * v ) ; return * this ; }
//! Divide stored value system time by "v"
//! \~english Divide time by "v"
//! \~russian Делит время на "v"
PISystemTime & operator / = ( const double & v ) { * this = fromMilliseconds ( toMilliseconds ( ) / v ) ; return * this ; }
//! Compare system times
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator = = ( const PISystemTime & t ) const { return ( ( seconds = = t . seconds ) & & ( nanoseconds = = t . nanoseconds ) ) ; }
//! Compare system times
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator ! = ( const PISystemTime & t ) const { return ( ( seconds ! = t . seconds ) | | ( nanoseconds ! = t . nanoseconds ) ) ; }
//! Compare system times
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator > ( const PISystemTime & t ) const { if ( seconds = = t . seconds ) return nanoseconds > t . nanoseconds ; return seconds > t . seconds ; }
//! Compare system times
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator < ( const PISystemTime & t ) const { if ( seconds = = t . seconds ) return nanoseconds < t . nanoseconds ; return seconds < t . seconds ; }
//! Compare system times
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator > = ( const PISystemTime & t ) const { if ( seconds = = t . seconds ) return nanoseconds > = t . nanoseconds ; return seconds > = t . seconds ; }
//! Compare system times
//! \~english Compare operator
//! \~russian Оператор сравнения
bool operator < = ( const PISystemTime & t ) const { if ( seconds = = t . seconds ) return nanoseconds < = t . nanoseconds ; return seconds < = t . seconds ; }
//! Contructs system time from seconds "v"
//! \~english Contructs time from seconds "v"
//! \~russian Создает время из "v" секунд
static PISystemTime fromSeconds ( double v ) { int s = piFloord ( v ) ; return PISystemTime ( s , int ( ( v - s ) * 1000000000. ) ) ; }
//! Contructs system time from milliseconds "v"
//! \~english Contructs time from milliseconds "v"
//! \~russian Создает время из "v" миллисекунд
static PISystemTime fromMilliseconds ( double v ) { int s = piFloord ( v / 1000. ) ; return PISystemTime ( s , int ( ( v / 1000. - s ) * 1000000000. ) ) ; }
//! Contructs system time from microseconds "v"
//! \~english Contructs time from microseconds "v"
//! \~russian Создает время из "v" микросекунд
static PISystemTime fromMicroseconds ( double v ) { int s = piFloord ( v / 1000000. ) ; return PISystemTime ( s , int ( ( v / 1000000. - s ) * 1000000000. ) ) ; }
//! Contructs system time from nanoseconds "v"
//! \~english Contructs time from nanoseconds "v"
//! \~russian Создает время из "v" наносекунд
static PISystemTime fromNanoseconds ( double v ) { int s = piFloord ( v / 1000000000. ) ; return PISystemTime ( s , int ( ( v / 1000000000. - s ) * 1000000000. ) ) ; }
//! Returns current system time
//! \~english Returns current system time
//! \~russian Возвращает текущее системное время
static PISystemTime current ( bool precise_but_not_system = false ) ;
//! Seconds of stored system time
//! \~english Seconds time part
//! \~russian Секунды времени
int seconds ;
//! Nanoseconds of stored system time
//! \~english Nanoseconds time part
//! \~russian Наносекунды времени
int nanoseconds ;
private :
@@ -175,7 +210,9 @@ private:
} ;
//! \relatesalso PICout \brief Output operator to PICout
//! \relatesalso PICout
//! \~english \brief Output operator to PICout
//! \~russian \brief Оператор вывода в PICout
inline PICout operator < < ( PICout s , const PISystemTime & v ) { s . space ( ) ; s . setControl ( 0 , true ) ; s < < " ( " < < v . seconds < < " s, " < < v . nanoseconds < < " ns) " ; s . restoreControl ( ) ; return s ; }
@@ -199,7 +236,9 @@ inline bool operator !=(const PITime & t0, const PITime & t1) {return !(t0 == t1
inline bool operator < = ( const PITime & t0 , const PITime & t1 ) { return ! ( t0 > t1 ) ; }
inline bool operator > = ( const PITime & t0 , const PITime & t1 ) { return ! ( t0 < t1 ) ; }
//! \relatesalso PICout \brief Output operator to PICout
//! \relatesalso PICout
//! \~english \brief Output operator to PICout
//! \~russian \brief Оператор вывода в PICout
PIP_EXPORT PICout operator < < ( PICout s , const PITime & v ) ;
@@ -221,7 +260,9 @@ inline bool operator !=(const PIDate & t0, const PIDate & t1) {return !(t0 == t1
inline bool operator < = ( const PIDate & t0 , const PIDate & t1 ) { return ! ( t0 > t1 ) ; }
inline bool operator > = ( const PIDate & t0 , const PIDate & t1 ) { return ! ( t0 < t1 ) ; }
//! \relatesalso PICout \brief Output operator to PICout
//! \relatesalso PICout
//! \~english \brief Output operator to PICout
//! \~russian \brief Оператор вывода в PICout
PIP_EXPORT PICout operator < < ( PICout s , const PIDate & v ) ;
@@ -266,7 +307,9 @@ inline bool operator >=(const PIDateTime & t0, const PIDateTime & t1) {return !(
inline PIByteArray & operator < < ( PIByteArray & s , const PIDateTime & v ) { s < < v . year < < v . month < < v . day < < v . hours < < v . minutes < < v . seconds < < v . milliseconds ; return s ; }
inline PIByteArray & operator > > ( PIByteArray & s , PIDateTime & v ) { s > > v . year > > v . month > > v . day > > v . hours > > v . minutes > > v . seconds > > v . milliseconds ; return s ; }
//! \relatesalso PICout \brief Output operator to PICout
//! \relatesalso PICout
//! \~english \brief Output operator to PICout
//! \~russian \brief Оператор вывода в PICout
PIP_EXPORT PICout operator < < ( PICout s , const PIDateTime & v ) ;