home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSINC.ZIP / LTIME.H < prev    next >
C/C++ Source or Header  |  1992-02-18  |  4KB  |  176 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  LTIME.H                                                               */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __LTIME_H )
  11. #define __LTIME_H
  12.  
  13. #if !defined( __CHECKS_H )
  14. #include <Checks.h>
  15. #endif    // __CHECKS_H
  16.  
  17. #if !defined( __DOS_H )
  18. #include <Dos.h>
  19. #endif  // __DOS_H
  20.  
  21. #if !defined( __SORTABLE_H )
  22. #include <Sortable.h>
  23. #endif  // __SORTABLE_H
  24.  
  25. _CLASSDEF(ostream)
  26. _CLASSDEF(BaseTime)
  27. _CLASSDEF(Time)
  28.  
  29. class _CLASSTYPE BaseTime : public Sortable
  30. {
  31.  
  32. public:
  33.  
  34.     unsigned hour() const;
  35.     unsigned minute() const;
  36.     unsigned second() const;
  37.     unsigned hundredths() const;
  38.     void setHour( unsigned char );
  39.     void setMinute( unsigned char );
  40.     void setSecond( unsigned char );
  41.     void setHundredths( unsigned char );
  42.  
  43.     virtual classType isA() const = 0;
  44.     virtual char _FAR *nameOf() const = 0;
  45.     virtual hashValueType hashValue() const;
  46.     virtual int isEqual( const Object _FAR & ) const;
  47.     virtual int isLessThan( const Object _FAR & ) const;
  48.     virtual void printOn( ostream _FAR & ) const = 0;
  49.  
  50. protected:
  51.  
  52.     BaseTime();
  53.     BaseTime( const BaseTime _FAR & );
  54.     BaseTime( unsigned char,
  55.               unsigned char = 0,
  56.               unsigned char = 0,
  57.               unsigned char = 0
  58.             );
  59.  
  60. private:
  61.  
  62.     unsigned char HH;
  63.     unsigned char MM;
  64.     unsigned char SS;
  65.     unsigned char HD;
  66. };
  67.  
  68. inline BaseTime::BaseTime()
  69. {
  70.     struct time t;
  71.     gettime( &t );
  72.     HH = t.ti_hour;
  73.     MM = t.ti_min;
  74.     SS = t.ti_sec;
  75.     HD = t.ti_hund;
  76. }
  77.  
  78. inline BaseTime::BaseTime( const BaseTime _FAR & B ) :
  79.     HH(B.HH), MM(B.MM), SS(B.SS), HD(B.HD)
  80. {
  81. }
  82.  
  83. inline BaseTime::BaseTime( unsigned char H, unsigned char M, unsigned char S, unsigned char D )
  84. {
  85.     setHour( H );
  86.     setMinute( M );
  87.     setSecond( S );
  88.     setHundredths( D );
  89. }
  90.  
  91. inline unsigned BaseTime::hour() const
  92. {
  93.     return HH;
  94. }
  95.  
  96. inline unsigned BaseTime::minute() const
  97. {
  98.     return MM;
  99. }
  100.  
  101. inline unsigned BaseTime::second() const
  102. {
  103.     return SS;
  104. }
  105.  
  106. inline unsigned BaseTime::hundredths() const
  107. {
  108.     return HD;
  109. }
  110.  
  111. inline void BaseTime::setHour( unsigned char anHour )
  112. {
  113.     PRECONDITION( anHour < 24 );
  114.     HH = anHour;
  115. }
  116.  
  117. inline void BaseTime::setMinute( unsigned char M )
  118. {
  119.     PRECONDITION( M < 60 );
  120.     MM = M;
  121. }
  122.  
  123. inline void BaseTime::setSecond( unsigned char S )
  124. {
  125.     PRECONDITION( S < 60 );
  126.     SS = S;
  127. }
  128.  
  129. inline void BaseTime::setHundredths( unsigned char D )
  130. {
  131.     PRECONDITION( D < 100 );
  132.     HD = D;
  133. }
  134.  
  135. class _CLASSTYPE Time : public BaseTime
  136. {
  137.  
  138. public:
  139.  
  140.     Time();
  141.     Time( const Time _FAR & );
  142.     Time( unsigned char,
  143.           unsigned char = 0,
  144.           unsigned char = 0,
  145.           unsigned char = 0
  146.         );
  147.  
  148.     virtual classType isA() const
  149.         {
  150.         return timeClass;
  151.         }
  152.  
  153.     virtual char _FAR *nameOf() const
  154.         {
  155.         return "Time";
  156.         }
  157.  
  158.     virtual void printOn( ostream _FAR & ) const;
  159. };
  160.  
  161. inline Time::Time() : BaseTime()
  162. {
  163. }
  164.  
  165. inline Time::Time( const Time& T ) : BaseTime( T )
  166. {
  167. }
  168.  
  169. inline Time::Time( unsigned char H, unsigned char M, unsigned char S,
  170.                    unsigned char D ) :  BaseTime( H, M, S, D )
  171. {
  172. }
  173.  
  174. #endif  // __LTIME_H
  175.  
  176.