Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Time_Value.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // $Id: Time_Value.inl,v 1.1.1.1.2.1 2003/04/23 15:16:40 chad Exp $
00004 
00005 
00006 // Returns the value of the object as a timeval.
00007 
00008 ACE_INLINE
00009 ACE_Time_Value::operator timeval () const
00010 {
00011   // ACE_OS_TRACE ("ACE_Time_Value::operator timeval");
00012   return this->tv_;
00013 }
00014 
00015 // Returns a pointer to the object as a timeval.
00016 
00017 ACE_INLINE
00018 ACE_Time_Value::operator const timeval * () const
00019 {
00020   // ACE_OS_TRACE ("ACE_Time_Value::operator const timeval *");
00021   return (const timeval *) &this->tv_;
00022 }
00023 
00024 ACE_INLINE void
00025 ACE_Time_Value::set (long sec, long usec)
00026 {
00027   // ACE_OS_TRACE ("ACE_Time_Value::set");
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   // ACE_OS_TRACE ("ACE_Time_Value::set");
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 // Initializes a timespec_t.  Note that this approach loses precision
00044 // since it converts the nano-seconds into micro-seconds.  But then
00045 // again, do any real systems have nano-second timer precision?!
00046 
00047 ACE_INLINE void
00048 ACE_Time_Value::set (const timespec_t &tv)
00049 {
00050   // ACE_OS_TRACE ("ACE_Time_Value::set");
00051 #if ! defined(ACE_HAS_BROKEN_TIMESPEC_MEMBERS)
00052   this->tv_.tv_sec = ACE_static_cast (long, tv.tv_sec);
00053   // Convert nanoseconds into microseconds.
00054   this->tv_.tv_usec = tv.tv_nsec / 1000;
00055 #else
00056   this->tv_.tv_sec = tv.ts_sec;
00057   // Convert nanoseconds into microseconds.
00058   this->tv_.tv_usec = tv.ts_nsec / 1000;
00059 #endif /* ACE_HAS_BROKEN_TIMESPEC_MEMBERS */
00060 
00061   this->normalize ();
00062 }
00063 
00064 ACE_INLINE void
00065 ACE_Time_Value::set (const timeval &tv)
00066 {
00067   // ACE_OS_TRACE ("ACE_Time_Value::set");
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   // : tv_ ()
00077 {
00078   // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
00079   this->set (tv);
00080 }
00081 
00082 ACE_INLINE
00083 ACE_Time_Value::ACE_Time_Value (void)
00084   // : tv_ ()
00085 {
00086   // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
00087   this->set (0, 0);
00088 }
00089 
00090 ACE_INLINE
00091 ACE_Time_Value::ACE_Time_Value (long sec, long usec)
00092 {
00093   // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
00094   this->set (sec, usec);
00095 }
00096 
00097 // Returns number of seconds.
00098 
00099 ACE_INLINE long
00100 ACE_Time_Value::sec (void) const
00101 {
00102   // ACE_OS_TRACE ("ACE_Time_Value::sec");
00103   return this->tv_.tv_sec;
00104 }
00105 
00106 // Sets the number of seconds.
00107 
00108 ACE_INLINE void
00109 ACE_Time_Value::sec (long sec)
00110 {
00111   // ACE_OS_TRACE ("ACE_Time_Value::sec");
00112   this->tv_.tv_sec = sec;
00113 }
00114 
00115 // Converts from Time_Value format into milli-seconds format.
00116 
00117 ACE_INLINE long
00118 ACE_Time_Value::msec (void) const
00119 {
00120   // ACE_OS_TRACE ("ACE_Time_Value::msec");
00121   return this->tv_.tv_sec * 1000 + this->tv_.tv_usec / 1000;
00122 }
00123 
00124 // Converts from milli-seconds format into Time_Value format.
00125 
00126 ACE_INLINE void
00127 ACE_Time_Value::msec (long milliseconds)
00128 {
00129   // ACE_OS_TRACE ("ACE_Time_Value::msec");
00130   // Convert millisecond units to seconds;
00131   this->tv_.tv_sec = milliseconds / 1000;
00132   // Convert remainder to microseconds;
00133   this->tv_.tv_usec = (milliseconds - (this->tv_.tv_sec * 1000)) * 1000;
00134 }
00135 
00136 // Returns number of micro-seconds.
00137 
00138 ACE_INLINE long
00139 ACE_Time_Value::usec (void) const
00140 {
00141   // ACE_OS_TRACE ("ACE_Time_Value::usec");
00142   return this->tv_.tv_usec;
00143 }
00144 
00145 // Sets the number of micro-seconds.
00146 
00147 ACE_INLINE void
00148 ACE_Time_Value::usec (long usec)
00149 {
00150   // ACE_OS_TRACE ("ACE_Time_Value::usec");
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 // True if tv1 > tv2.
00179 
00180 ACE_INLINE int
00181 operator > (const ACE_Time_Value &tv1,
00182             const ACE_Time_Value &tv2)
00183 {
00184   // ACE_OS_TRACE ("operator >");
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 // True if tv1 >= tv2.
00195 
00196 ACE_INLINE int
00197 operator >= (const ACE_Time_Value &tv1,
00198              const ACE_Time_Value &tv2)
00199 {
00200   // ACE_OS_TRACE ("operator >=");
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 // Returns the value of the object as a timespec_t.
00211 
00212 ACE_INLINE
00213 ACE_Time_Value::operator timespec_t () const
00214 {
00215   // ACE_OS_TRACE ("ACE_Time_Value::operator timespec_t");
00216   timespec_t tv;
00217 #if ! defined(ACE_HAS_BROKEN_TIMESPEC_MEMBERS)
00218   tv.tv_sec = this->sec ();
00219   // Convert microseconds into nanoseconds.
00220   tv.tv_nsec = this->tv_.tv_usec * 1000;
00221 #else
00222   tv.ts_sec = this->sec ();
00223   // Convert microseconds into nanoseconds.
00224   tv.ts_nsec = this->tv_.tv_usec * 1000;
00225 #endif /* ACE_HAS_BROKEN_TIMESPEC_MEMBERS */
00226   return tv;
00227 }
00228 
00229 // Initializes the ACE_Time_Value object from a timespec_t.
00230 
00231 ACE_INLINE
00232 ACE_Time_Value::ACE_Time_Value (const timespec_t &tv)
00233   // : tv_ ()
00234 {
00235   // ACE_OS_TRACE ("ACE_Time_Value::ACE_Time_Value");
00236   this->set (tv);
00237 }
00238 
00239 // True if tv1 < tv2.
00240 
00241 ACE_INLINE int
00242 operator < (const ACE_Time_Value &tv1,
00243             const ACE_Time_Value &tv2)
00244 {
00245   // ACE_OS_TRACE ("operator <");
00246   return tv2 > tv1;
00247 }
00248 
00249 // True if tv1 >= tv2.
00250 
00251 ACE_INLINE int
00252 operator <= (const ACE_Time_Value &tv1,
00253              const ACE_Time_Value &tv2)
00254 {
00255   // ACE_OS_TRACE ("operator <=");
00256   return tv2 >= tv1;
00257 }
00258 
00259 // True if tv1 == tv2.
00260 
00261 ACE_INLINE int
00262 operator == (const ACE_Time_Value &tv1,
00263              const ACE_Time_Value &tv2)
00264 {
00265   // ACE_OS_TRACE ("operator ==");
00266   return tv1.sec () == tv2.sec ()
00267     && tv1.usec () == tv2.usec ();
00268 }
00269 
00270 // True if tv1 != tv2.
00271 
00272 ACE_INLINE int
00273 operator != (const ACE_Time_Value &tv1,
00274              const ACE_Time_Value &tv2)
00275 {
00276   // ACE_OS_TRACE ("operator !=");
00277   return !(tv1 == tv2);
00278 }
00279 
00280 // Add TV to this.
00281 
00282 ACE_INLINE ACE_Time_Value &
00283 ACE_Time_Value::operator+= (const ACE_Time_Value &tv)
00284 {
00285   // ACE_OS_TRACE ("ACE_Time_Value::operator+=");
00286   this->sec (this->sec () + tv.sec ());
00287   this->usec (this->usec () + tv.usec ());
00288   this->normalize ();
00289   return *this;
00290 }
00291 
00292 // Subtract TV to this.
00293 
00294 ACE_INLINE ACE_Time_Value &
00295 ACE_Time_Value::operator-= (const ACE_Time_Value &tv)
00296 {
00297   // ACE_OS_TRACE ("ACE_Time_Value::operator-=");
00298   this->sec (this->sec () - tv.sec ());
00299   this->usec (this->usec () - tv.usec ());
00300   this->normalize ();
00301   return *this;
00302 }
00303 
00304 // Adds two ACE_Time_Value objects together, returns the sum.
00305 
00306 ACE_INLINE ACE_Time_Value
00307 operator + (const ACE_Time_Value &tv1,
00308             const ACE_Time_Value &tv2)
00309 {
00310   // ACE_OS_TRACE ("operator +");
00311   ACE_Time_Value sum (tv1.sec () + tv2.sec (),
00312                       tv1.usec () + tv2.usec ());
00313 
00314   sum.normalize ();
00315   return sum;
00316 }
00317 
00318 // Subtracts two ACE_Time_Value objects, returns the difference.
00319 
00320 ACE_INLINE ACE_Time_Value
00321 operator - (const ACE_Time_Value &tv1,
00322             const ACE_Time_Value &tv2)
00323 {
00324   // ACE_OS_TRACE ("operator -");
00325   ACE_Time_Value delta (tv1.sec () - tv2.sec (),
00326                         tv1.usec () - tv2.usec ());
00327   delta.normalize ();
00328   return delta;
00329 }

Generated on Mon Jun 16 11:21:48 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002