Automatic generation produced by ISE Eiffel

Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:
indexing description: "Directories, in the Unix sense, with creation and exploration features" status: "See notice at end of class" date: "$Date: 2001-11-16 20:32:23 +0000 (Fri, 16 Nov 2001) $" revision: "$Revision: 51435 $" class DIRECTORY create make, make_open_read feature -- Initialization create_dir is -- Create a physical directory. require physical_not_exists: not exists local external_name: ANY do external_name := name.to_c file_mkdir ($external_name) end make (dn: STRING) is -- Create directory object for the directory -- of name dn. require string_exists: dn /= void do name := dn mode := close_directory end make_open_read (dn: STRING) is -- Create directory object for the directory -- of name dn and open it for reading. require string_exists: dn /= void do make (dn) open_read end feature -- Access change_name (new_name: STRING) is -- Change file name to new_name require not_new_name_void: new_name /= void file_exists: exists local ext_old_name, ext_new_name: ANY do ext_old_name := name.to_c ext_new_name := new_name.to_c eif_dir_rename ($ext_old_name, $ext_new_name) name := new_name ensure name_changed: name.is_equal (new_name) end close is -- Close directory. require is_open: not is_closed do dir_close (directory_pointer) mode := close_directory end has_entry (entry_name: STRING): BOOLEAN is -- Has directory the entry entry_name? -- The use of dir_temp is required not -- to change the position in the current -- directory entries list. require string_exists: entry_name /= void local ext_entry_name: ANY dir_temp: DIRECTORY do create dir_temp.make_open_read (name) ext_entry_name := entry_name.to_c Result := dir_temp.dir_search (dir_temp.directory_pointer, $ext_entry_name) /= default_pointer dir_temp.close end name: STRING -- Directory name open_read is -- Open directory name for reading. local external_name: ANY do external_name := name.to_c directory_pointer := dir_open ($external_name) mode := read_directory end readentry is -- Read next directory entry -- make result available in lastentry. -- Make result void if all entries have been read. require is_opened: not is_closed do lastentry := dir_next (directory_pointer) end start is -- Go to first entry of directory. require is_opened: not is_closed do dir_rewind (directory_pointer) end feature {NONE} -- Access C_memory: INTEGER is 2 -- Code for the C memory managed -- by the garbage collector -- (from MEM_CONST) Eiffel_memory: INTEGER is 1 -- Code for the Eiffel memory managed -- by the garbage collector -- (from MEM_CONST) Full_collector: INTEGER is 0 -- Statistics for full collections -- (from MEM_CONST) Incremental_collector: INTEGER is 1 -- Statistics for incremental collections -- (from MEM_CONST) Total_memory: INTEGER is 0 -- Code for all the memory managed -- by the garbage collector -- (from MEM_CONST) feature -- Measurement count: INTEGER is -- Number of entries in directory. require directory_exists: exists local dir_temp: DIRECTORY counter: INTEGER do create dir_temp.make_open_read (name) from dir_temp.start dir_temp.readentry until dir_temp.lastentry = void loop counter := counter + 1 dir_temp.readentry end Result := counter dir_temp.close end feature {NONE} -- Measurement gc_statistics (collector_type: INTEGER): GC_INFO is -- Garbage collection information for collector_type. -- (from MEMORY) require -- from MEMORY type_ok: collector_type = full_collector or collector_type = incremental_collector do create Result.make (collector_type) end memory_statistics (memory_type: INTEGER): MEM_INFO is -- Memory usage information for memory_type -- (from MEMORY) require -- from MEMORY type_ok: memory_type = total_memory or memory_type = eiffel_memory or memory_type = c_memory do create Result.make (memory_type) end feature -- Status report empty: BOOLEAN is obsolete "Use `is_empty' instead" -- Is directory empty? do Result := is_empty end exists: BOOLEAN is -- Does the directory exist? local external_name: ANY do external_name := name.to_c Result := eif_dir_exists ($external_name) end is_closed: BOOLEAN is -- Is current directory closed? do Result := mode = close_directory end is_empty: BOOLEAN is -- Is directory empty? require directory_exists: exists do Result := (count = 2) end is_executable: BOOLEAN is -- Is the directory executable? require directory_exists: exists local external_name: ANY do external_name := name.to_c Result := eif_dir_is_executable ($external_name) end is_readable: BOOLEAN is -- Is the directory readable? require directory_exists: exists local external_name: ANY do external_name := name.to_c Result := eif_dir_is_readable ($external_name) end is_writable: BOOLEAN is -- Is the directory writable? require directory_exists: exists local external_name: ANY do external_name := name.to_c Result := eif_dir_is_writable ($external_name) end lastentry: STRING -- Last entry read by readentry feature {NONE} -- Status report chunk_size: INTEGER is -- Minimal size of a memory chunk. The run-time always -- allocates a multiple of this size. -- If the environment variable EIF_MEMORY_CHUNK -- is defined, it is set to the closest reasonable -- value from it. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_get_chunk_size" end coalesce_period: INTEGER is -- Period of full coalesce (in number of collections) -- If the environment variable EIF_FULL_COALESCE_PERIOD -- is defined, it is set to the closest reasonable -- value from it. -- If null, no full coalescing is launched. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_coalesce_period" end collecting: BOOLEAN is -- Is garbage collection enabled? -- (from MEMORY) external "C | %"eif_memory.h%"" alias "gc_ison" end collection_period: INTEGER is -- Period of full collection. -- If the environment variable EIF_FULL_COLLECTION_PERIOD -- is defined, it is set to the closest reasonable -- value from it. -- If null, no full collection is launched. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "mem_pget" end generation_object_limit: INTEGER is -- Maximum size of object in generational scavenge zone. -- If the environment variable EIF_GS_LIMIT -- is defined, it is set to the closest reasonable -- value from it. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_generation_object_limit" end largest_coalesced_block: INTEGER is -- Size of largest coalesced block since last call to -- largest_coalesced; 0 if none. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "mem_largest" end max_mem: INTEGER is -- Maximum amount of bytes the run-time can allocate. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_get_max_mem" end memory_threshold: INTEGER is -- Minimum amount of bytes to be allocated before -- starting an automatic garbage collection. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "mem_tget" end referers (an_object: ANY): ARRAY [ANY] is -- Objects that refer to an_object. -- (from MEMORY) local a: ANY do create Result.make (0, 200) a := Result.area find_referers ($an_object, $a, Result.count) end scavenge_zone_size: INTEGER is -- Size of generational scavenge zone. -- If the environment variable EIF_MEMORY_SCAVENGE -- is defined, it is set to the closest reasonable -- value from it. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_scavenge_zone_size" end tenure: INTEGER is -- Maximum age of object before being considered -- as old (old objects are not scanned during -- partial collection). -- If the environment variable EIF_TENURE_MAX -- is defined, it is set to the closest reasonable -- value from it. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "eif_tenure" end feature {NONE} -- Status setting allocate_compact is -- Enter `memory' mode: will try to compact memory -- before requesting more from the operating system. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "mem_slow" end allocate_fast is -- Enter `speed' mode: will optimize speed of memory -- allocation rather than memory usage. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "mem_speed" end allocate_tiny is -- Enter `tiny' mode: will enter `memory' mode -- after having freed as much memory as possible. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "mem_tiny" end collection_off is -- Disable garbage collection. -- (from MEMORY) external "C | %"eif_garcol.h%"" alias "gc_stop" end collection_on is -- Enable garbage collection. -- (from MEMORY) external "C | %"eif_garcol.h%"" alias "gc_run" end disable_time_accounting is -- Disable GC time accounting (default). -- (from MEMORY) do gc_monitoring (False) end enable_time_accounting is -- Enable GC time accouting, accessible in gc_statistics. -- (from MEMORY) do gc_monitoring (True) end set_coalesce_period (value: INTEGER) is -- Set coalesce_period. Every value collection, -- the Garbage Collector will coalesce -- the whole memory. -- (from MEMORY) require -- from MEMORY positive_value: value >= 0 external "C | %"eif_memory.h%"" alias "eif_set_coalesce_period" end set_collection_period (value: INTEGER) is -- Set collection_period. Every value collection, -- the Garbage collector will perform a collection -- on the whole memory (full collection), otherwise -- a simple partial collection is done. -- (from MEMORY) require -- from MEMORY positive_value: value >= 0 external "C | %"eif_memory.h%"" alias "mem_pset" end set_max_mem (value: INTEGER) is -- Set the maximum amount of memory the run-time can allocate. -- (from MEMORY) require -- from MEMORY positive_value: value > 0 external "C | %"eif_memory.h%"" alias "eif_set_max_mem" end set_memory_threshold (value: INTEGER) is -- Set a new memory_threshold in bytes. Whenever the memory -- allocated for Eiffel reaches this value, an automatic -- collection is performed. -- (from MEMORY) require -- from MEMORY positive_value: value > 0 external "C | %"eif_memory.h%"" alias "mem_tset" end feature -- Removal delete is -- Delete directory if empty require directory_exists: exists empty_directory: is_empty local external_name: ANY do external_name := name.to_c eif_dir_delete ($external_name) end delete_content is -- Delete all files located in current directory and its -- subdirectories. require directory_exists: exists local l: LINEAR [STRING] file_name: FILE_NAME file: RAW_FILE dir: DIRECTORY do l := linear_representation from l.start until l.after loop if not l.item.is_equal (".") and not l.item.is_equal ("..") then create file_name.make_from_string (name) file_name.set_file_name (l.item) create file.make (file_name) if file.exists and then not file.is_symlink and then file.is_directory then create dir.make (file_name) dir.recursive_delete else if file.exists and then file.is_writable then file.delete end end end l.forth end end delete_content_with_action (action: PROCEDURE [ANY, TUPLE]; is_cancel_requested: FUNCTION [ANY, TUPLE, BOOLEAN]; file_number: INTEGER) is -- Delete all files located in current directory and its -- subdirectories. -- -- action is called each time file_number files has -- been deleted and before the function exits. -- action may be set to Void if you don't need it. -- -- Same for is_cancel_requested. -- Make it return True to cancel the operation. -- is_cancel_requested may be set to Void if you don't need it. require directory_exists: exists valid_file_number: file_number > 0 local l: LINEAR [STRING] file_name: FILE_NAME file: RAW_FILE dir: DIRECTORY file_count: INTEGER deleted_files: ARRAYED_LIST [STRING] deleted_files_tuple: TUPLE [ARRAYED_LIST [STRING]] current_directory: STRING parent_directory: STRING requested_cancel: BOOLEAN do file_count := 1 create deleted_files.make (file_number) create deleted_files_tuple.make l := linear_representation current_directory := "." parent_directory := ".." from l.start until l.after or requested_cancel loop if not l.item.is_equal (current_directory) and not l.item.is_equal (parent_directory) then create file_name.make_from_string (name) file_name.set_file_name (l.item) create file.make (file_name) if file.exists and then not file.is_symlink and then file.is_directory then create dir.make (file_name) dir.recursive_delete_with_action (action, is_cancel_requested, file_number) else if file.exists and then file.is_writable then file.delete end end deleted_files.extend (file_name) file_count := file_count + 1 if file_count > file_number then if action /= void then deleted_files_tuple.put (deleted_files, 1) action.call (deleted_files_tuple) end if is_cancel_requested /= void then requested_cancel := is_cancel_requested.item ([]) end deleted_files.wipe_out file_count := 1 end end l.forth end if file_count > 1 then if action /= void then deleted_files_tuple.put (deleted_files, 1) action.call (deleted_files_tuple) end deleted_files.wipe_out file_count := 1 end end dispose is -- Ensure this medium is closed when garbage collected. do if not is_closed then close end end recursive_delete is -- Delete directory, its files and its subdirectories. require directory_exists: exists do delete_content delete end recursive_delete_with_action (action: PROCEDURE [ANY, TUPLE]; is_cancel_requested: FUNCTION [ANY, TUPLE, BOOLEAN]; file_number: INTEGER) is -- Delete directory, its files and its subdirectories. -- -- action is called each time file_number files has -- been deleted and before the function exits. require directory_exists: exists local deleted_files: ARRAYED_LIST [STRING] do delete_content_with_action (action, is_cancel_requested, file_number) if (is_cancel_requested = void) or else (not is_cancel_requested.item ([])) then delete if action /= void then create deleted_files.make (1) deleted_files.extend (name) action.call ([deleted_files]) end end end feature {NONE} -- Removal collect is -- Force a partial collection cycle if garbage -- collection is enabled; do nothing otherwise. -- (from MEMORY) external "C | %"eif_eiffel.h%"" end free (object: ANY) is -- Free object, by-passing garbage collection. -- Erratic behavior will result if the object is still -- referenced. -- (from MEMORY) do mem_free ($object) end full_coalesce is -- Coalesce the whole memory: merge adjacent free -- blocks to reduce fragmentation. Useful, when -- a lot of memory is allocated with garbage collector off. -- (from MEMORY) external "C | %"eif_memory.h%"" alias "mem_coalesc" end full_collect is -- Force a full collection cycle if garbage -- collection is enabled; do nothing otherwise. -- (from MEMORY) external "C | %"eif_garcol.h%"" alias "plsc" end mem_free (addr: POINTER) is -- Free memory of object at addr. -- (Preferred interface is free.) -- (from MEMORY) external "C | %"eif_memory.h%"" end feature -- Conversion linear_representation: ARRAYED_LIST [STRING] is -- The entries, in sequential format. local dir_temp: DIRECTORY do create dir_temp.make_open_read (name) create Result.make (count) from dir_temp.start dir_temp.readentry until dir_temp.lastentry = void loop Result.extend (dir_temp.lastentry) dir_temp.readentry end dir_temp.close end feature {DIRECTORY} -- Implementation dir_search (dir_ptr: POINTER; entry: POINTER): POINTER is -- Return the DIRENTRY structure corresponding -- to the name entry of directory dir_ptr. external "C | %"eif_dir.h%"" end directory_pointer: POINTER -- Directory pointer as required in C feature {NONE} -- Implementation Close_directory: INTEGER is unique dir_close (dir_ptr: POINTER) is -- Close the directory dir_ptr. external "C | %"eif_dir.h%"" end dir_next (dir_ptr: POINTER): STRING is -- Return the next entry for directory 'dir_ptr'. external "C | %"eif_dir.h%"" end dir_open (dir_name: POINTER): POINTER is -- Open the directory dir_name. external "C | %"eif_dir.h%"" end dir_rewind (dir_ptr: POINTER) is -- Rewind the directory dir_ptr. external "C | %"eif_dir.h%"" end eif_dir_delete (dir_name: POINTER) is -- Delete the directory dir_name. external "C | %"eif_dir.h%"" end eif_dir_exists (dir_name: POINTER): BOOLEAN is -- Does the directory dir_name exist? external "C | %"eif_dir.h%"" end eif_dir_is_executable (dir_name: POINTER): BOOLEAN is -- Is dir_name executable? external "C | %"eif_dir.h%"" end eif_dir_is_readable (dir_name: POINTER): BOOLEAN is -- Is dir_name readable? external "C | %"eif_dir.h%"" end eif_dir_is_writable (dir_name: POINTER): BOOLEAN is -- Is dir_name writable? external "C | %"eif_dir.h%"" end eif_dir_rename (old_name, new_name: POINTER) is -- Change directory name from old_name to new_name. external "C | %"eif_file.h%"" alias "file_rename" end file_mkdir (dir_name: POINTER) is -- Make directory dir_name. external "C | %"eif_file.h%"" end find_referers (target: POINTER; esult: POINTER; result_size: INTEGER) is -- (from MEMORY) external "C | %"eif_traverse.h%"" end gc_monitoring (flag: BOOLEAN) is -- Set up GC monitoring according to flag -- (from MEMORY) external "C | %"eif_memory.h%"" alias "gc_mon" end mode: INTEGER -- Status mode of the directory. -- Possible values are the following: Read_directory: INTEGER is unique invariant -- from ANY reflexive_equality: standard_is_equal (Current) reflexive_conformance: conforms_to (Current) indexing library: "[ EiffelBase: Library of reusable components for Eiffel. ]" status: "[ Copyright 1986-2001 Interactive Software Engineering (ISE). For ISE customers the original versions are an ISE product covered by the ISE Eiffel license and support agreements. ]" license: "[ EiffelBase may now be used by anyone as FREE SOFTWARE to develop any product, public-domain or commercial, without payment to ISE, under the terms of the ISE Free Eiffel Library License (IFELL) at http://eiffel.com/products/base/license.html. ]" source: "[ Interactive Software Engineering Inc. ISE Building 360 Storke Road, Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Electronic mail <info@eiffel.com> Customer support http://support.eiffel.com ]" info: "[ For latest info see award-winning pages: http://eiffel.com ]" end -- class DIRECTORY
Classes Clusters Cluster hierarchy Chart Relations Text Flat Contracts Flat contracts Go to:

-- Generated by ISE Eiffel --
For more details: www.eiffel.com