home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / CLASSINC.ZIP / LDATE.H < prev    next >
C/C++ Source or Header  |  1990-09-26  |  3KB  |  141 lines

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