stream.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
abstract class $STREAM{ETP < $ORDERED{ETP}}
abstract class $STREAM{ETP < $ORDERED{ETP}} is
-- This abstract class provides an abstraction of a generator of
-- successive unique values (ie NOT reference classes) of type ETP. This
-- is not necessarily restricted to numeric values.
-- Version 1.1 May 2001. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 16 Dec 96 kh Original from standard Sather dist
-- 31 May 01 kh Changed name to $STREAM
create( start_val : ETP ) : SAME;
-- This creation routine returns a new cardinal stream whose next yielded
-- value will be "start_val"
next : ETP ;
-- This feature returns the next unique value in the class ETP,
-- irrespective of the use of the iter following..
next! : ETP ;
-- This iter feature returns the next unique value in the class ETP,
-- irrespecitve of other uses of this iter or the above routine feature.
end ; -- $STREAM{ETP}
class STREAM < $STREAM{CARD}
class STREAM < $STREAM{CARD} is
-- This class implements a stream of successive cardinal numbers.
-- Version 1.1 Oct 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 10 Jun 98 kh Original from INT_STREAM
-- 9 Oct 98 kh Added pre/post conditions
private attr val : CARD ;
create(start_val : CARD) : SAME is
-- This creation routine returns a new cardinal stream whose next yielded value will be "start_val"
me : SAME := new ;
me.val := start_val ;
return me
end ;
next : CARD
pre val < CARD::maxval
post result = initial(val)
is
-- This routine returns the next number in sequence in this stream.
res : CARD := val ;
assert val /= CARD::maxval ;
val := val + 1 ;
return res
end ;
next! : CARD
pre true
post result = initial(val)
is
-- This iterator yields successive cardinal numbers. It will quit
-- when maxcard has been yielded.
if val = CARD::maxval then quit; end ;
yield next
end ;
end; -- STREAM
class FIELD_STREAM < $STREAM{FIELD}
class FIELD_STREAM < $STREAM{FIELD} is
-- This class implements a stream of numbers from a closed Galois field
-- of specified cardinality.
-- Version 1.1 Oct 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 10 Jun 98 kh Original from STREAM
-- 9 Oct 98 kh added pre/post conditions
private attr val : FIELD ;
readonly attr size : FIELD ;
create(
start_val : FIELD,
field_size : CARD
) : SAME
pre start_val.card < field_size
post true
is
-- This creation routine returns a new stream whose next yielded
-- value will be the value of "start_val" as determined by the modulus of
-- the field "field_size".
--
-- NOTE The largest field size contains maxfield (= maxcard) numbers which
-- range from zero to (maxfield - 1)!
me : SAME := new ;
me.size := field_size.field ;
me.val := start_val.mod(me.size) ;
return me
end ;
next : FIELD
pre true
post result = initial(val)
is
-- This routine returns the next number in sequence in this stream.
res : FIELD := val ;
if val = size then
val := 0
else
val := val + 1
end ;
return res
end ;
next! : FIELD
pre true
post result = initial(val)
is
-- This iterator yields successive values in the field - it never quits!
yield next
end ;
end ; -- FIELD_STREAM
class INT_STREAM < $STREAM{INT}
class INT_STREAM < $STREAM{INT} is
-- This class implements a stream of successive integers.
-- Version 1.0 Dec 96. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 16 Dec 96 kh Original from standard Sather dist.
private attr val : INT ;
create(
start_val : INT
) : SAME is
-- This creation routine returns a new integer stream whose next yielded
-- value will be "start_val"
me : SAME := new ;
me.val := start_val ;
return me
end ;
next : INT
pre val < INT::maxval
post result = initial(val)
is
-- This routine returns the next integer in this stream.
res : INT := val ;
assert val /= INT::maxval ;
val := val + 1 ;
return res
end ;
next! : INT
pre true
post result = initial(val)
is
-- This iterator yields successive integers. It will quit after
-- yielding maxval.
if val = INT::maxval then
quit
end ;
yield next
end ;
end ; -- INT_STREAM