home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / boolean.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  131 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. expanded class BOOLEAN
  13. --
  14. -- Note: An Eiffel BOOLEAN is mapped as a C int or as a Java int.
  15. --
  16.  
  17. inherit
  18.    BOOLEAN_REF
  19.       redefine
  20.          infix "and", infix "and then", infix "or",
  21.          infix "or else", infix "implies", infix "xor",
  22.          prefix "not", out_in_tagged_out_memory, fill_tagged_out_memory
  23.       end;
  24.  
  25. feature 
  26.  
  27.    infix "and" (other: BOOLEAN): BOOLEAN is
  28.          -- `and' of Current with `other'.
  29.          -- 
  30.          -- Note: when evaluation of `other' has no side effects, it 
  31.          -- may be better to use "and then" to avoid execution-time
  32.          -- overhead.
  33.       do
  34.          Result := Current and then other;
  35.       end;
  36.  
  37.    infix "and then" (other: BOOLEAN): BOOLEAN is
  38.          -- Semi-strict `and' of Current with `other'.
  39.       external "SmallEiffel"
  40.       end;
  41.  
  42.    infix "implies"(other: BOOLEAN): BOOLEAN is
  43.          -- Does Current imply `other'.
  44.       external "SmallEiffel"
  45.       end;
  46.  
  47.    infix "or" (other: BOOLEAN): BOOLEAN is
  48.          -- `or' of Current with `other'
  49.          --
  50.          -- Note: when evaluation of `other' has no side effects, it 
  51.          -- may be better to use "or else" to avoid execution-time
  52.          -- overhead.
  53.       do
  54.          Result := Current or else other;
  55.       end;
  56.  
  57.    infix "or else" (other: BOOLEAN): BOOLEAN is
  58.          -- Semi-strict `or' of Current with `other'
  59.       external "SmallEiffel"
  60.       end;
  61.  
  62.    infix "xor" (other: BOOLEAN): BOOLEAN is
  63.          -- `xor' of Current with `other'
  64.       do
  65.          if Current then
  66.             Result := not other;
  67.          else
  68.             Result := other;
  69.          end;
  70.       end;
  71.  
  72.    prefix "not": BOOLEAN is
  73.          -- `not' of Current.
  74.       do
  75.          if Current then
  76.          else
  77.             Result := true;
  78.          end;
  79.       end;
  80.  
  81.    to_string: STRING is
  82.       do
  83.          if Current then
  84.             Result := "true";
  85.          else
  86.             Result := "false";
  87.          end;
  88.       ensure
  89.          ("true").is_equal(Result) implies Current;
  90.          ("false").is_equal(Result) implies not Current
  91.       end;
  92.  
  93.    to_integer: INTEGER is
  94.       do
  95.          if Current then
  96.             Result := 1;
  97.          else
  98.             Result := 0;
  99.          end;
  100.       ensure
  101.          Result = 1 implies Current;
  102.          Result = 0 implies not Current
  103.       end;
  104.  
  105.    to_character: CHARACTER is
  106.       do
  107.          if Current then
  108.             Result := '1';
  109.          else
  110.             Result := '0';
  111.          end;
  112.       ensure
  113.          Result = '1' implies Current;
  114.          Result = '0' implies not Current
  115.       end;
  116.  
  117.    append_in(str: STRING) is
  118.       do
  119.          str.append(to_string);
  120.       end;
  121.  
  122. feature -- Object Printing :
  123.  
  124.    out_in_tagged_out_memory, fill_tagged_out_memory is
  125.       do
  126.          tagged_out_memory.append(to_string);
  127.       end;
  128.  
  129. end -- BOOLEAN
  130.  
  131.