Sather Home Page

Section 8.3.1.1:
$CODE_MAPPER

abstract class $CODE_MAPPER < $BINARY
$BINARY

Inheritance map

Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types

SAME = object_type ;
$CODE_MAPPER = set of object_type ;

object_type = map token to token

state

references : $CODE_MAPPER
   inv ref_types ==
      forall obj | obj in set ref_types &
         sub_type($CODE_MAPPER,obj)
NOTE See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstract class models concept of a one-to-one bijective map (table) between encodings which are not Unicode and Unicode encoding itself. This implies that only those encodings for which there is a forward mapping to Unicode have reverse mappings from Unicode.

Note that for formal modelling purposes the codes are treated merely as tokens.


create

This feature creates a new empty map for conversion between the given code kind and Unicode.

create (
kind : CODE_KINDS
) : SAME
Formal Signature
create(kind : CODE_KINDS) res : SAME
Pre-condition

Since this is a creation operation and the argument is no optional, this pre-condition is vacuously true.

Post-condition
post kind(res) = kind

This feature creates an empty mapper object for the code kind indicated.


create

This feature creates a new empty map for conversion between the given code kind and Unicode.

create (
kind : CODE_KINDS
path : FILE_PATH
) : SAME
Formal Signature
create2(kind : CODE_KINDS, fpath : FILE_PATH) res : [SAME]
Pre-condition

Since this is a creation operation and both the arguments are not optional, this pre-condition is vacuously true.

Post-condition

Since this is an abstraction, ther can be no more precise post-condition than that given since in general the size of the map is not determinable until a program executes.

post (kind(res) = kind
         and card dom res > 0)
      or res = nil

This feature creates a new mapper from the contents of the indicated file. If there is a problem in accessing the file or the file is not a valid map file then the routine returns void.


kind

This feature returns the kind of encoding for which this map serves.

kind : CODE_KINDS
Formal Signature
kind(self : SAME) res : CODE_KINDS
Pre-condition

Since the self argument is not optional, then this pre-condition is vacuously true.

Post-condition
post create(res) = self

This feature returns the kind of code for which this map may be used.


from_unicode

This feature returns the character code resulting from applying the reverse of this map to the argument code.

create (
ch_code : CHAR_CODE
) : CHAR_CODE
Formal Signature
from_unicode(ch_code : CHAR_CODE) res : CHAR_CODE
Pre-condition
pre kind(self) = CULTURE.kind(LIBCHARS.culture(CHAR_CODE.lib(ch_code)))
Post-condition
post self(res) = ch_code
      or res = CHAR_CODE.nil

This feature convert the single code given as a Unicode code into the encoding used in this mapping table if such a value exists, otherwise returning CHAR_CODE::nil.


to_unicode

This feature returns the character code (encoded in Unicode) resulting from applying this map to the argument code.

create (
ch_code : CHAR_CODE
) : CHAR_CODE
Formal Signature
to_unicode(ch_code : CHAR_CODE) res : CHAR_CODE
Pre-condition
pre kind(self) = CULTURE.kind(LIBCHARS.culture(CHAR_CODE.lib(ch_code)))
Post-condition
post res = self(ch_code)
      or res = CHAR_CODE.nil

This feature convert the single code given into the corresponding Unicode encoding using this mapping table.


Language Index Library Index Codes Index
Comments or enquiries should be made toKeith Hopper.
Page last modified: Thursday, 26 April 2001.
Produced with Amaya