home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / integer_ref.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  119 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. class INTEGER_REF
  13.  
  14. inherit
  15.    NUMERIC
  16.       undefine out_in_tagged_out_memory, fill_tagged_out_memory
  17.       redefine
  18.          infix "^", prefix "-", prefix "+"
  19.       end;
  20.    COMPARABLE
  21.       redefine out_in_tagged_out_memory, fill_tagged_out_memory
  22.       end;
  23.    
  24. feature 
  25.  
  26.    item: INTEGER;
  27.    
  28. feature
  29.    
  30.    set_item(value: like item) is
  31.       do
  32.          item := value;
  33.       end;
  34.    
  35.    infix "+" (other: like Current): like Current is
  36.       do
  37.          Result := item + other.item;
  38.       end;
  39.    
  40.    infix "-" (other: like Current): like Current is
  41.       do
  42.          Result := item - other.item;
  43.       end;
  44.    
  45.    infix "*" (other: like Current): like Current is
  46.       do
  47.          Result := item * other.item;
  48.       end;
  49.  
  50.    infix "/" (other: like Current): DOUBLE_REF is
  51.       do
  52.          Result := item / other.item;
  53.       end;
  54.  
  55.    infix "//" (other: like Current): like Current is
  56.          -- Integer division by `other'.
  57.       require
  58.          divisible (other)
  59.       do
  60.          Result := item // other.item;
  61.       end;
  62.  
  63.    infix "\\" (other: like Current): like Current is
  64.          -- Remainder of integer division by `other'.
  65.       require
  66.          valid_modulus: divisible (other)
  67.       do
  68.          Result := item \\ other.item;
  69.       end;
  70.  
  71.    infix "^" (exp: INTEGER): like Current is
  72.       do
  73.          Result := item ^ exp;
  74.       end;
  75.  
  76.    infix "<" (other: like Current): BOOLEAN is
  77.       do
  78.          Result := (item < other.item)
  79.       end;
  80.  
  81.    prefix "+": like Current is
  82.       do
  83.          Result := item;
  84.       end;
  85.  
  86.    prefix "-": like Current is
  87.       do
  88.          Result := -item;
  89.       end;
  90.  
  91.    divisible(other: like Current): BOOLEAN is
  92.       do
  93.          Result := (other.item /= 0)
  94.       end;
  95.  
  96.    one: like Current is
  97.       do
  98.          !!Result;
  99.          Result.set_item(1);
  100.       end;
  101.  
  102.    zero: like Current is
  103.       do
  104.          Result := 0;
  105.       end;
  106.  
  107.    out_in_tagged_out_memory, fill_tagged_out_memory is
  108.       do
  109.          item.fill_tagged_out_memory;
  110.       end;
  111.  
  112.    hash_code: INTEGER is
  113.       do
  114.          Result := item.hash_code;
  115.       end;
  116.  
  117. end -- INTEGER_REF
  118.  
  119.