home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 1.ddi / CLASSINC.ZIP / LDATE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  2.8 KB  |  131 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //     BaseDate
  6. //
  7. // Description
  8. //
  9. /*  Provides BaseDate as an abstract base class for handling date    */
  10. /*  storage and formatting                                           */
  11. //
  12. /*  Provides the Date class for storing dates and converting them    */
  13. /*  to an ASCII string of the form                                   */
  14. /*                                                                   */
  15. /*      January 1, 1990                                              */
  16. //
  17. // End ---------------------------------------------------------------------
  18.  
  19. #ifndef __LDATE_H
  20. #define __LDATE_H
  21.  
  22. #include <assert.h>
  23. #include <dos.h>
  24. #include "strng.h"
  25.  
  26. class BaseDate : public Sortable
  27. {
  28. public:
  29.     unsigned Month() const;
  30.     unsigned Day() const;
  31.     unsigned Year() const;
  32.     void SetMonth( unsigned char );
  33.     void SetDay( unsigned char );
  34.     void SetYear( unsigned );
  35.  
  36.     virtual classType       isA() const = 0;
  37.     virtual char            *nameOf() const = 0;
  38.     virtual hashValueType   hashValue() const;
  39.     virtual int             isEqual( const Object& ) const;
  40.     virtual int             isLessThan( const Object& ) const;
  41.     virtual void            printOn( ostream& ) const = 0;
  42. protected:
  43.     BaseDate();
  44.     BaseDate( unsigned char, unsigned char, unsigned );
  45.     BaseDate( const BaseDate& );
  46.     ~BaseDate();
  47. private:
  48.     unsigned char MM;
  49.     unsigned char DD;
  50.     unsigned int YY;
  51. };
  52.  
  53. inline BaseDate::BaseDate()
  54. {
  55.     struct date d;
  56.     getdate( &d );
  57.     MM = d.da_mon - 1;
  58.     DD = d.da_day;
  59.     YY = d.da_year;
  60. }
  61.  
  62. inline BaseDate::BaseDate( unsigned char M, unsigned char D, unsigned Y )
  63. {
  64.     SetMonth( M );
  65.     SetDay( D );
  66.     SetYear( Y );
  67. }
  68.  
  69. inline BaseDate::BaseDate( const BaseDate& B ) :
  70.     MM(B.MM), DD(B.DD), YY(B.YY)
  71. {
  72. }
  73.  
  74. inline unsigned BaseDate::Month() const
  75. {
  76.     return MM;
  77. }
  78.  
  79. inline unsigned BaseDate::Day() const
  80. {
  81.     return DD;
  82. }
  83.  
  84. inline unsigned BaseDate::Year() const
  85. {
  86.     return YY;
  87. }
  88.  
  89. inline void BaseDate::SetMonth( unsigned char M )
  90. {
  91.     assert( M > 0 && M < 13 );
  92.     MM = M - 1;
  93. }
  94.  
  95. inline void BaseDate::SetDay( unsigned char D )
  96. {
  97.     assert( D < 32 );
  98.     DD = D;
  99. }
  100.  
  101. inline void BaseDate::SetYear( unsigned Y )
  102. {
  103.     YY = Y;
  104. }
  105.  
  106. class Date : public BaseDate
  107. {
  108. public:
  109.     Date();
  110.     Date( unsigned char, unsigned char, unsigned );
  111.     Date( const Date& );
  112.     ~Date();
  113.     virtual classType       isA() const;
  114.     virtual char            *nameOf() const;
  115.     virtual void            printOn( ostream& ) const;
  116. };
  117.  
  118. inline Date::Date()
  119. {
  120. }
  121.  
  122. inline Date::Date( unsigned char M, unsigned char D, unsigned Y ) : BaseDate( M, D, Y )
  123. {
  124. }
  125.  
  126. inline Date::Date( const Date& D ) : BaseDate( D )
  127. {
  128. }
  129.  
  130. #endif  // ifndef __LDATE_H //
  131.