bin_cursor.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>  <--------------


class BIN_CURSOR < $CURSOR{OCTET,BINSTR}

class BIN_CURSOR < $CURSOR{OCTET,BINSTR} is -- This class specifies the binary cursor equivalent of a string cursor. -- Version 1.0 Apr 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 4 Apr 97 kh Original include CURSOR{OCTET,BINSTR} ; const Single_Length : CARD := FLT::Num_Bits / OCTET::Octet_Bits ; const Double_Length : CARD := FLTD::Num_Bits / OCTET::Octet_Bits ; const Num_Max : CARD := CARD::Num_Bits / OCTET::Octet_Bits ; const Max_Card : CARD := CARD::maxval ; -- The following group of predicates indicate whether the remaining -- string from the currently indicated element is correctly formed -- to produce an item of the indicated class if the elements were -- to be retrieved. is_bool : BOOL is -- This routine returns true if and only if the next following element -- is a boolean value. return ~is_done and ((item.card = true.card) or (item.card = false.card)) end ; -- Since any item could be considered to be a number, the following -- five predicates need only test for the presence of one or more -- items. is_card : BOOL is -- This routine returns true if and only if the next following element -- is a numeric value. return ~is_done end ; is_field : BOOL is -- This routine returns true if and only if the next following element -- is a numeric field value. return ~is_done end ; is_int : BOOL is -- This routine returns true if and only if the next following element -- is a (possibly signed) numeric value. return ~is_done end ; is_flt : BOOL is -- This routine returns true if and only if the next following element -- is an approximate value. return remaining >= Single_Length end ; is_fltd : BOOL is -- This routine returns true if and only if the next following element -- is a double-length approximate value. return remaining >= Double_Length end ; get_sized : BINSTR pre ~void(self) and ~is_done and (self.item.card < self.remaining) post (is_done and (result.size = initial(remaining) - 1)) or (~is_done and (result.size = initial(item.card))) is -- This routine presumes that the current item is a single octet -- containing a binary number which must be less than the number of remaining -- octets in the string. The binary number indicates the number of -- items to be returned - updating the cursor. return get_upto(get_item.card) end ; -- The following group of routines obtain one or more elements -- of the string which are converted into a value of the -- corresponding class updating the value of cursor as may be -- appropriate. In all cases void is returned if either -- -- -- There is a current error condition, OR -- -- The end of the string has already been reached, OR -- -- There are insufficient elements remaining to convert into -- a value of the class concerned, OR -- -- The structure of the string starting at the element -- currently pointed to by the cursor is not convertible -- to a value of the required class. -- -- In all these cases an error will be indicated. bool : BOOL pre ~void(self) post void(error) or (~void(error) and ~result) is -- This routine tests for the ability to convert the string at the -- present position into a logic value. If this is possible then the value -- is returned, otherwise an error is indicated. if is_bool then return BOOL::build(self) else error := CURSOR_ERRORS::Format_Error ; return false end end ; card : CARD pre ~void(self) post void(error) or (~void(error) and (result = 0)) is -- This routine tests for the ability to convert the string at the -- present position into a numeric value. If this is possible then the -- value is returned, otherwise an error is indicated. if is_card then return CARD::build(self) else error := CURSOR_ERRORS::Format_Error ; return 0 end end ; field : FIELD pre ~void(self) post void(error) or (~void(error) and (result = #(0))) is -- This routine tests for the ability to convert the string at the -- present position into a field numeric value. If this is possible then -- the value is returned, otherwise an error is indicated. if is_field then return FIELD::build(self) else error := CURSOR_ERRORS::Format_Error ; return #(0) end end ; int : INT pre ~void(self) post void(error) or (~void(error) and (result.is_zero)) is -- This routine test for the ability to convert the string at the -- present position into a (possibly signed) numeric value. If this is -- possible then the value is returned, otherwise an error is indicated. if is_int then return INT::build(self) else error := CURSOR_ERRORS::Format_Error ; return 0.int end end ; flt : FLT pre ~void(self) post void(error) or (~void(error) and (result = 0.0)) is -- This routine test for the ability to convert the string at the -- present position into an approximate numeric value. If this is possible -- then the value is returned, otherwise an error is indicated. if is_flt then return FLT::build(self) else error := CURSOR_ERRORS::Format_Error ; return 0.0 end end ; fltd : FLTD pre ~void(self) post void(error) or (~void(error) and (result = 0.0d)) is -- This routine test for the ability to convert the string at the -- present position into a double length approximate numeric value. If this -- is possible then the value is returned, otherwise an error is indicated. if is_fltd then return FLTD::build(self) else error := CURSOR_ERRORS::Format_Error ; return 0.0d end end ; end ; -- BIN_CURSOR