# Section 8.1.2.5:
CAST

###### class CAST{T}

#### Formal Types

types
SAME = CAST_T ;

This class is provided to permit explicit narrowing from the general abstract class $OB to the argument class T. It may then be used as a substitute for the 'one line' typecase statement.

#### create

This creation operation serves merely to encapsulate the class argument type. There is no internal state other than this.

create |

##### Formal Signature

create() res : SAME

##### Post-condition

Since there are no arguments the post-condition is vacuously true.

This creation operation merely encapsulates the class argument type for use when casting objects.

#### from

This is the single 'working' feature of this class, permitting an in-line typecase to be written. Note that if the argument happens not to be of type T then an exception will be raised.

from | (
| anything : $OB
| ) : T

##### Formal Signature

from(self : SAME, anything : $OB) res : SAME

##### Pre-condition

Since the argument can be of any type then this is vacuously true!

##### Post-condition

Note that this post-condition is always valid, since otherwise an exception has been raised.

post typeof(res) = T

##### Exception condition

For the meaning of the raise statement see its specification in section 6.7.12. The specification of the typeof auxiliary function is given in Section 6.9.

errs Exception : typeof(anything) <> T -> raise anything

This routine allows an explicit typecase 'cast' to be made to an object of the class argument type. An exception is raised if anything is not of class T.

| Language Index |  | Library Index |  | Basic Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Wednesday, 24 May 2000. |