home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / directory.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  108 lines

  1. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  2. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  3. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  4. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  5. -- this header is kept unaltered, and a notification of the changes is added.
  6. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  7. -- another product.
  8. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  9. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  10. --                       http://www.loria.fr/SmallEiffel
  11. --
  12. class DIRECTORY
  13.    --
  14.    -- Tools for file-system directory handling.
  15.    -- 
  16.    -- Clean hight-level facade for class BASIC_DIRECTORY.
  17.    --
  18. creation connect_to
  19.  
  20. feature {NONE}
  21.  
  22.    basic_directory: BASIC_DIRECTORY;
  23.  
  24. feature
  25.  
  26.    is_connected: BOOLEAN;
  27.  
  28. feature -- Creation / Modification :
  29.  
  30.    connect_to(new_path: STRING) is
  31.       require
  32.          not new_path.empty
  33.       do
  34.          if basic_directory = Void then
  35.             !!basic_directory.make;
  36.          end;
  37.          if basic_directory.set_path(new_path) then
  38.             is_connected := true;
  39.          else
  40.             is_connected := false;
  41.          end;
  42.       end;
  43.  
  44. feature -- Access :
  45.  
  46.    lower: INTEGER is 1;
  47.          -- Index of the first item.
  48.  
  49.    upper: INTEGER is
  50.          -- Index of the last item.
  51.       do
  52.          if is_connected then
  53.             Result := basic_directory.upper + 1;
  54.          end;
  55.       end;
  56.  
  57.    count: INTEGER is
  58.          -- Number of items (files or directories) in Current.
  59.       do
  60.          if is_connected then
  61.             Result := basic_directory.count;
  62.          end;
  63.       ensure
  64.          Result >= 0
  65.       end;
  66.  
  67.    valid_index(index: INTEGER): BOOLEAN is
  68.       do
  69.          if index >= 1 then
  70.             if is_connected then
  71.                Result := basic_directory.valid_index(index - 1);
  72.             end;
  73.          end;
  74.       ensure
  75.          Result = index.in_range(1,count)
  76.       end;
  77.  
  78.    path: STRING is
  79.       require
  80.          is_connected
  81.       do
  82.          Result := basic_directory.path;
  83.       end;
  84.  
  85.    name(index: INTEGER): STRING is
  86.          -- Return the name of entry (file or subdirectory) at `index'.
  87.       require
  88.          is_connected;
  89.          valid_index(index)
  90.       do
  91.          Result := basic_directory.name(index - 1);
  92.       ensure
  93.          has(Result)
  94.       end;
  95.  
  96.    has(entry_name: STRING): BOOLEAN is
  97.          -- Does Current contain the `entry_name' (file or subdirectory) ?
  98.       require
  99.          is_connected;
  100.          not entry_name.empty
  101.       do
  102.          Result := basic_directory.has(entry_name);
  103.       end;
  104.  
  105.  
  106. end -- DIRECTORY
  107.  
  108.