home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / pointer.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  123 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 POINTER
  13. --
  14. -- References to objects meant to be exchanged with non-Eiffel 
  15. -- software.
  16. --
  17. -- Note : An Eiffel POINTER is mapped as C type "void *" or as
  18. -- Java "java.lang.Object" type.
  19. --
  20.  
  21. inherit 
  22.    POINTER_REF
  23.       redefine fill_tagged_out_memory, hash_code
  24.       end;
  25.  
  26. feature
  27.  
  28.    is_null: BOOLEAN is
  29.          -- Is the external POINTER a NULL pointer ?
  30.       do
  31.          Result := not is_not_null;
  32.       end;
  33.  
  34.    is_not_null: BOOLEAN is
  35.          -- Is the external POINTER a non-NULL pointer ?
  36.       external "SmallEiffel"
  37.       end;
  38.  
  39.    is_void: BOOLEAN is
  40.       obsolete "This feature will be soon removed. %
  41.                %Since release -0.78, the new name for this feature %
  42.                %is `is_null'. Please, update your code."
  43.       do
  44.          Result := is_null;
  45.       end;
  46.  
  47.    is_not_void: BOOLEAN is
  48.       obsolete "This feature will be soon removed. %
  49.                %Since release -0.78, the new name for this feature %
  50.                %is `is_not_null'. Please, update your code."
  51.       do
  52.          Result := is_not_null;
  53.       end;
  54.  
  55. feature -- Object Printing :
  56.  
  57.    append_in(str: STRING) is
  58.          -- Append on `str' a viewable version of Current.
  59.       local
  60.          i: INTEGER;
  61.       do
  62.          sprintf_pointer(tmp_native_array);
  63.          from
  64.             i := 0;
  65.          until
  66.             tmp_native_array.item(i) = '%U'
  67.          loop
  68.             str.extend(tmp_native_array.item(i));
  69.             i := i + 1;
  70.          end;
  71.       end;
  72.  
  73.    fill_tagged_out_memory is
  74.       do
  75.          Current.append_in(tagged_out_memory);
  76.       end;
  77.  
  78.    hash_code: INTEGER is
  79.       local
  80.          i: INTEGER;
  81.          view: STRING;
  82.       do
  83.          view := "    ";
  84.          view.clear;
  85.          append_in(view);
  86.          from
  87.             i := view.count;
  88.          until
  89.             i = 0
  90.          loop
  91.             if not view.item(i).is_digit then
  92.                view.remove(i);
  93.             end;
  94.             i := i - 1;
  95.          end;
  96.          if view.count = 0 then
  97.             view.extend('1');
  98.          end;
  99.          Result := view.to_integer.hash_code;
  100.       end;
  101.  
  102. feature 
  103.  
  104.    to_any: ANY is
  105.          -- Assume that `Current' is really an Eiffel reference.
  106.       do
  107.          c_inline_c("R=((void*)C);");
  108.       end;
  109.  
  110. feature {NONE}
  111.  
  112.    sprintf_pointer(native_array: NATIVE_ARRAY[CHARACTER]) is
  113.       external "SmallEiffel"
  114.       end;
  115.    
  116.    tmp_native_array: NATIVE_ARRAY[CHARACTER] is
  117.       once
  118.          Result := Result.calloc(32);
  119.       end;
  120.  
  121. end -- POINTER
  122.  
  123.