phone_culture.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 ACCESS_CODES < $ENUMS{ACCESS_CODES}

immutable class ACCESS_CODES < $ENUMS{ACCESS_CODES} is -- This class is an enumeration of all of the kinds of telephone access -- code which are supported by the specification in ISO/IEC 14652. -- Version 1.0 Mar 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 4 Mar 98 kh Original from ISO/IEC 14652 include ENUM{ACCESS_CODES} ; private const val_count : CARD := 4 ; -- The following constant 'routines' specify the enumeration values. Foreign : SAME is return enum(1) end ; External : SAME is return enum(2) end ; Domestic : SAME is return enum(3) end ; Local : SAME is return enum(4) end ; end ; -- ACCESS_CODES

immutable class PHONE_CODES < $ENUMS{PHONE_CODES}

immutable class PHONE_CODES < $ENUMS{PHONE_CODES} is -- This class is an enumeration of all the telephone component format -- values which are defined in the LC_ADDRESS component of ISO/IEC 14652. -- -- The corresponding names in the common resources file -- should be the ISO/IEC 14652 names specified for the indicated formats. -- -- Version 1.0 Mar 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 4 Mar 98 kh Original from ISO/IEC 14652 include EXACT_ENUM{PHONE_CODES} ; private const val_count : CARD := 4 ; -- The following constant 'routines' specify the enumeration values. Area_Code : SAME is return enum(1) end ; -- a Prefixed_Area_Code : SAME is return enum(2) end ; -- A Country_Code : SAME is return enum(3) end ; -- c Local_Number : SAME is return enum(4) end ; -- l end ; -- PHONE_CODES

class PHONE_FMT < $BINARY

class PHONE_FMT < $BINARY is -- This class is the descriptor to be used when converting and -- formatting a telephone number value into a textual representation. -- The format descriptor provides for an optional prefix string and then -- pairs of component/string pairs for as many components as needed. Any of -- the 'component' strings may be empty where two or more value components -- are to be formatted adjacent to each other (without any space!). -- Version 1.1 Nov 99. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 4 Mar 98 kh Original design from ISO/IEC 14652 -- 5 Nov 99 kh Modified for generic format I/O include ISO_FORMAT{SAME,PHONE_CODES} ; private do_special( code : PHONE_CODES, inout sep_str : CODE_STR, out modifier : PHONE_CODES, inout pushed : BOOL ) : BOOL is -- This routine returns true if and only if the code argument has resulted -- in any special action being taken, otherwise nothing has been done and -- the creation routine below sets the appropriate list components. modifier := void ; return false end ; private do_format( number : PHONE_NO, lib : LIBCHARS ) : CODE_STR pre ~void(number) and ~void(lib) post ~void(result) is -- This private routine does formatting for a telephone number according -- to the culturally defined specification. res : CODE_STR := CODE_STR::create(lib) ; prev : CODE_STR := CODE_STR::create(lib) ; line : CODE_STR := CODE_STR::create(lib) + prefix ; loop case components.elt! when PHONE_CODES::Area_Code then line := line + prev ; prev := number.render(number.area,lib) when PHONE_CODES::Prefixed_Area_Code then line := line + prev ; prev := number.render(number.extension,lib).capitalize when PHONE_CODES::Country_Code then line := line + prev ; prev := number.render(number.country,lib) when PHONE_CODES::Local_Number then line := line + prev ; prev := number.render(number.local,lib) else -- error in cultural spec! SYS_ERROR::create.error(self,SYS_EXCEPT::Bad_Format, res + line + prev) end ; loc_sep : CODE_STR := separators.elt! ; if loc_sep.size > 0 then prev := prev + loc_sep end end ; return res + line + prev end ; fmt( val : PHONE_NO, lib : LIBCHARS ) : STR pre ~void(val) and ~void(lib) post ~void(result) is -- This routine produces a formatted version of the given telephone -- number as a text string representation. return do_format(val,lib).tgt_str end ; end ; -- PHONE_FMT

class PHONE_ACCESS < $BINARY

class PHONE_ACCESS < $BINARY is -- This class models a telephone number format descriptor and the -- associated telephone network access code number. -- Version 1.1 Jul 99. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 4 Mar 98 kh Original from ISO/IEC 14652 -- 22 Jul 99 kh Revised structure to simplify use. include BINARY ; readonly attr format : PHONE_FMT ; readonly attr access : CODE_STR ; create : SAME is -- This creation routine creates a new empty object. return new end ; create( fmt : PHONE_FMT, code : CODE_STR ) : SAME is -- This routine creates a new objeft with the given components. me : SAME := create ; me.format := fmt ; me.access := code ; return me end ; build( index : BIN_CURSOR, lib : LIBCHARS ) : SAME pre ~void(index) and ~void(lib) post true is -- This routine creates a new object from the given binary string. me : SAME := create ; me.format := PHONE_FMT::build(index,lib) ; loc_binstr : BINSTR := index.get_sized ; if loc_binstr.size > 0 then -- this one is empty too! me.access := CODE_STR::build(loc_binstr.cursor,lib) end ; return me end ; build( index : BIN_CURSOR ) : SAME pre ~void(index) post true is -- This routine creates a new object from the given binary string, using -- the default repertoire and encoding. return build(index,LIBCHARS::default) end ; binstr : BINSTR pre ~void(self) post ~void(result) is -- This routine returns the binary string representation of self. res : BINSTR := BINSTR::create ; if void(format) then res := res + false.binstr else res := res + true.binstr + format.binstr end ; return res + access.binstr.sized end ; end ; -- PHONE_ACCESS

class PHONING < $BINARY

class PHONING < $BINARY is -- This class contains the components of the cultural specification in -- ISO/IEC 14652 devoted to telephone number representation. -- Version 1.2 Jul 99. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 26 Jun 98 kh Original design from cultural compiler -- 30 Oct 98 kh Added pre/post conds & BINARY -- 22 Jul 99 kh Renamed from PHONE_CODES include BINARY ; private attr access : ARRAY{PHONE_ACCESS} ; private get_access( cursor : BIN_CURSOR, lib : LIBCHARS ) : PHONE_ACCESS pre ~void(cursor) and ~cursor.is_done post true is -- This routine, after checking that the required format description -- is present in the source, constructs it if so, otherwise returns void. if BOOL::build(cursor) then return PHONE_ACCESS::build(cursor,lib) else return void end end ; build( cursor : BIN_CURSOR, lib : LIBCHARS ) : SAME pre ~void(cursor) and ~cursor.is_done and ~void(lib) post true is -- This routine attempts to build a new object from the data starting -- at the current position in the given binary string. If an error occurs -- (eg running out of data) then void is returned. me : SAME := new ; loc_cnt : CARD := cursor.get_item.card ; if loc_cnt /= PHONE_CODES::cardinality then return void end ; me.access := ARRAY{PHONE_ACCESS}::create(PHONE_CODES::cardinality) ; loop index : CARD := 0.upto!(PHONE_CODES::cardinality - 1) ; me.access[index] := get_access(cursor,lib) end ; return me end ; build( cursor : BIN_CURSOR ) : SAME pre ~void(cursor) and ~cursor.is_done post true is -- This routine attempts to build a new object from the data starting -- at the current position in the given binary string. If an error occurs -- (eg running out of data) then void is returned. return build(cursor,LIBCHARS::default) end ; read( index : BIN_CURSOR, lib : LIBCHARS ) : 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 build and return a new object. The use of -- lib is provided in case the object being built needs conversion of -- binary data to some textual form. if BOOL::build(index) then return build(index,lib) else return void end end ; set( elem : ACCESS_CODES, val : PHONE_ACCESS ) : SAME pre ~elem.is_nil post true -- access[elem.card - 1] = val is -- This routine sets the element of the map 'indexed' by elem. access[elem.card - 1] := val ; return self end ; get( elem : ACCESS_CODES ) : PHONE_ACCESS pre ~elem.is_nil post true -- result = access[elem.card - 1] is -- This routine returns the value of the string indexed by 'elem'. return access[elem.card - 1] end ; binstr : BINSTR pre ~void(self) post (result.size > 0) is -- This routine appends the contents of self as a binary string to -- the given file. res : BINSTR := BINSTR::create + OCTET::create(access.size) ; loop res := res + access.elt!.binstr end ; return res end ; end ; -- PHONING