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 / LDATE.H < prev    next >
C/C++ Source or Header  |  1992-02-18  |  3KB  |  150 lines

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