ANY FILTER_OUTPUT_STREAM NONE
class interface TEXT_FILE_WRITE
   --
   -- Basic output facilities to write a named file on the disk.
   --
   -- Note: most features are common with STD_OUTPUT so you can test your
   --       program first on the screen and then, changing of instance
   --       (STD_OUTPUT/TEXT_FILE_WRITE), doing the same on a file.
   --

creation
   make
      -- The new created object is not connected. (See also connect_to and
      -- connect_for_appending_to.)
      ensure
         not is_connected

   connect_to (new_path: STRING)
      -- Truncate file to zero length or create text file for writing.
      -- The stream is positioned at the beginning of the file.
      require
         not is_connected;
         not new_path.is_empty
      ensure
         is_connected implies character_count = 0;
         is_connected implies path.same_as(new_path)

   connect_for_appending_to (new_path: STRING)
      -- Open for writing. The file is created if it does not exist.
      -- The stream is positioned at the end of the file.
      require
         not is_connected;
         not new_path.is_empty
      ensure
         is_connected implies character_count = 0

feature(s) from FILE
   path: STRING
      -- Not Void when connected to the corresponding file on the disk.

   is_connected: BOOLEAN
      -- Is this file connected to some file of the operating system?
      ensure
         definition: Result = (path /= Void)

   connect_to (new_path: STRING)
      -- Truncate file to zero length or create text file for writing.
      -- The stream is positioned at the beginning of the file.
      require
         not is_connected;
         not new_path.is_empty
      ensure
         is_connected implies character_count = 0;
         is_connected implies path.same_as(new_path)

   disconnect
      -- Disconnect from any file.
      require
         is_connected
      require else
         is_connected
      ensure
         filter = Void;
         not is_connected

feature(s) from STREAM
   is_filtered: BOOLEAN

   detach
      ensure
         not is_filtered

feature(s) from STREAM
   set_filter (a_filter: FILTER_OUTPUT_STREAM)
      require
         a_filter /= Void
      ensure
         filter = a_filter

   filter: FILTER_OUTPUT_STREAM

feature(s) from OUTPUT_STREAM
   put_character (c: CHARACTER)
      require
         is_connected;
         not is_filtered and then can_put_character(c)

   flush
      -- Flushes the pipe. If is_filtered, calls the filter's
      -- flush instead.
      require
         is_connected

   can_put_character (c: CHARACTER): BOOLEAN

feature(s) from OUTPUT_STREAM
   filtered_put_character (c: CHARACTER)
      require
         is_connected;
         can_put_character(c)

   filtered_flush
      require
         is_connected
      ensure
         flushed_character_count = character_count

feature(s) from OUTPUT_STREAM
   put_string (s: STRING)
      -- Output s to current output device.
      require
         is_connected;
         not is_filtered;
         s /= Void

   put_unicode_string (unicode_string: UNICODE_STRING)
      -- Output the UTF-8 encoding of the unicode_string.
      require
         is_connected;
         not is_filtered;
         unicode_string /= Void

feature(s) from OUTPUT_STREAM
   -- To write a number:

   put_integer (i: INTEGER_64)
      -- Output i to current output device.
      require
         is_connected;
         not is_filtered

   put_integer_format (i: INTEGER_64; s: INTEGER)
      -- Output i to current output device using at most s character.
      require
         is_connected;
         not is_filtered

   put_real (r: REAL)
      -- Output r to current output device.
      require
         is_connected;
         not is_filtered

   put_real_format (r: REAL; f: INTEGER)
      -- Output r with only f digit for the fractionnal part.
      -- Examples:
      --    put_real(3.519,2) print "3.51".
      require
         is_connected;
         not is_filtered;
         f >= 0

   put_double (d: DOUBLE)
      -- Output d to current output device.
      require
         is_connected;
         not is_filtered

   put_double_format (d: DOUBLE; f: INTEGER)
      -- Output d with only f digit for the fractionnal part.
      -- Examples:
      --    put_double(3.519,2) print "3.51".
      require
         is_connected;
         not is_filtered;
         f >= 0

   put_number (number: NUMBER)
      -- Output the number.
      require
         is_connected;
         not is_filtered;
         number /= Void

feature(s) from OUTPUT_STREAM
   -- Other features:

   put_boolean (b: BOOLEAN)
      -- Output b to current output device according
      -- to the Eiffel format.
      require
         is_connected;
         not is_filtered

   put_pointer (p: POINTER)
      -- Output a viewable version of p.
      require
         is_connected;
         not is_filtered

   put_new_line
      -- Output a newline character.
      require
         is_connected;
         not is_filtered

   put_spaces (nb: INTEGER)
      -- Output nb spaces character.
      require
         is_connected;
         not is_filtered;
         nb >= 0

   append_file (file_name: STRING)
      require
         is_connected;
         not is_filtered;
         file_exists(file_name)

feature(s) from MEMORY
   -- Garbage collector information and tuning:

   collecting: BOOLEAN
      -- Is garbage collection enabled?

   collection_off
      -- Disable garbage collection.

   collection_on
      -- Enable garbage collection.

   full_collect
      -- Force a full collection cycle if garbage collection is
      -- enabled (i.e. collecting is True); do nothing otherwise.

   collector_counter: INTEGER
      -- The number of collections actually performed or -1 when the
      -- system is not using the SmartEiffel garbage collector (i.e. when
      -- the system is compiled using the -no_gc flag).
      ensure
         Result >= -1

feature(s) from MEMORY
   -- SmartEiffel Garbage collector information and tuning:

   smart_eiffel_collector: BOOLEAN
      -- Is the SmartEiffel garbage collector really used?
      ensure
         Result = (collector_counter >= 0)

   low_memory_strategy: BOOLEAN
      -- Is the low memory strategy in use? When this strategy is used,
      -- the garbage collector try to use as few memory as possible.
      require
         smart_eiffel_collector

   set_low_memory_strategy
      require
         smart_eiffel_collector
      ensure
         low_memory_strategy

   high_memory_strategy: BOOLEAN
      -- Is the high memory strategy in use? When this strategy is used,
      -- the garbage collector assume that more memory can be allocated
      -- if necessary.
      require
         smart_eiffel_collector

   set_high_memory_strategy
      require
         smart_eiffel_collector
      ensure
         high_memory_strategy

   default_memory_strategy: BOOLEAN
      -- Is the default memory strategy in use? This is the default initial
      -- mode for the garbage collector (somewhere between low_memory_strategy
      -- and high_memory_strategy).
      require
         smart_eiffel_collector

   set_default_memory_strategy
      require
         smart_eiffel_collector
      ensure
         default_memory_strategy

   allocated_bytes: INTEGER
      -- Total number of allocated bytes of memory in the heap.
      require
         collector_counter >= 0

feature(s) from TEXT_FILE_WRITE
   flushed_character_count: INTEGER_64
      -- Note that '%N' is counted as one character even if two
      -- bytes are written in the file.

   character_count: INTEGER_64
      -- See also flushed_character_count
      -- Note that '%N' is counted as one character even if two
      -- bytes are written in the file.
      require
         is_connected

   connect_for_appending_to (new_path: STRING)
      -- Open for writing. The file is created if it does not exist.
      -- The stream is positioned at the end of the file.
      require
         not is_connected;
         not new_path.is_empty
      ensure
         is_connected implies character_count = 0



end of TEXT_FILE_WRITE