![]() |
Section 8.16.1.3:
|
![]() |
This page contains the definition of the two generic $STRING abstract classes.
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 ; $STRING_ELT = set of object_type state multi : $STRING_ELT inv multi_types == forall obj in set multi_types & sub_type($STRING_ELT,obj)
NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification. |
This abstract class characterises the concept of all forms of simple string whether binary, text or other as sequences of the argument class (elements) which must sub-type from $IS_EQ. Classes which sub-type from this shall have immutable semantics!
This class defines NO features of its own.
abstract class $STRING{ | |
ELT < $IS_EQ, | |
FSTP < $FSTRING{ELT}, | |
STP < $STRING{ELT} | |
} < $STRING{ELT}, $SEARCH{ELT}, $BINARY |
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 ; $STRING_ELT_FTP_STP = set of object_type state multi : $STRING_ELT_FTP_STP inv multi_types == forall obj in set multi_types & sub_type($STRING_ELT_FTP_STP,obj)
NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification. |
This abstract class characterises the concept of simple non-text strings as sequences of the argument class (elements) which must sub-type from $IS_EQ. The second and third class arguments are the 'corresponding' mutable ($FSTRINGS{ELT}) and immutable (sub-typing from this abstract class) string classes. Classes which sub-type from this class shall have immutable semantics!
This is the first version of the string append operation which appends another string of the same kind to self and returns the result.
plus | ( |
vals : SAME | |
) : SAME |
plus(self : SAME, vals : SAME) res : SAME
pre len vals > 0
post res = self ^ vals
This feature returns a new string formed by appending the contents of other to the contents of self.
This version of the string append operation a single element to self and returns the result.
plus | ( |
val : ELT | |
) : SAME |
plus2(self : SAME, val : ELT) res : SAME
Since neither argument is optional, this pre-condition is vacuously true.
post res = self ^ [val]
This feature returns a new string formed by appending the single element given to the contents of self.
This version of the string append operation takes a mutable string as argument.
plus | ( |
vals : FSTP | |
) : SAME |
plus3(self : SAME, vals : FSTP) res : SAME
post res = self ^ vals
This feature returns a new string formed by appending the contents of the mutable string to the contents of self.
reverse | : SAME |
reverse(self : SAME) res : SAME
Since the domain of the result is identical to the domain of self, the pre-condition is vacuously true.
post forall idx | idx in set inds self & res(idx) = self(len self - idx + 1)
This routine returns a new string which has the same contents as self with all elements in the reverse order.
This iter version and the one following complement the one inherited by this abstraction. This permits the first element yielded to be the element indexed by the start argument.
Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.
elt_iter2(self : SAME, start : CARD) res : ELT
Since the iter will quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post history = history~ ^ [res] and res = self(len history + start)
For quit actions see the specification of the quit statement.
errs QUIT : (len history + start) = len self -> quit
This iter yields the elements of self in order beginning with the element at the given starting index.
This iter version specifies both the element to yield first and the number of elements to be yielded.
Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.
elt_iter3(self : SAME, start : CARD, num : CARD) res : ELT
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes).
post history = history~ ^ [res] and res = self(len history + start)
For quit actions see the specification of the quit statement.
errs QUIT : (len history = num) or (len history + start) = len self -> quit
This iter yields num elements of self in order beginning with the element at the given starting index.
This iter yields provides a substring sequence facility, the lengths of each dependent on the argument at each invocation. Note that the last iteration before quitting will yield the sub-sequence of the size indicated or the remainder of the string, whichever is the shortest sequence.
Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.
chunk_iter(self : SAME, chunk_size : CARD) res : SAME
Since the iter may quit when all elements have been yielded, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes). Note also that the vdm sub-sequence operation yields a sub-sequence which is no longer than the range indicated if that would extend beyond the end of the sequence.
post history = history~ ^ res and res = self((len history~ + 1), ..., (len history~ + chunk_size))
For quit actions see the specification of the quit statement.
errs QUIT : (len history = len self -> quit
This iter yields in sequence successive sub-sequences of self the length of each being determined by the argument.
This iter yields the character encodings of self in sequence starting at the one indicated.
Note that the formal name of the iter has been changed to replace the exclamation mark iter symbol to a name acceptable to vdm tools.
chunk_iter2(self : SAME, start : CARD, chunk_size : CARD) res : SAME
Since the iter may quit if start is not in the domain of indices of self, the pre-condition is vacuously true.
This post-condition makes use of the history concept from vdm++ (see the vdm dialect notes). Note also that the vdm sub-sequence operation yields a sub-sequence which is no longer than the range indicated if that would extend beyond the end of the sequence.
post history = history~ ^ res and res = self((start + len history~ + 1), ..., (start + len history~ + chunk_size))
For quit actions see the specification of the quit statement.
errs QUIT : (len history + start) = len self -> quit
This iter yields successive sub-sequences of elements of self, starting the first sub-sequence at the given index.
![]() |
Language Index | ![]() |
Library Index | ![]() |
String Index |
Comments
or enquiries should be made toKeith Hopper. Page last modified: Wednesday, 4 April 2001. |
![]() |