misc.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 CAST{T}
class CAST{T} is
-- This class is provided to permit explicit narrowing from the general
-- abstract class $OB to class T. It is a useful substitute for the one
-- line typecase statement.
--
-- Usage:
-- thing : $OB := 3 ;
-- num : INT := CAST{INT}::from(thing) ;
--
-- 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.
create : SAME is
-- This operation is used to 'get' the class name -- it won't work
-- with void!
return new
end ;
from(
anything : $OB
) : T is
-- This routine allows an explicit cast to make the class of anything
-- to be class T. An exception is raised if anything is not of class T.
typecase anything
when T then
return anything
else
SYS_ERROR::create.error(self,SYS_EXCEPT::Bad_Type,
CAST_EXC::create(anything,SAME::create)) ;
return void -- to keep compiler happy!
end
end ;
end ; -- CAST{T}
class CAST_EXC < $STR
class CAST_EXC < $STR is
-- This class is the class of the exception that is raised when
-- a CAST{T}::from call fails.
--
-- NOTE This class requires a text resource file.
-- Version 1.0 Dec 96. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 16 Dec 96 kh Original modified from Sather dist.
readonly attr ob : $OB ;
readonly attr caster : $OB ; -- Mainly so that the class name
-- of the cast can be determined
-- for error reporting.
private shared Messages : ARRAY{STR} ;
private const -- local message enumeration
Typecase, Attempted, Invalid ;
private const Msg_Cnt : CARD := Invalid + 1 ;
create(
ob : $OB,
caster : $OB
) : SAME is
-- This creation routine merely sets the components of a new object of
-- this class.
me : SAME := new ;
me.ob := ob ;
me.caster := caster ;
return me
end ;
str(
lib : LIBCHARS
) : STR is
-- This routine returns a string error message in the given repertoire
-- and encoding. Note that the 'system' class returns the string
-- representation of the class name as RUNES, since this is the only portable
-- term -- which will need to be converted to the run-time character encoding
-- during the execution of this routine.
type_name : RUNES := SYS::rune_name(caster) ;
if void(Messages)then
Messages := lib.culture.resources.read(
SYS::rune_name(self),Msg_Cnt) ;
if Messages.size /= Msg_Cnt then
raise SYS::str_for_tp(SYS::tp(self)) +
LIBCHARS::default.Hyphen.char + Messages.size.str
end
end ;
res : STR := FMT::create(Messages[Typecase],type_name.str,lib).str ;
if void(ob) then
res := res + Messages[Attempted]
else
ob_classname : RUNES := SYS::rune_name(ob) ;
res := res + FMT::create(Messages[Invalid],ob_classname.str,lib).str
end ;
return res
end ;
str : STR is
-- This routine returns a string error message in the default character
-- repertoire and encoding. Note that the 'system' class returns the
-- string representation of the class name as RUNES, since this is the only
-- portable form -- which will need to be converted to the run-time
-- character encoding during the execution of this routine.
return str(LIBCHARS::default)
end ;
end ; -- CLASS_EXC
partial class ID
partial class ID is
-- This partial class is meant to be included by types that wish to
-- provide object equality as their natural, immutable identity relation.
-- 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.
is_eq(
arg : $OB
) : BOOL is
-- This returns object equality!
return SYS::ob_eq(self,arg)
end ;
-- NOTE is_lt and hash fail for immutable classes
is_lt(
arg : $OB
) : BOOL is
-- This returns true or false depending upon the ordering of
-- object identity codes as established by the compiler/run-time system.
return SYS::id(self) < SYS::id(arg)
end ;
hash : CARD is
-- This returns a consistent hash function using the value of the
-- identity code as a number.
return SYS::id(self).hash
end ;
end ; -- ID
class EXT_OB
class EXT_OB is
-- This class is obsolete and appear in the required library solely
-- for compatibility with the interim compiler.
-- Version 1.0 Jan 97. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 3 Jan 97 kh Original from standard Sather dist.
end ; -- EXT_OB