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

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3.  
  4. // Contents ----------------------------------------------------------------
  5. //
  6. //      FileData::FileData                            constructor
  7. //
  8. // Description
  9. //
  10. //     Class FileData member function implementation.
  11. //
  12. // End ---------------------------------------------------------------------
  13.  
  14. // Interface Dependencies ---------------------------------------------------
  15.  
  16. #ifndef __IOSTREAM_H
  17. #include <iostream.h>
  18. #define __IOSTREAM_H
  19. #endif
  20.  
  21. #ifndef __IOMANIP_H
  22. #include <iomanip.h>
  23. #define __IOMANIP_H
  24. #endif
  25.  
  26. #ifndef __DIR_H
  27. #include <dir.h>
  28. #define __DIR_H
  29. #endif
  30.  
  31. #ifndef __CSLTYPES_H
  32. #include <clstypes.h>
  33. #endif
  34.  
  35. #ifndef __FILEDATA_H
  36. #include "filedata.h"
  37. #endif
  38.  
  39. // End Interface Dependencies ------------------------------------------------
  40.  
  41. // Implementation Dependencies ----------------------------------------------
  42. // End Implementation Dependencies -------------------------------------------
  43.  
  44.  
  45. // Constructor //
  46.  
  47. FileData::FileData( ffblk& blk ) :
  48.     fileName( blk.ff_name ),
  49.     fileDate( (blk.ff_fdate >> 5) & 0x000F,
  50.               blk.ff_fdate & 0x0001F,
  51.               (blk.ff_fdate >> 9) + 1980 ),
  52.     fileSize( blk.ff_fsize ),
  53.     fileTime( blk.ff_ftime >> 11,
  54.               (blk.ff_ftime >> 5) & 0x3F,
  55.               blk.ff_ftime & 0x1F )
  56.  
  57. // Summary -----------------------------------------------------------------
  58. //
  59. //     Constructor for a file data object.  Constructs the file name
  60. //     file data, and file size objects.
  61. //
  62. // Parameters
  63. //
  64. //     blk
  65. //
  66. //     The DOS file block structure we are to use to construct the
  67. //     file data object.
  68. //
  69. // End ---------------------------------------------------------------------
  70. {
  71. }
  72. // End Constructor //
  73.  
  74.  
  75. // Member Function //
  76.  
  77. void FileData::printOn( ostream& outputStream ) const
  78.  
  79. // Summary -----------------------------------------------------------------
  80. //
  81. //     Displays the contents of a file data object on the given stream.
  82. //
  83. // Parameters
  84. //
  85. //     outputStream
  86. //
  87. //     The stream on which we are to display.
  88. //
  89. // End ---------------------------------------------------------------------
  90. {
  91.     outputStream << setw( 14 ) << setiosflags( ios::left )   << fileName
  92.                  << setw( 18 ) << fileDate
  93.                  << setw( 17 ) << resetiosflags( ios::left ) << fileTime
  94.                  << setw( 10 ) << fileSize << " bytes";
  95. }
  96. // End Member Function printOn //
  97.  
  98. // Member Function //
  99.  
  100. int FilesByName::isEqual( const Object& testFile ) const
  101.  
  102. // Summary -----------------------------------------------------------------
  103. //
  104. //      Determines whether two files are equal by comparing their names.
  105. //
  106. // Return Value
  107. //
  108. //      Returns 1 if the files have the same name, 0 otherwise.
  109. //
  110. // End ---------------------------------------------------------------------
  111. {
  112.     return fileName == ( (FilesByName&)testFile ).fileName;
  113. }
  114. // End Member Function FilesByName::isEqual //
  115.  
  116.  
  117. // Member Function //
  118.  
  119. int FilesByName::isLessThan( const Object& testFile ) const
  120.  
  121. // Summary -----------------------------------------------------------------
  122. //
  123. //      Determines the ordering of two files by comparing their names.
  124. //
  125. // Return Value
  126. //
  127. //      Returns 1 if this file is less than the given file, 0 otherwise.
  128. //
  129. // End ---------------------------------------------------------------------
  130. {
  131.     return fileName < ( (FilesByName&)testFile ).fileName;
  132. }
  133. // End Member Function FilesByName::isLessThan //
  134.  
  135.  
  136. // Member Function //
  137.  
  138. int FilesByDate::isEqual( const Object& testFile ) const
  139.  
  140. // Summary -----------------------------------------------------------------
  141. //
  142. //      Determines whether two files by are equal by comparing their dates.
  143. //
  144. // Return Value
  145. //
  146. //      Returns 1 if the files have the same date, 0 otherwise.
  147. //
  148. // End ---------------------------------------------------------------------
  149. {
  150.     return fileDate == ( (FilesByDate&)testFile ).fileDate &&
  151.            fileTime == ( (FilesByDate&)testFile ).fileTime;
  152. }
  153. // End Member Function FilesByDate::isEqual //
  154.  
  155.  
  156. // Member Function //
  157.  
  158. int FilesByDate::isLessThan( const Object& testFile ) const
  159.  
  160. // Summary -----------------------------------------------------------------
  161. //
  162. //      Determines the ordering of two files by comparing their names.
  163. //
  164. // Return Value
  165. //
  166. //      Returns 1 if this file is less than the given file, 0 otherwise.
  167. //
  168. // End ---------------------------------------------------------------------
  169. {
  170.     if( fileDate == ( (FilesByDate&)testFile ).fileDate )
  171.         return fileTime < ( (FilesByDate&)testFile ).fileTime;
  172.     else
  173.         return fileDate < ( (FilesByDate&)testFile ).fileDate;
  174. }
  175. // End Member Function FilesByDate::isLessThan //
  176.  
  177.  
  178. // Member Function //
  179.  
  180. int FilesBySize::isEqual( const Object& testFile ) const
  181.  
  182. // Summary -----------------------------------------------------------------
  183. //
  184. //      Determines the whether two files are equal by comparing their
  185. //      sizes.
  186. //
  187. // Return Value
  188. //
  189. //      Returns 1 if this file is less than the given file, 0 otherwise.
  190. //
  191. // End ---------------------------------------------------------------------
  192. {
  193.     return fileSize == ( (FilesBySize&)testFile ).fileSize;
  194. }
  195. // End Member Function FilesBySize::isEqual //
  196.  
  197.  
  198. // Member Function //
  199.  
  200. int FilesBySize::isLessThan( const Object& testFile ) const
  201.  
  202. // Summary -----------------------------------------------------------------
  203. //
  204. //      Determines the ordering of two files by comparing their sizes.
  205. //
  206. // Return Value
  207. //
  208. //      Returns 1 if this file is less than the given file, 0 otherwise.
  209. //
  210. // End ---------------------------------------------------------------------
  211. {
  212.     return fileSize < ( (FilesBySize&)testFile ).fileSize;
  213. }
  214. // End Member Function FilesBySize::isLessThan //
  215.  
  216.