home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / LIBRARY / AVAL.SA < prev    next >
Text File  |  1994-10-25  |  4KB  |  94 lines

  1. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  2. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  3. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  4. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  5. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  6. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  7.  
  8. -- aval.sa: Built-in value arrays, only for inclusion.
  9.  
  10. -------------------------------------------------------------------
  11. value class AVAL{T} is
  12.    -- Built-in value arrays of elements of type T. Only exists for
  13.    -- inclusion by other value types. They must redefine `asize' to
  14.    -- get a non-trivial array portion. Array indices start at 0 and
  15.    -- go up to "asize-1". Together with BOOL this is the
  16.    -- fundamental class for the construction of objects. All feature 
  17.    -- names begin with "a" to minimize name conflicts when included.
  18.    
  19.    const asize:INT:=0;
  20.       -- The number of elements of type T in self. Must be redefined as 
  21.       -- a constant in the including class. Built-in.
  22.  
  23.    aget(ind:INT):T 
  24.       -- The element of self with index `ind'. Built-in.
  25.       pre ind.is_bet(0,asize-1) is 
  26.       raise "AVAL{T}::aget(INT):T undefined." end;            
  27.  
  28.    aset(ind:INT,val:T):SAME 
  29.       -- Return a copy of self with the component with index `ind' set 
  30.       -- to `val'. Built-in. 
  31.       pre ind.is_bet(0,asize-1) is 
  32.       raise "AVAL{T}::aset(INT,T) undefined." end;                  
  33.  
  34.    aelt!:T is
  35.       -- Yield each element of self in order. Built-in.
  36.       loop yield [asize.times!] end end;
  37.  
  38.    aelt!(beg:INT):T
  39.       -- Yield each element of self starting at `beg'. Built-in.
  40.       pre beg.is_bet(0,asize-1) is
  41.       loop yield [beg.upto!(asize-1)] end end;
  42.    
  43.    aelt!(beg,num:INT):T
  44.       -- Yield `num' successive elements of self starting at
  45.       -- index `beg'. Built-in.
  46.       pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg) is
  47.       loop yield [beg.upto!(beg+num-1)] end end;
  48.  
  49.    private is_legal_aelts_arg(beg,num,step:INT):BOOL is
  50.       -- True if the arguments are legal values for `aelts'.
  51.       return beg.is_bet(0,asize-1) and
  52.          ((step>0 and num.is_bet(0,(asize-beg+step-1)/step)) or
  53.           (step<0 and num.is_bet(0,(beg-step)/-step))) end;
  54.    
  55.    aelt!(beg,num,step:INT):T
  56.       -- Yield `num' elements of self starting at `beg' and stepping
  57.       -- by `step' which must not be zero. Built-in.
  58.       pre is_legal_aelts_arg(beg,num,step) is
  59.       loop yield [beg.step!(num,step)] end end;
  60.    
  61.    acopy_from(beg:INT,src:SAME):SAME 
  62.       -- Return a copy of self modified by copying elements from `src'
  63.       -- into locations with indices starting at `beg'. Built-in.
  64.       pre beg.is_bet(0,asize-1) is
  65.       r::=self; 
  66.       loop r:=r.aset(beg.upto!(asize-1),src.aelt!) end;
  67.       return r end;
  68.    
  69.    acopy_from(beg,num:INT,src:SAME):SAME
  70.       -- Return a copy of self modified by copying `num' elements from 
  71.       -- `src' into locations with indices starting at `beg'. Built-in.   
  72.       pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg) is
  73.       r::=self; 
  74.       loop r:=r.aset(beg.upto!(beg+num-1),src.aelt!) end;
  75.       return r end;      
  76.    
  77.    acopy_from(beg,num,srcbeg:INT,src:SAME):SAME
  78.       -- Return a copy of self modified by copying `num' elements from 
  79.       -- `src' starting at index `srcbeg' into locations with indices 
  80.       -- starting at `beg'. Built-in.      
  81.       pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg)
  82.          and num<src.asize-srcbeg is   
  83.       r::=self; 
  84.       loop r:=r.aset(beg.upto!(beg+num-1),src.aelt!(srcbeg)) end;
  85.       return r end;            
  86.    
  87.    ainds!:INT is
  88.       -- Yield the indices of self in order. Built-in.
  89.       loop yield asize.times! end end;
  90.  
  91. end; -- class AVAL{T}
  92.  
  93. -------------------------------------------------------------------
  94.