home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / baku100.zip / baku100 / Kernel / Array.tonyu next >
Text File  |  2003-01-19  |  2KB  |  82 lines

  1. extends classes.lang.Object;
  2.  
  3. constructor Array() {init();}
  4.  
  5. function init() { _x=native_init();}
  6. native native_init ;
  7. function add(d) { native_add(_x,d);}
  8. native native_add ;
  9. function insert(i,o) { _n_insert(_x,i,o); } 
  10. native _n_insert;
  11. function get(i) { return native_get(_x,i);}
  12. native native_get ;
  13. function set(i,c) { return native_set(_x,i,c);}
  14. native native_set ;
  15. function size() { return native_size(_x);}
  16. native native_size ;
  17. function delete(i) { return native_delete(_x,i);}
  18. native native_delete ;
  19. function indexOf(o) { return native_indexof(_x,o);}
  20. native native_indexof ;
  21. function lightIndexOf(o) { return native_lightindexof(_x,o);}
  22. native native_lightindexof ;
  23.  
  24. function remove(o) {
  25.   var i; 
  26.   i=indexOf(o);
  27.   if (i>=0) return delete(i);
  28.   return null;
  29.  
  30. native _n_pack;
  31. function pack(v) {
  32.    return _n_pack (_x,v);
  33. }  
  34.  
  35. function _setBody(x) {
  36.   native_free(_x);
  37.   _x=x;
  38. }
  39.  
  40. destructor free() { native_free(_x); _x=null; }
  41. native native_free ;
  42.  
  43. function gc_mark() {
  44.     var i,c;
  45.     i=0;c=size();
  46.     while(i<c) {
  47.       native_gc_mark(get(i));i=i+1;
  48.     }
  49. }
  50.  
  51. function clear() {
  52.    while (size()>0) delete(0);
  53. }
  54.  
  55. function load(fn) {
  56.    var s,eof,ln;
  57.    s=new FileReader(fn);
  58.    if (s.error() ) return s.error();
  59.    eof=0;clear();
  60.    while (!eof) {
  61.       ln=s.readLn();
  62.       if (ln!=null) add(ln); else eof=1;
  63.    }
  64.    s.close();
  65.    return 0;
  66. }
  67.  
  68. function save(fn) {
  69.    var s,ln,lc;
  70.    s=new FileWriter(fn);
  71.    if (s.error()) return s.error();
  72.    lc=size();
  73.    for (ln in this) {
  74.        lc-=1; 
  75.        if (lc==0) s.writeStr(ln); else s.writeLn(ln);
  76.    }
  77.    s.close();
  78.    return 0;
  79. }
  80.  
  81.