Go to the documentation of this file.00001
00002
00003
00004
00005 #include "ace/Truncate.h"
00006
00007 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00008
00009
00010 ACE_INLINE
00011 ACE_Time_Value::operator timeval () const
00012 {
00013
00014 #if defined (ACE_HAS_TIME_T_LONG_MISMATCH)
00015
00016 ACE_Time_Value *me = const_cast<ACE_Time_Value*> (this);
00017 me->ext_tv_.tv_sec = ACE_Utils::truncate_cast<long> (this->tv_.tv_sec);
00018 me->ext_tv_.tv_usec = ACE_Utils::truncate_cast<long> (this->tv_.tv_usec);
00019 return this->ext_tv_;
00020 #else
00021 return this->tv_;
00022 #endif
00023 }
00024
00025 ACE_INLINE void
00026 ACE_Time_Value::set (const timeval &tv)
00027 {
00028
00029 this->tv_.tv_sec = tv.tv_sec;
00030 this->tv_.tv_usec = tv.tv_usec;
00031
00032 this->normalize ();
00033 }
00034
00035 ACE_INLINE
00036 ACE_Time_Value::ACE_Time_Value (const struct timeval &tv)
00037 {
00038
00039 this->set (tv);
00040 }
00041
00042 ACE_INLINE
00043 ACE_Time_Value::operator const timeval * () const
00044 {
00045
00046 #if defined (ACE_HAS_TIME_T_LONG_MISMATCH)
00047
00048 ACE_Time_Value *me = const_cast<ACE_Time_Value*> (this);
00049 me->ext_tv_.tv_sec = ACE_Utils::truncate_cast<long> (this->tv_.tv_sec);
00050 me->ext_tv_.tv_usec = ACE_Utils::truncate_cast<long> (this->tv_.tv_usec);
00051 return (const timeval *) &this->ext_tv_;
00052 #else
00053 return (const timeval *) &this->tv_;
00054 #endif
00055 }
00056
00057 ACE_INLINE void
00058 ACE_Time_Value::set (time_t sec, suseconds_t usec)
00059 {
00060
00061 # if defined (_WIN32_WCE) && (_WIN32_WCE == 0x600) && !defined (_USE_32BIT_TIME_T) && defined (_MSC_VER)
00062
00063
00064
00065
00066
00067 # pragma warning (push)
00068 # pragma warning (disable: 4244)
00069 # endif
00070 this->tv_.tv_sec = sec;
00071 # if defined (_WIN32_WCE) && (_WIN32_WCE == 0x600) && !defined (_USE_32BIT_TIME_T) && defined (_MSC_VER)
00072 # pragma warning (pop)
00073 # endif
00074 this->tv_.tv_usec = usec;
00075 #if __GNUC__
00076 if (__builtin_constant_p(sec) &&
00077 __builtin_constant_p(usec) &&
00078 (sec >= 0 && usec >= 0 && usec < ACE_ONE_SECOND_IN_USECS))
00079 return;
00080 #endif
00081 this->normalize ();
00082 }
00083
00084 ACE_INLINE void
00085 ACE_Time_Value::set (double d)
00086 {
00087
00088 long l = (long) d;
00089 this->tv_.tv_sec = l;
00090 this->tv_.tv_usec = (suseconds_t) ((d - (double) l) * ACE_ONE_SECOND_IN_USECS + .5);
00091 this->normalize ();
00092 }
00093
00094
00095
00096
00097 ACE_INLINE void
00098 ACE_Time_Value::set (const timespec_t &tv)
00099 {
00100
00101
00102 this->set (tv.tv_sec,
00103 tv.tv_nsec / 1000);
00104 }
00105
00106 ACE_INLINE
00107 ACE_Time_Value::ACE_Time_Value (void)
00108
00109 {
00110
00111 this->set (0, 0);
00112 }
00113
00114 ACE_INLINE
00115 ACE_Time_Value::ACE_Time_Value (time_t sec, suseconds_t usec)
00116 {
00117
00118 this->set (sec, usec);
00119 }
00120
00121
00122 ACE_INLINE time_t
00123 ACE_Time_Value::sec (void) const
00124 {
00125
00126 return this->tv_.tv_sec;
00127 }
00128
00129
00130 ACE_INLINE void
00131 ACE_Time_Value::sec (time_t sec)
00132 {
00133
00134 this->tv_.tv_sec = ACE_Utils::truncate_cast<long> (sec);
00135 }
00136
00137
00138 ACE_INLINE unsigned long
00139 ACE_Time_Value::msec (void) const
00140 {
00141
00142
00143
00144
00145
00146 time_t secs = this->tv_.tv_sec * 1000 + this->tv_.tv_usec / 1000;
00147 return ACE_Utils::truncate_cast<unsigned long> (secs);
00148 }
00149
00150 ACE_INLINE ACE_UINT64
00151 ACE_Time_Value::get_msec () const
00152 {
00153
00154 ACE_UINT64 ms = ACE_Utils::truncate_cast<ACE_UINT64> (this->tv_.tv_sec);
00155 ms *= 1000;
00156 ms += (this->tv_.tv_usec / 1000);
00157 return ms;
00158 }
00159
00160 ACE_INLINE void
00161 ACE_Time_Value::msec (ACE_UINT64 &ms) const
00162 {
00163
00164 ms = this->get_msec ();
00165 }
00166
00167 ACE_INLINE void
00168 ACE_Time_Value::msec (ACE_UINT64 &ms)
00169 {
00170
00171 const ACE_Time_Value *tv = this;
00172 tv->msec (ms);
00173 }
00174
00175 ACE_INLINE void
00176 ACE_Time_Value::set_msec (const ACE_UINT64 &ms)
00177 {
00178
00179
00180 ACE_UINT64 secs = ms / 1000;
00181 this->tv_.tv_sec = static_cast<long> (secs);
00182
00183 this->tv_.tv_usec = static_cast<long>((ms - (secs * 1000)) * 1000);
00184 }
00185
00186
00187 ACE_INLINE void
00188 ACE_Time_Value::msec (long milliseconds)
00189 {
00190
00191
00192 long secs = milliseconds / 1000;
00193 this->tv_.tv_sec = secs;
00194
00195 this->tv_.tv_usec = (milliseconds - (secs * 1000)) * 1000;
00196 }
00197
00198
00199 ACE_INLINE void
00200 ACE_Time_Value::msec (int milliseconds)
00201 {
00202 ACE_Time_Value::msec (static_cast<long> (milliseconds));
00203 }
00204
00205
00206 ACE_INLINE suseconds_t
00207 ACE_Time_Value::usec (void) const
00208 {
00209
00210 return this->tv_.tv_usec;
00211 }
00212
00213
00214 ACE_INLINE void
00215 ACE_Time_Value::usec (suseconds_t usec)
00216 {
00217
00218 this->tv_.tv_usec = usec;
00219 }
00220
00221 ACE_INLINE void
00222 ACE_Time_Value::to_usec (ACE_UINT64 & usec) const
00223 {
00224
00225
00226 #if defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00227 usec = ACE_U_LongLong (static_cast<long long> (this->tv_.tv_sec));
00228 #elif defined (ACE_LACKS_LONGLONG_T)
00229
00230 usec = ACE_U_LongLong (this->tv_.tv_sec);
00231 #else
00232 usec = static_cast<ACE_UINT64> (this->tv_.tv_sec);
00233 #endif
00234 usec *= 1000000;
00235 usec += this->tv_.tv_usec;
00236 }
00237
00238 ACE_INLINE ACE_Time_Value
00239 operator * (double d, const ACE_Time_Value &tv)
00240 {
00241 return ACE_Time_Value (tv) *= d;
00242 }
00243
00244 ACE_INLINE ACE_Time_Value
00245 operator * (const ACE_Time_Value &tv, double d)
00246 {
00247 return ACE_Time_Value (tv) *= d;
00248 }
00249
00250
00251 ACE_INLINE bool
00252 operator > (const ACE_Time_Value &tv1,
00253 const ACE_Time_Value &tv2)
00254 {
00255
00256 if (tv1.sec () > tv2.sec ())
00257 return 1;
00258 else if (tv1.sec () == tv2.sec ()
00259 && tv1.usec () > tv2.usec ())
00260 return 1;
00261 else
00262 return 0;
00263 }
00264
00265
00266 ACE_INLINE bool
00267 operator >= (const ACE_Time_Value &tv1,
00268 const ACE_Time_Value &tv2)
00269 {
00270
00271 if (tv1.sec () > tv2.sec ())
00272 return 1;
00273 else if (tv1.sec () == tv2.sec ()
00274 && tv1.usec () >= tv2.usec ())
00275 return 1;
00276 else
00277 return 0;
00278 }
00279
00280
00281 ACE_INLINE
00282 ACE_Time_Value::operator timespec_t () const
00283 {
00284
00285 timespec_t tv;
00286 tv.tv_sec = this->sec ();
00287
00288 tv.tv_nsec = this->tv_.tv_usec * 1000;
00289 return tv;
00290 }
00291
00292
00293 ACE_INLINE
00294 ACE_Time_Value::ACE_Time_Value (const timespec_t &tv)
00295
00296 {
00297
00298 this->set (tv);
00299 }
00300
00301
00302 ACE_INLINE bool
00303 operator < (const ACE_Time_Value &tv1,
00304 const ACE_Time_Value &tv2)
00305 {
00306
00307 return tv2 > tv1;
00308 }
00309
00310
00311 ACE_INLINE bool
00312 operator <= (const ACE_Time_Value &tv1,
00313 const ACE_Time_Value &tv2)
00314 {
00315
00316 return tv2 >= tv1;
00317 }
00318
00319
00320 ACE_INLINE bool
00321 operator == (const ACE_Time_Value &tv1,
00322 const ACE_Time_Value &tv2)
00323 {
00324
00325 return tv1.sec () == tv2.sec ()
00326 && tv1.usec () == tv2.usec ();
00327 }
00328
00329
00330 ACE_INLINE bool
00331 operator != (const ACE_Time_Value &tv1,
00332 const ACE_Time_Value &tv2)
00333 {
00334
00335 return !(tv1 == tv2);
00336 }
00337
00338
00339 ACE_INLINE ACE_Time_Value &
00340 ACE_Time_Value::operator+= (const ACE_Time_Value &tv)
00341 {
00342
00343 this->sec (this->sec () + tv.sec ());
00344 this->usec (this->usec () + tv.usec ());
00345 this->normalize ();
00346 return *this;
00347 }
00348
00349 ACE_INLINE ACE_Time_Value &
00350 ACE_Time_Value::operator+= (time_t tv)
00351 {
00352
00353 this->sec (this->sec () + tv);
00354 return *this;
00355 }
00356
00357 ACE_INLINE ACE_Time_Value &
00358 ACE_Time_Value::operator= (const ACE_Time_Value &tv)
00359 {
00360
00361 this->sec (tv.sec ());
00362 this->usec (tv.usec ());
00363 return *this;
00364 }
00365
00366 ACE_INLINE ACE_Time_Value &
00367 ACE_Time_Value::operator= (time_t tv)
00368 {
00369
00370 this->sec (tv);
00371 this->usec (0);
00372 return *this;
00373 }
00374
00375
00376 ACE_INLINE ACE_Time_Value &
00377 ACE_Time_Value::operator-= (const ACE_Time_Value &tv)
00378 {
00379
00380 this->sec (this->sec () - tv.sec ());
00381 this->usec (this->usec () - tv.usec ());
00382 this->normalize ();
00383 return *this;
00384 }
00385
00386 ACE_INLINE ACE_Time_Value &
00387 ACE_Time_Value::operator-= (time_t tv)
00388 {
00389
00390 this->sec (this->sec () - tv);
00391 return *this;
00392 }
00393
00394
00395 ACE_INLINE ACE_Time_Value
00396 operator + (const ACE_Time_Value &tv1,
00397 const ACE_Time_Value &tv2)
00398 {
00399
00400 ACE_Time_Value sum (tv1);
00401 sum += tv2;
00402
00403 return sum;
00404 }
00405
00406
00407 ACE_INLINE ACE_Time_Value
00408 operator - (const ACE_Time_Value &tv1,
00409 const ACE_Time_Value &tv2)
00410 {
00411
00412 ACE_Time_Value delta (tv1);
00413 delta -= tv2;
00414
00415 return delta;
00416 }
00417
00418 ACE_END_VERSIONED_NAMESPACE_DECL