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


immutable class TRI_STATE < $ENUMS{TRI_STATE}

immutable class TRI_STATE < $ENUMS{TRI_STATE} is -- This class implements the concept of a logical response by a 'user' -- to a question requiring a yes/no answer. -- -- The corresponding names in the culture-dependent resources file -- should be the language-dependent names for the English notions -- -- -- No -- Yes -- Version 1.0 Jun 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 8 Jun 97 kh Original include ENUM{TRI_STATE} ; private const val_count : CARD := 3 ; -- The following constant 'routines' specify the enumeration values. No : SAME is return enum(1) end ; Yes : SAME is return enum(2) end ; Unknown : SAME is return enum(3) end ; end ; -- TRI_STATE

class ANSWERS < $BINARY

class ANSWERS < $BINARY is -- This class implements the concept of a logical response by a 'user' -- to a question requiring a yes/no answer. -- -- The corresponding names in the culture-dependent resources file -- should be the language-dependent names for the English notions -- -- -- No -- Yes -- Version 1.1 Jun 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 8 May 97 kh Original -- 8 Jun 97 kh Redesign for regular expressions. include BINARY ; private attr yes_expr : REG_EXP ; private attr no_expr : REG_EXP ; private attr yes_str : STR ; private attr no_str : STR ; private check_exps is -- This routine creates the regular expressions from the strings if -- this has not already been done. if void(yes_expr) then loc_str : STR := yes_str ; yes_expr := REG_EXP::create(inout loc_str) ; if loc_str = yes_str then loc_str := no_str ; no_expr := REG_EXP::create(inout loc_str) ; if loc_str = no_str then return else SYS_ERROR::create.error(self, SYS_EXCEPT::Bad_Value,loc_str) end else SYS_ERROR::create.error(self, SYS_EXCEPT::Bad_Value,loc_str) end end end ; build( cursor : BIN_CURSOR, lib : LIBCHARS ) : SAME pre ~void(cursor) and ~cursor.is_done and ~void(lib) post ~void(result.yes_str) and ~void(result.no_str) is -- This routine initialises the shared values from the indicated binary -- string. It is important to remember that this routine is called while -- building the cultural specification. This means that the cultural file -- string is correct - but this cannot be checked in REGEXP yet! The two -- strings are therefore merely stored for later use in check_exps! me : SAME := new ; me.yes_str := cursor.get_sized.str(lib) ; me.no_str := cursor.get_sized.str(lib) ; return me end ; build( cursor : BIN_CURSOR ) : SAME pre ~void(cursor) and ~cursor.is_done post ~void(result.yes_str) and ~void(result.no_str) is -- This routine initialises the shared values from the indicated binary -- string. It is important to remember that this routine is called while -- building the cultural specification. This means that the cultural file -- string is correct - but this cannot be checked in REGEXP yet! The two -- strings are therefore merely stored for later use in check_exps! return build(cursor,LIBCHARS::default) end ; create( yes, no : REG_EXP ) : SAME is -- This creation routine needs to be invoked once to set up the shared -- values. Thereafter the class may be 'interrogated' by any of the other -- routines provided. me : SAME := new ; me.yes_expr := yes ; me.no_expr := no ; return me end ; binstr : BINSTR pre ~void(self) post result.size > 0 is -- This routine returns a binary string representation of self. check_exps ; return yes_expr.binstr + no_expr.binstr end ; response( val : STR ) : TRI_STATE pre ~void(self) post ((result = TRI_STATE::Yes) and yes_expr.matches(val)) or ((result = TRI_STATE::No) and no_expr.matches(val)) or (result = TRI_STATE::Unknown) is -- This routine returns 'yes' if val matches the regular expression -- yes_expr, 'no' if it matches the regular expression no_expr, otherwise -- 'unknown' check_exps ; if yes_expr.matches(val) then return TRI_STATE::Yes elsif no_expr.matches(val) then return TRI_STATE::No else return TRI_STATE::Unknown end end ; yes( val : STR ) : BOOL is -- This predicate returns true if and only if val matches the yes_expr, -- otherwise false. if void(self) then return false else check_exps ; return yes_expr.matches(val) end end ; no( val : STR ) : BOOL is -- This predicate returns true if and only if val matches the no_expr, -- otherwise false. if void(self) then return false else check_exps ; return no_expr.matches(val) end end ; end ; -- ANSWERS