00001
00002
00003
00004
00005
00006
00007
00008 ACE_INLINE
00009 ACE_Time_Value::operator timeval () const
00010 {
00011
00012 return this->tv_;
00013 }
00014
00015
00016
00017 ACE_INLINE
00018 ACE_Time_Value::operator const timeval * () const
00019 {
00020
00021 return (const timeval *) &this->tv_;
00022 }
00023
00024 ACE_INLINE void
00025 ACE_Time_Value::set (long sec, long usec)
00026 {
00027
00028 this->tv_.tv_sec = sec;
00029 this->tv_.tv_usec = usec;
00030 this->normalize ();
00031 }
00032
00033 ACE_INLINE void
00034 ACE_Time_Value::set (double d)
00035 {
00036
00037 long l = (long) d;
00038 this->tv_.tv_sec = l;
00039 this->tv_.tv_usec = (long) ((d - (double) l) * ACE_ONE_SECOND_IN_USECS);
00040 this->normalize ();
00041 }
00042
00043
00044
00045
00046
00047 ACE_INLINE void
00048 ACE_Time_Value::set (const timespec_t &tv)
00049 {
00050
00051 #if ! defined(ACE_HAS_BROKEN_TIMESPEC_MEMBERS)
00052 this->tv_.tv_sec = ACE_static_cast (long, tv.tv_sec);
00053
00054 this->tv_.tv_usec = tv.tv_nsec / 1000;
00055 #else
00056 this->tv_.tv_sec = tv.ts_sec;
00057
00058 this->tv_.tv_usec = tv.ts_nsec / 1000;
00059 #endif
00060
00061 this->normalize ();
00062 }
00063
00064 ACE_INLINE void
00065 ACE_Time_Value::set (const timeval &tv)
00066 {
00067
00068 this->tv_.tv_sec = tv.tv_sec;
00069 this->tv_.tv_usec = tv.tv_usec;
00070
00071 this->normalize ();
00072 }
00073
00074 ACE_INLINE
00075 ACE_Time_Value::ACE_Time_Value (const struct timeval &tv)
00076
00077 {
00078
00079 this->set (tv);
00080 }
00081
00082 ACE_INLINE
00083 ACE_Time_Value::ACE_Time_Value (void)
00084
00085 {
00086
00087 this->set (0, 0);
00088 }
00089
00090 ACE_INLINE
00091 ACE_Time_Value::ACE_Time_Value (long sec, long usec)
00092 {
00093
00094 this->set (sec, usec);
00095 }
00096
00097
00098
00099 ACE_INLINE long
00100 ACE_Time_Value::sec (void) const
00101 {
00102
00103 return this->tv_.tv_sec;
00104 }
00105
00106
00107
00108 ACE_INLINE void
00109 ACE_Time_Value::sec (long sec)
00110 {
00111
00112 this->tv_.tv_sec = sec;
00113 }
00114
00115
00116
00117 ACE_INLINE long
00118 ACE_Time_Value::msec (void) const
00119 {
00120
00121 return this->tv_.tv_sec * 1000 + this->tv_.tv_usec / 1000;
00122 }
00123
00124
00125
00126 ACE_INLINE void
00127 ACE_Time_Value::msec (long milliseconds)
00128 {
00129
00130
00131 this->tv_.tv_sec = milliseconds / 1000;
00132
00133 this->tv_.tv_usec = (milliseconds - (this->tv_.tv_sec * 1000)) * 1000;
00134 }
00135
00136
00137
00138 ACE_INLINE long
00139 ACE_Time_Value::usec (void) const
00140 {
00141
00142 return this->tv_.tv_usec;
00143 }
00144
00145
00146
00147 ACE_INLINE void
00148 ACE_Time_Value::usec (long usec)
00149 {
00150
00151 this->tv_.tv_usec = usec;
00152 }
00153
00154 ACE_INLINE ACE_Time_Value &
00155 ACE_Time_Value::operator *= (double d)
00156 {
00157 double time =
00158 ((double) this->sec ()) * ACE_ONE_SECOND_IN_USECS + this->usec ();
00159 time *= d;
00160 this->sec ((long)(time / ACE_ONE_SECOND_IN_USECS));
00161 this->usec (((long)time) % ACE_ONE_SECOND_IN_USECS);
00162 this->normalize ();
00163 return *this;
00164 }
00165
00166 ACE_INLINE ACE_Time_Value
00167 operator * (double d, const ACE_Time_Value &tv)
00168 {
00169 return ACE_Time_Value (tv) *= d;
00170 }
00171
00172 ACE_INLINE ACE_Time_Value
00173 operator * (const ACE_Time_Value &tv, double d)
00174 {
00175 return ACE_Time_Value (tv) *= d;
00176 }
00177
00178
00179
00180 ACE_INLINE int
00181 operator > (const ACE_Time_Value &tv1,
00182 const ACE_Time_Value &tv2)
00183 {
00184
00185 if (tv1.sec () > tv2.sec ())
00186 return 1;
00187 else if (tv1.sec () == tv2.sec ()
00188 && tv1.usec () > tv2.usec ())
00189 return 1;
00190 else
00191 return 0;
00192 }
00193
00194
00195
00196 ACE_INLINE int
00197 operator >= (const ACE_Time_Value &tv1,
00198 const ACE_Time_Value &tv2)
00199 {
00200
00201 if (tv1.sec () > tv2.sec ())
00202 return 1;
00203 else if (tv1.sec () == tv2.sec ()
00204 && tv1.usec () >= tv2.usec ())
00205 return 1;
00206 else
00207 return 0;
00208 }
00209
00210
00211
00212 ACE_INLINE
00213 ACE_Time_Value::operator timespec_t () const
00214 {
00215
00216 timespec_t tv;
00217 #if ! defined(ACE_HAS_BROKEN_TIMESPEC_MEMBERS)
00218 tv.tv_sec = this->sec ();
00219
00220 tv.tv_nsec = this->tv_.tv_usec * 1000;
00221 #else
00222 tv.ts_sec = this->sec ();
00223
00224 tv.ts_nsec = this->tv_.tv_usec * 1000;
00225 #endif
00226 return tv;
00227 }
00228
00229
00230
00231 ACE_INLINE
00232 ACE_Time_Value::ACE_Time_Value (const timespec_t &tv)
00233
00234 {
00235
00236 this->set (tv);
00237 }
00238
00239
00240
00241 ACE_INLINE int
00242 operator < (const ACE_Time_Value &tv1,
00243 const ACE_Time_Value &tv2)
00244 {
00245
00246 return tv2 > tv1;
00247 }
00248
00249
00250
00251 ACE_INLINE int
00252 operator <= (const ACE_Time_Value &tv1,
00253 const ACE_Time_Value &tv2)
00254 {
00255
00256 return tv2 >= tv1;
00257 }
00258
00259
00260
00261 ACE_INLINE int
00262 operator == (const ACE_Time_Value &tv1,
00263 const ACE_Time_Value &tv2)
00264 {
00265
00266 return tv1.sec () == tv2.sec ()
00267 && tv1.usec () == tv2.usec ();
00268 }
00269
00270
00271
00272 ACE_INLINE int
00273 operator != (const ACE_Time_Value &tv1,
00274 const ACE_Time_Value &tv2)
00275 {
00276
00277 return !(tv1 == tv2);
00278 }
00279
00280
00281
00282 ACE_INLINE ACE_Time_Value &
00283 ACE_Time_Value::operator+= (const ACE_Time_Value &tv)
00284 {
00285
00286 this->sec (this->sec () + tv.sec ());
00287 this->usec (this->usec () + tv.usec ());
00288 this->normalize ();
00289 return *this;
00290 }
00291
00292
00293
00294 ACE_INLINE ACE_Time_Value &
00295 ACE_Time_Value::operator-= (const ACE_Time_Value &tv)
00296 {
00297
00298 this->sec (this->sec () - tv.sec ());
00299 this->usec (this->usec () - tv.usec ());
00300 this->normalize ();
00301 return *this;
00302 }
00303
00304
00305
00306 ACE_INLINE ACE_Time_Value
00307 operator + (const ACE_Time_Value &tv1,
00308 const ACE_Time_Value &tv2)
00309 {
00310
00311 ACE_Time_Value sum (tv1.sec () + tv2.sec (),
00312 tv1.usec () + tv2.usec ());
00313
00314 sum.normalize ();
00315 return sum;
00316 }
00317
00318
00319
00320 ACE_INLINE ACE_Time_Value
00321 operator - (const ACE_Time_Value &tv1,
00322 const ACE_Time_Value &tv2)
00323 {
00324
00325 ACE_Time_Value delta (tv1.sec () - tv2.sec (),
00326 tv1.usec () - tv2.usec ());
00327 delta.normalize ();
00328 return delta;
00329 }