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

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3.  
  4. // Contents ----------------------------------------------------------------
  5. //
  6. //      Directory::Directory                        constructor
  7. //      Directory::addFile
  8. //
  9. // Description
  10. //
  11. //      Implementation of class Directory member functions.
  12. //
  13. // End ---------------------------------------------------------------------
  14.  
  15. // Interface Dependencies ---------------------------------------------------
  16.  
  17. #ifndef __DIR_H
  18. #include <dir.h>
  19. #define __DIR_H
  20. #endif
  21.  
  22. #ifndef __CLSTYPES_H
  23. #include <clstypes.h>
  24. #endif
  25.  
  26. #ifndef __DIRECTRY_H
  27. #include "directry.h"
  28. #endif
  29.  
  30. // End Interface Dependencies ------------------------------------------------
  31.  
  32. // Implementation Dependencies ----------------------------------------------
  33.  
  34. #ifndef __FILEDATA_H
  35. #include "filedata.h"
  36. #endif
  37.  
  38. // End Implementation Dependencies -------------------------------------------
  39.  
  40.  
  41. // Constructor //
  42.  
  43. Directory::Directory( char *pathName, sortOrder sortBy ) :
  44.                     SortedArray( 10, 0, 5 ), mask( pathName )
  45.  
  46. // Summary -----------------------------------------------------------------
  47. //
  48. //      Constructs a directory object.  A directory object contains
  49. //      a sorted array of the file names which are in the directory.
  50. //
  51. // Parameters
  52. //
  53. //      pathName
  54. //
  55. //      Character pointer to the pathname for the directory.  This
  56. //      pathname may include wildcard characters.
  57. //
  58. //      sortBy
  59. //
  60. //      The order by which we are to sort the directory entries.
  61. //
  62. // Functional Description
  63. //
  64. //      We walk through the directory, adding each of the file names to
  65. //      our directory object.
  66. //
  67. // End ---------------------------------------------------------------------
  68. {
  69.     struct ffblk fileBlock;
  70.     int morePathNames = !findfirst( mask, &fileBlock, 0 );
  71.     while( morePathNames )
  72.     {
  73.         addFile( fileBlock, sortBy );
  74.         morePathNames = !findnext( &fileBlock );
  75.     } // end while more files.
  76. }
  77. // End Constructor Directory::Directory //
  78.  
  79.  
  80. // Member Function //
  81.  
  82. void Directory::addFile( ffblk& fileBlock, sortOrder sortBy )
  83.  
  84. // Summary -----------------------------------------------------------------
  85. //
  86. //      Adds a file to a directory object.
  87. //
  88. // Parameters
  89. //
  90. //      fileBlock
  91. //
  92. //      The DOS file block we are to add to this directory object.
  93. //
  94. //      sortBy
  95. //
  96. //      The order in which files are to be sorted.
  97. //
  98. // Functional Description
  99. //
  100. //      Depending upon the sort order, we add a new object to the
  101. //      sorted array.
  102. //
  103. // End ---------------------------------------------------------------------
  104. {
  105.     switch( sortBy )
  106.     {
  107.         case byName:
  108.             add( *(new FilesByName( fileBlock )) );
  109.             break;
  110.         case byDate:
  111.             add( *(new FilesByDate( fileBlock )) );
  112.             break;
  113.         case bySize:
  114.             add( *(new FilesBySize( fileBlock )) );
  115.             break;
  116.     } // end switch on sort order.
  117. }
  118. // End Member Function Directory::addFile //
  119.  
  120.  
  121. // Member Function //
  122.  
  123. void Directory::printHeader( ostream& outputStream ) const
  124.  
  125. // Summary -----------------------------------------------------------------
  126. //
  127. //      Displays the directory mask for the directory listing
  128. //
  129. // Parameters
  130. //
  131. //      outputStream
  132. //
  133. //      The stream on which we will be writing the header.
  134. //
  135. // Functional Description
  136. //
  137. //      We print the directory mask
  138. //
  139. // End ---------------------------------------------------------------------
  140. {
  141.     outputStream << "Directory: " << mask << "\n    ";
  142. }
  143. // End Member Function Directory::printHeader //
  144.  
  145.  
  146. // Member Function //
  147.  
  148. void Directory::printSeparator( ostream& outputStream ) const
  149.  
  150. // Summary -----------------------------------------------------------------
  151. //
  152. //      Starts a new line for the next directory entry.
  153. //
  154. // Parameters
  155. //
  156. //      outputStream
  157. //
  158. //      The stream on which we will be writing the separator.
  159. //
  160. // End ---------------------------------------------------------------------
  161. {
  162.     outputStream << "\n    ";
  163. }
  164. // End Member Function Directory::printSeparator //
  165.  
  166.  
  167. // Member Function //
  168.  
  169. void Directory::printTrailer( ostream& outputStream ) const
  170.  
  171. // Summary -----------------------------------------------------------------
  172. //
  173. //      Displays a new line for the trailer.
  174. //
  175. // Parameters
  176. //
  177. //      outputStream
  178. //
  179. //      The stream on which we will be writing the trailer.
  180. //
  181. // End ---------------------------------------------------------------------
  182. {
  183.     outputStream << "\n";
  184. }
  185. // End Member Function Directory::printTrailer //
  186.  
  187.