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 >
Wrap
Text File
|
1994-10-25
|
4KB
|
94 lines
-- Copyright (C) International Computer Science Institute, 1994. COPYRIGHT --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in --
-- the file "Doc/License" of the Sather distribution. The license is also --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. --
--------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
-- aval.sa: Built-in value arrays, only for inclusion.
-------------------------------------------------------------------
value class AVAL{T} is
-- Built-in value arrays of elements of type T. Only exists for
-- inclusion by other value types. They must redefine `asize' to
-- get a non-trivial array portion. Array indices start at 0 and
-- go up to "asize-1". Together with BOOL this is the
-- fundamental class for the construction of objects. All feature
-- names begin with "a" to minimize name conflicts when included.
const asize:INT:=0;
-- The number of elements of type T in self. Must be redefined as
-- a constant in the including class. Built-in.
aget(ind:INT):T
-- The element of self with index `ind'. Built-in.
pre ind.is_bet(0,asize-1) is
raise "AVAL{T}::aget(INT):T undefined." end;
aset(ind:INT,val:T):SAME
-- Return a copy of self with the component with index `ind' set
-- to `val'. Built-in.
pre ind.is_bet(0,asize-1) is
raise "AVAL{T}::aset(INT,T) undefined." end;
aelt!:T is
-- Yield each element of self in order. Built-in.
loop yield [asize.times!] end end;
aelt!(beg:INT):T
-- Yield each element of self starting at `beg'. Built-in.
pre beg.is_bet(0,asize-1) is
loop yield [beg.upto!(asize-1)] end end;
aelt!(beg,num:INT):T
-- Yield `num' successive elements of self starting at
-- index `beg'. Built-in.
pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg) is
loop yield [beg.upto!(beg+num-1)] end end;
private is_legal_aelts_arg(beg,num,step:INT):BOOL is
-- True if the arguments are legal values for `aelts'.
return beg.is_bet(0,asize-1) and
((step>0 and num.is_bet(0,(asize-beg+step-1)/step)) or
(step<0 and num.is_bet(0,(beg-step)/-step))) end;
aelt!(beg,num,step:INT):T
-- Yield `num' elements of self starting at `beg' and stepping
-- by `step' which must not be zero. Built-in.
pre is_legal_aelts_arg(beg,num,step) is
loop yield [beg.step!(num,step)] end end;
acopy_from(beg:INT,src:SAME):SAME
-- Return a copy of self modified by copying elements from `src'
-- into locations with indices starting at `beg'. Built-in.
pre beg.is_bet(0,asize-1) is
r::=self;
loop r:=r.aset(beg.upto!(asize-1),src.aelt!) end;
return r end;
acopy_from(beg,num:INT,src:SAME):SAME
-- Return a copy of self modified by copying `num' elements from
-- `src' into locations with indices starting at `beg'. Built-in.
pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg) is
r::=self;
loop r:=r.aset(beg.upto!(beg+num-1),src.aelt!) end;
return r end;
acopy_from(beg,num,srcbeg:INT,src:SAME):SAME
-- Return a copy of self modified by copying `num' elements from
-- `src' starting at index `srcbeg' into locations with indices
-- starting at `beg'. Built-in.
pre beg.is_bet(0,asize-1) and num.is_bet(0,asize-beg)
and num<src.asize-srcbeg is
r::=self;
loop r:=r.aset(beg.upto!(beg+num-1),src.aelt!(srcbeg)) end;
return r end;
ainds!:INT is
-- Yield the indices of self in order. Built-in.
loop yield asize.times! end end;
end; -- class AVAL{T}
-------------------------------------------------------------------