home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / output_stream.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  223 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://SmallEiffel.loria.fr
  11. --
  12. deferred class OUTPUT_STREAM
  13.    --
  14.    -- This abstract class is the superclass of all classes representing 
  15.    -- an output stream of bytes. 
  16.    --
  17.  
  18. feature -- State of the stream :
  19.  
  20.    is_connected: BOOLEAN is
  21.       deferred
  22.       end;
  23.  
  24. feature -- To write one character at a time :
  25.  
  26.    put_character(c: CHARACTER) is
  27.       require
  28.          is_connected
  29.       deferred
  30.       end;
  31.  
  32. feature 
  33.  
  34.    put_string(s: STRING) is
  35.          -- Output `s' to current output device.
  36.       require
  37.          is_connected;
  38.          s /= Void
  39.       local
  40.          i: INTEGER;
  41.       do
  42.          from  
  43.             i := 1;
  44.          until
  45.             i > s.count
  46.          loop
  47.             put_character(s.item(i));
  48.             i := i + 1;
  49.          end;
  50.       end;
  51.    
  52.    putstring(s: STRING) is
  53.       obsolete "Please use ELKS 95 `put_string' instead."
  54.       do
  55.          put_string(s);
  56.       end;
  57.  
  58. feature -- To write a number :
  59.  
  60.    put_integer(i: INTEGER) is
  61.          -- Output `i' to current output device.
  62.       require
  63.          is_connected
  64.       do
  65.          tmp_string.clear;
  66.          i.append_in(tmp_string);
  67.          put_string(tmp_string);
  68.       end;
  69.    
  70.    put_integer_format(i, s: INTEGER) is
  71.          -- Output `i' to current output device using at most
  72.          -- `s' character.
  73.       require
  74.          is_connected
  75.       do
  76.          tmp_string.clear;
  77.          i.append_in_format(tmp_string,s);
  78.          put_string(tmp_string);
  79.       end;
  80.    
  81.    put_real(r: REAL) is
  82.          -- Output `r' to current output device.
  83.       require
  84.          is_connected
  85.       do
  86.          tmp_string.clear;
  87.          r.append_in(tmp_string);
  88.          put_string(tmp_string);
  89.       end;
  90.    
  91.    put_real_format(r: REAL; f: INTEGER) is
  92.          -- Output `r' with only `f' digit for the fractionnal part.
  93.          -- Examples: 
  94.          --    put_real(3.519,2) print "3.51".
  95.       require
  96.          is_connected;
  97.          f >= 0;
  98.       do
  99.          tmp_string.clear;
  100.          r.append_in_format(tmp_string,f);
  101.          put_string(tmp_string);
  102.       end;
  103.    
  104.    put_double(d: DOUBLE) is
  105.          -- Output `d' to current output device.
  106.       require
  107.          is_connected
  108.       do
  109.          tmp_string.clear;
  110.          d.append_in(tmp_string);
  111.          put_string(tmp_string);
  112.       end;
  113.    
  114.    put_double_format(d: DOUBLE; f: INTEGER) is
  115.          -- Output `d' with only `f' digit for the fractionnal part.
  116.          -- Examples: 
  117.          --    put_double(3.519,2) print "3.51". 
  118.       require
  119.          is_connected;
  120.          f >= 0
  121.       do
  122.          tmp_string.clear;
  123.          d.append_in_format(tmp_string,f);
  124.          put_string(tmp_string);
  125.       end;
  126.  
  127. feature -- Other features :   
  128.  
  129.    put_boolean(b: BOOLEAN) is
  130.          -- Output `b' to current output device according
  131.          -- to the Eiffel format.
  132.       require
  133.          is_connected
  134.       do
  135.          if b then
  136.             put_string("true");
  137.          else
  138.             put_string("false");
  139.          end;
  140.       end;
  141.    
  142.    put_pointer(p: POINTER) is
  143.          -- Output a viewable version of `p'.
  144.       require
  145.          is_connected
  146.       do
  147.          tmp_string.clear;
  148.          p.append_in(tmp_string);
  149.          put_string(tmp_string);
  150.       end;
  151.  
  152.    put_new_line is
  153.          -- Output a newline character.
  154.       require
  155.          is_connected
  156.       do
  157.          put_character('%N');
  158.       end;
  159.    
  160.    put_spaces(nb: INTEGER) is
  161.       -- Output `nb' spaces character.
  162.       require
  163.          nb >= 0
  164.       local
  165.          count : INTEGER;
  166.       do
  167.          from  
  168.          until
  169.             count >= nb
  170.          loop
  171.             put_character(' ');
  172.             count := count + 1;
  173.          end;
  174.       end; 
  175.    
  176.    append_file(file_name: STRING) is
  177.       require
  178.          is_connected;
  179.          file_exists(file_name);
  180.       local
  181.          c: CHARACTER;
  182.       do
  183.          tmp_file_read.connect_to(file_name);
  184.          from  
  185.             tmp_file_read.read_character;
  186.          until
  187.             tmp_file_read.end_of_input
  188.          loop
  189.             c := tmp_file_read.last_character;
  190.             put_character(c);
  191.             tmp_file_read.read_character;
  192.          end;
  193.          tmp_file_read.disconnect;
  194.       end;
  195.  
  196.    flush is
  197.       deferred
  198.       end;
  199.  
  200. feature {NONE}
  201.  
  202.    write_byte(stream_pointer: POINTER; byte: CHARACTER) is
  203.          -- Low level buffered output.
  204.       external "SmallEiffel"
  205.       end;
  206.  
  207.    flush_stream(stream_pointer: POINTER) is
  208.       external "SmallEiffel"
  209.       end;
  210.  
  211.    tmp_file_read: STD_FILE_READ is
  212.       once
  213.          !!Result.make;
  214.       end;
  215.    
  216.    tmp_string: STRING is
  217.       once
  218.          !!Result.make(512);
  219.       end;
  220.    
  221. end -- OUTPUT_STREAM
  222.  
  223.