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