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

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  LDATE.H                                                               */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1992                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __LDATE_H )
  11. #define __LDATE_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(BaseDate)
  32. _CLASSDEF(Date)
  33.  
  34. class _CLASSTYPE BaseDate : public Sortable
  35. {
  36.  
  37. public:
  38.  
  39.     unsigned Month() const;
  40.     unsigned Day() const;
  41.     unsigned Year() const;
  42.     void SetMonth( unsigned char );
  43.     void SetDay( unsigned char );
  44.     void SetYear( unsigned );
  45.  
  46.     virtual hashValueType hashValue() const;
  47.     virtual int isEqual( const Object _FAR & ) const;
  48.     virtual int isLessThan( const Object _FAR & ) const;
  49.     virtual void printOn( ostream _FAR & ) const = 0;
  50.  
  51. protected:
  52.  
  53.     BaseDate();
  54.     BaseDate( unsigned char, unsigned char, unsigned );
  55.     BaseDate( const BaseDate _FAR & );
  56.  
  57. private:
  58.  
  59.     unsigned char MM;
  60.     unsigned char DD;
  61.     unsigned int YY;
  62.  
  63. };
  64.  
  65. inline BaseDate::BaseDate()
  66. {
  67.     struct date d;
  68.     getdate( &d );
  69.     MM = d.da_mon;
  70.     DD = d.da_day;
  71.     YY = d.da_year;
  72. }
  73.  
  74. inline BaseDate::BaseDate( unsigned char M, unsigned char D, unsigned Y )
  75. {
  76.     SetMonth( M );
  77.     SetDay( D );
  78.     SetYear( Y );
  79. }
  80.  
  81. inline BaseDate::BaseDate( const BaseDate _FAR & B ) :
  82.     MM(B.MM), DD(B.DD), YY(B.YY)
  83. {
  84. }
  85.  
  86. inline unsigned BaseDate::Month() const
  87. {
  88.     return MM;
  89. }
  90.  
  91. inline unsigned BaseDate::Day() const
  92. {
  93.     return DD;
  94. }
  95.  
  96. inline unsigned BaseDate::Year() const
  97. {
  98.     return YY;
  99. }
  100.  
  101. inline void BaseDate::SetMonth( unsigned char M )
  102. {
  103.     PRECONDITION( M > 0 && M < 13 );
  104.     MM = M;
  105. }
  106.  
  107. inline void BaseDate::SetDay( unsigned char D )
  108. {
  109.     PRECONDITION( D < 32 );
  110.     DD = D;
  111. }
  112.  
  113. inline void BaseDate::SetYear( unsigned Y )
  114. {
  115.     YY = Y;
  116. }
  117.  
  118. class _CLASSTYPE Date : public BaseDate
  119. {
  120.  
  121. public:
  122.  
  123.     Date();
  124.     Date( unsigned char, unsigned char, unsigned );
  125.     Date( const Date _FAR & );
  126.  
  127.     virtual classType isA() const
  128.         {
  129.         return dateClass;
  130.         }
  131.  
  132.     virtual char _FAR *nameOf() const
  133.         {
  134.         return "Date";
  135.         }
  136.  
  137.     virtual void printOn( ostream _FAR & ) const;
  138.  
  139. };
  140.  
  141. inline Date::Date()
  142. {
  143. }
  144.  
  145. inline Date::Date( unsigned char M, unsigned char D, unsigned Y ) :
  146.     BaseDate( M, D, Y )
  147. {
  148. }
  149.  
  150. inline Date::Date( const Date& D ) : BaseDate( D )
  151. {
  152. }
  153.  
  154. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  155. #pragma option -po.
  156. #endif
  157. #pragma option -Vo.
  158.  
  159. #endif  // __LDATE_H
  160.