home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tcpp / classlib / source / ltime.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-10  |  4.8 KB  |  187 lines

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