home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / itime.inl < prev    next >
Encoding:
Text File  |  1996-02-22  |  4.4 KB  |  136 lines

  1. #ifndef _ITIME_INL_
  2. #define _ITIME_INL_ 0
  3. /*******************************************************************************
  4. * FILE NAME: itime.inl                                                         *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   This file contains the definition of the inline functions for the          *
  8. *   classes declared in itime.hpp.                                             *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   IBM Open Class Library                                                     *
  12. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  13. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _ITIME_
  19.   #undef  _ITIME_INL_
  20.   #define _ITIME_INL_ 1
  21.   #include <itime.hpp>
  22. #endif
  23.  
  24. extern "C"
  25.   {
  26.   #include <time.h>
  27.   }
  28.  
  29. #if _ITIME_INL_
  30.   #define inline
  31. #endif
  32.  
  33. /*------------------------------ Implementation ------------------------------*/
  34. inline ITime& ITime :: initialize ( long seconds )
  35.   {
  36.   const long secondsPerDay = 24*60*60L;
  37.   if ( seconds < 0 )
  38.     this->ticks = secondsPerDay - (-seconds % secondsPerDay);
  39.   else
  40.     this->ticks = seconds % secondsPerDay;
  41.   return *this;
  42.   }
  43. /*------------------------------- Constructors -------------------------------*/
  44. inline ITime :: ITime ( unsigned hours,
  45.                         unsigned minutes,
  46.                         unsigned seconds )
  47.   {
  48.   long secs = hours;
  49.   secs *= 60;
  50.   secs += minutes;
  51.   secs *= 60;
  52.   secs += seconds;
  53.   this->initialize( secs );
  54.   }
  55. inline ITime ITime :: now ( )
  56.   {
  57.   time_t t    = time( 0 );
  58.   tm     time = *localtime( &t );
  59.   return ITime( time.tm_hour, time.tm_min, time.tm_sec );
  60.   }
  61. inline ITime :: ITime ( )
  62.   {
  63.   this->ticks = this->now().ticks;
  64.   }
  65. inline ITime :: ITime ( long seconds )
  66.   {
  67.   this->initialize( seconds );
  68.   }
  69. inline ITime :: ITime ( const ITime &aTime )
  70.   {
  71.   this->ticks = aTime.ticks;
  72.   }
  73. /*-------------------------------- Accessors ---------------------------------*/
  74. inline long ITime :: asSeconds ( ) const
  75.   {
  76.   return this->ticks;
  77.   }
  78. inline unsigned ITime :: hours ( ) const
  79.   {
  80.   // seconds/(seconds/hour) -> hours.
  81.   return ((unsigned)(this->ticks / 3600));
  82.   }
  83. inline unsigned ITime :: minutes ( ) const
  84.   {
  85.   // seconds (past hour)/(seconds/minute) -> minutes.
  86.   return ((unsigned)((this->ticks % 3600 ) / 60));
  87.   }
  88. inline unsigned ITime :: seconds ( ) const
  89.   {
  90.   // seconds (past minute)
  91.   return ((unsigned)(this->ticks % 60));
  92.   }
  93. /*-------------------------------- Comparison --------------------------------*/
  94. inline IBase::Boolean ITime :: operator == ( const ITime &aTime ) const
  95.   {
  96.   return this->ticks == aTime.ticks;
  97.   }
  98. inline IBase::Boolean ITime :: operator != ( const ITime &aTime ) const
  99.   {
  100.   return this->ticks != aTime.ticks;
  101.   }
  102. inline IBase::Boolean ITime :: operator <  ( const ITime &aTime ) const
  103.   {
  104.   return this->ticks <  aTime.ticks;
  105.   }
  106. inline IBase::Boolean ITime :: operator <= ( const ITime &aTime ) const
  107.   {
  108.   return this->ticks <= aTime.ticks;
  109.   }
  110. inline IBase::Boolean ITime :: operator >  ( const ITime &aTime ) const
  111.   {
  112.   return this->ticks >  aTime.ticks;
  113.   }
  114. inline IBase::Boolean ITime :: operator >= ( const ITime &aTime ) const
  115.   {
  116.   return this->ticks >= aTime.ticks;
  117.   }
  118. /*-------------------------- Manipulation Operators --------------------------*/
  119. inline ITime& ITime :: operator += ( const ITime &aTime )
  120.   {
  121.   return this->initialize( this->ticks + aTime.ticks );
  122.   }
  123. inline ITime ITime :: operator + ( const ITime &aTime ) const
  124.   {
  125.   return ITime( this->ticks + aTime.ticks );
  126.   }
  127. inline ITime& ITime :: operator -= ( const ITime &aTime )
  128.   {
  129.   return this->initialize( this->ticks - aTime.ticks );
  130.   }
  131. inline ITime ITime :: operator - ( const ITime &aTime ) const
  132.   {
  133.   return ITime( this->ticks - aTime.ticks );
  134.   }
  135. #endif // _ITIME_INL_
  136.