binary.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 $BINARY
abstract class $BINARY is
-- This abstract class specifies three routines which sub-classes must
-- provide in order to convert the value into a form suitable for
-- manipulation as a sequence of storage units and vice-versa. Both
-- transformations must satisfy the identity --
--
-- create(Value.binstr) = Value
-- Version 1.0 Feb 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 25 Feb 98 kh Original
create(storage : BINSTR) : SAME ;
-- Provided that the size of the storage argument is exactly the amount
-- of storage required for an object of this class as produced by the binstr
-- routine, then storage is converted into an object of this class which is
-- returned.
build(cursor : BIN_CURSOR) : SAME ;
-- Provided that there are at least the number of storaqge units
-- required to produce a value of this class then the number of storage units
-- required are used to do so and the cursor is moved to the next position on
-- the binary string.
read(cursor : BIN_CURSOR) : SAME ;
-- This routine returns the next object in the file providing that the
-- next item in the file is the boolean value for true, otherwise it returns
-- void having moved past the item in the string.
binstr : BINSTR ;
-- This returns a sequence of storage units which is suitable for
-- conversion back into a value of the class concerned..
write(fyle : BIN_FILE) ;
-- This routine appends self to the given binary file.
end ; -- $BINARY
partial class BINARY < $BINARY
partial class BINARY < $BINARY is
-- This class specifies defines those components of the binary
-- reading/writing mechanism which are the same irrespective of the class
-- involved.
-- Version 1.0 Jul 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 22 Jul 98 kh Original
stub build(cursor : BIN_CURSOR) : SAME ;
-- Provided that there are at least the number of storage units
-- required to produce a value of this class then the number of storage units
-- required are used to do so and the cursor is moved to the next position on
-- the binary string.
create(str : BINSTR) : SAME
pre (str.size > 0)
post true -- ~void(result) (but immutables
-- could be ZERO!!
is
-- This routine requires that the binary string argument contains
-- exactly the correct number of octets in the right format for it to create
-- and return a value, otherwise void is returned.
loc_cursor : BIN_CURSOR := str.cursor ;
me : SAME := build(loc_cursor) ;
if loc_cursor.remaining > 0 then -- string too long!
return void
else
return me -- may be void if too short!
end
end ;
read(index : BIN_CURSOR) : SAME
pre ~void(index) and ~index.is_done
post true
is
-- This routine assumes that the next octet in the binary string
-- represents a boolean value. If this value is true then the appropriate
-- number of octets is used to create and return a new object.
if BOOL::build(index) then
return build(index)
else
return void
end
end ;
stub binstr : BINSTR ;
-- This returns a sequence of storage units which is suitable for
-- conversion back into a value of the class concerned..
write(fyle : BIN_FILE)
pre ~void(self) and ~void(fyle)
post (fyle.size = initial(fyle.size) + binstr.size)
is
-- This routine writes a binary representation of self to the given binary file.
fyle := fyle + binstr ;
fyle.flush
end ;
end ; -- BINARY