home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 11.ddi / CLASSSRC.ZIP / LTIME.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  4.2 KB  |  173 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //      BaseTime::operator String()
  6. //
  7. // Description
  8. //
  9. //      Implementation of class BaseTime member functions.
  10. //
  11. // End ---------------------------------------------------------------------
  12.  
  13. // Interface Dependencies ---------------------------------------------------
  14.  
  15. #ifndef __STRNG_H
  16. #include <strng.h>
  17. #endif
  18.  
  19. #ifndef __LTIME_H
  20. #include <ltime.h>
  21. #endif
  22.  
  23. // End Interface Dependencies ------------------------------------------------
  24.  
  25.  
  26. // Implementation Dependencies ----------------------------------------------
  27.  
  28. #ifndef __IOMANIP_H
  29. #include <iomanip.h>
  30. #endif
  31.  
  32. #ifndef __STRSTREAM_H
  33. #include <strstream.h>
  34. #endif
  35.  
  36. #ifndef __STDIO_H
  37. #include <stdio.h>
  38. #define __STDIO_H
  39. #endif
  40.  
  41. // End Implementation Dependencies -------------------------------------------
  42.  
  43.  
  44. const BufSize = 20;
  45.  
  46. // Member Function //
  47.  
  48. BaseTime::isEqual( const Object& testTime ) const
  49.  
  50. // Summary -----------------------------------------------------------------
  51. //
  52. //      Determines whether two times are equal.  Times are assumed to be
  53. //      normalized.
  54. //
  55. // Parameters
  56. //
  57. //      testTime
  58. //
  59. //      The time we are testing against this.
  60. //
  61. // End ---------------------------------------------------------------------
  62. {
  63.         return HH == ((BaseTime&)testTime).HH &&
  64.                MM == ((BaseTime&)testTime).MM &&
  65.                SS == ((BaseTime&)testTime).SS &&
  66.                HD == ((BaseTime&)testTime).HD;
  67. }
  68. // End Member Function Time::isEqual //
  69.  
  70. // Member Function //
  71.  
  72. BaseTime::isLessThan( const Object& testTime ) const
  73.  
  74. // Summary -----------------------------------------------------------------
  75. //
  76. //      Determines whether this time is less than the time passed as
  77. //        an argument.  Times are assumed to be normalized.
  78. //
  79. // Parameters
  80. //
  81. //      testTime
  82. //
  83. //      The time we are testing against this.
  84. //
  85. // End ---------------------------------------------------------------------
  86. {
  87.         if( HH != ((BaseTime&)testTime).HH )
  88.             return HH < ((BaseTime&)testTime).HH;
  89.         if( MM != ((BaseTime&)testTime).MM )
  90.             return MM < ((BaseTime&)testTime).MM;
  91.         if( SS != ((BaseTime&)testTime).SS )
  92.             return SS < ((BaseTime&)testTime).SS;
  93.         if( HD == ((BaseTime&)testTime).HD )
  94.             return HD < ((BaseTime&)testTime).HD;
  95. }
  96. // End Member Function Time::isEqual //
  97.  
  98. // Member Function //
  99.  
  100. hashValueType BaseTime::hashValue() const
  101.  
  102. // Summary -----------------------------------------------------------------
  103. //
  104. //      Returns the hash value of a string object.
  105. //
  106. // End ---------------------------------------------------------------------
  107. {
  108.     return hashValueType( HH + MM + SS + HD );
  109. }
  110. // End Member Function BaseTime::hashValue //
  111.  
  112.  
  113. // Member Function //
  114.  
  115. void Time::printOn( ostream& outputStream ) const
  116.  
  117. // Summary -----------------------------------------------------------------
  118. //
  119. //      Displays this object on the given stream.
  120. //
  121. // Parameters
  122. //
  123. //      outputStream
  124. //
  125. //      The stream where we are to display the object.
  126. //
  127. // End ---------------------------------------------------------------------
  128. {
  129.     char temp[16];
  130.  
  131.     ostrstream( temp, BufSize ) << 
  132.         ((hour()%12 == 0) ? 12 : hour()%12) << ":"
  133.         << setfill( '0' )
  134.         << setw( 2 ) << minute() << ":"
  135.         << setw( 2 ) << second() << "."
  136.         << setw( 2 ) << hundredths() << " "
  137.         << ((hour() > 11) ? "p" : "a") << "m" << ends;
  138.  
  139.     outputStream << temp;
  140. }
  141. // End Member Function Time::printOn //
  142.  
  143.  
  144. // Member Function //
  145.  
  146. classType Time::isA() const
  147.  
  148. // Summary -----------------------------------------------------------------
  149. //
  150. //      Returns the class type of a Time object.
  151. //
  152. // End ---------------------------------------------------------------------
  153. {
  154.     return timeClass;
  155. }
  156. // End Member Function Time::isA //
  157.  
  158.  
  159. // Member Function //
  160.  
  161. char *Time::nameOf() const
  162.  
  163. // Summary -----------------------------------------------------------------
  164. //
  165. //      Returns a pointer to the character string "Time."
  166. //
  167. // End ---------------------------------------------------------------------
  168. {
  169.     return "Time";
  170. }
  171. // End Member Function Time::nameOf //
  172.  
  173.