home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / CLASSINC.ZIP / LTIME.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.9 KB  |  186 lines

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