PipalMosIOImpl.mesa
Copyright Ó 1986, 1987, 1988 by Xerox Corporation. All rights reserved.
Bertrand Serlet March 31, 1988 10:06:01 pm PST
Barth, December 4, 1986 6:01:02 pm PST
PipalMosIOImpl:
CEDAR
PROGRAM
IMPORTS CoreIO, Pipal, PipalInt, PipalIO, PipalMos =
BEGIN OPEN CoreIO, PipalIO;
Overlay
WriteOverlay: ClassWriteProc = {
overlay: Pipal.Overlay ← NARROW [object];
WriteInt[h, overlay.size];
FOR i: NAT IN [0 .. overlay.size) DO WriteObject[h, overlay[i]] ENDLOOP;
};
ReadOverlay: ClassReadProc = {
size: NAT = ReadInt[h];
object ← Pipal.CreateOverlay[ReadObjects[h, size]];
};
Icon
WriteIcon: ClassWriteProc = {
icon: Pipal.Icon ← NARROW [object];
WriteObject[h, icon.reference]; WriteObject[h, icon.referent];
};
ReadIcon: ClassReadProc = {
reference: Pipal.Object ← ReadObject[h];
referent: Pipal.Object ← ReadObject[h];
object ← Pipal.CreateIcon[reference, referent];
};
Annotation
WriteAnnotation: ClassWriteProc = {
annotation: Pipal.Annotation ← NARROW [object];
WriteAtom[h, annotation.key];
IF annotation.value=
NIL
THEN WriteAtom[h, $Nil]
ELSE
WITH annotation.value
SELECT
FROM
atom:
ATOM => {
WriteAtom[h, $Atom];
WriteAtom[h, atom];
};
rope: Pipal.
ROPE => {
WriteAtom[h, $Rope];
WriteRope[h, rope];
};
refRect:
REF PipalInt.Rectangle => {
WriteAtom[h, $Rectangle];
WriteRectangle[h, refRect^];
};
ENDCASE => ERROR;
WriteObject[h, annotation.child];
};
ReadAnnotation: ClassReadProc = {
key: ATOM ← ReadAtom[h];
valueKey: ATOM ← ReadAtom[h];
value:
REF ←
SELECT valueKey
FROM
$Nil => NIL,
$Atom => ReadAtom[h],
$Rope => ReadRope[h],
$Rectangle => NEW [PipalInt.Rectangle ← ReadRectangle[h]],
ENDCASE => ERROR;
object ← Pipal.CreateAnnotation[ReadObject[h], key, value];
};
All Transformations
WriteTransform: ClassWriteProc = {
trans: PipalInt.Transformation;
sub: Pipal.Object ← NIL;
EachChild: PipalInt.EachChildProc = {
IF sub#NIL THEN ERROR;
sub ← child; trans ← transformation;
};
IF PipalInt.Enumerate[object, EachChild] THEN ERROR;
IF sub=NIL THEN ERROR;
WriteTransformation[h, trans];
WriteObject[h, sub];
};
ReadTransform: ClassReadProc = {
transformation: PipalInt.Transformation ← ReadTransformation[h];
object ← PipalInt.TransformObject[transformation, ReadObject[h]];
};
Box
WriteBox: ClassWriteProc = {
box: PipalMos.Box = NARROW [object];
WriteVector[h, box.size];
WriteAtom[h, box.layer];
};
ReadBox: ClassReadProc = {
size: PipalInt.Size = ReadVector[h];
layer: PipalMos.Layer = ReadAtom[h];
RETURN [PipalMos.CreateBox[size, layer]]
};
Star
WriteStar: ClassWriteProc = {
star: PipalMos.Star ← NARROW [object];
WriteBool[h, star.overlayStar];
WriteObject[h, star.master];
WriteInt[h, star.size];
FOR i: NAT IN [0 .. star.size) DO WriteObject[h, star[i]] ENDLOOP;
};
ReadStar: ClassReadProc = {
overlayStar: BOOL ← ReadBool[h];
master: Pipal.Object ← ReadObject[h];
size: NAT = ReadInt[h];
object ← PipalMos.CreateStar[master, ReadObjects[h, size], overlayStar];
};
Routing
WriteRouting: ClassWriteProc = {
routing: PipalMos.Routing ← NARROW [object];
WriteInt[h, routing.size];
FOR i: NAT IN [0 .. routing.size) DO WriteObject[h, routing[i]] ENDLOOP;
};
ReadRouting: ClassReadProc = {
size: NAT = ReadInt[h];
object ← PipalMos.CreateRouting[ReadObjects[h, size]];
};
Tiling
WriteTiling: ClassWriteProc = {
tiling: PipalMos.Tiling ← NARROW [object];
WriteInt[h, tiling.sizeX];
WriteInt[h, tiling.sizeY];
FOR y:
NAT
IN [0 .. tiling.sizeY)
DO
FOR x: NAT IN [0 .. tiling.sizeX) DO WriteObject[h, tiling.xyTile[x, y, tiling.data]] ENDLOOP;
ENDLOOP;
};
TileArrayRec: TYPE = RECORD [SEQUENCE sizeY: NAT OF REF TileLinesRec];
TileLinesRec: TYPE = RECORD [SEQUENCE sizeX: NAT OF Pipal.Object];
TileArrayXY: PipalMos.XYTileProc = {
tileArray: REF TileArrayRec ← NARROW [data];
RETURN [tileArray[y][x]];
};
ReadTiling: ClassReadProc = {
sizeX: NAT ← NAT [ReadInt[h]];
sizeY: NAT ← NAT [ReadInt[h]];
tileArray: REF TileArrayRec ← NEW [TileArrayRec[sizeY]];
FOR y:
NAT
IN [0 .. sizeY)
DO
tileArray[y] ← NEW [TileLinesRec[sizeX]];
FOR x: NAT IN [0 .. sizeX) DO tileArray[y][x] ← ReadObject[h] ENDLOOP;
ENDLOOP;
object ← PipalMos.CreateTiling[sizeX, sizeY, TileArrayXY, tileArray];
};
Marker
WriteMarker: ClassWriteProc = {
marker: PipalMos.Marker = NARROW [object];
WriteVector[h, marker.size];
WriteAtom[h, marker.layer];
};
ReadMarker: ClassReadProc = {
size: PipalInt.Size = ReadVector[h];
layer: PipalMos.Layer = ReadAtom[h];
RETURN [PipalMos.CreateMarker[size, layer]]
};
Initialization
RegisterClass[Pipal.overlayClass, WriteOverlay, ReadOverlay];
RegisterClass[Pipal.iconClass, WriteIcon, ReadIcon];
RegisterClass[Pipal.annotationClass, WriteAnnotation, ReadAnnotation];
RegisterClass[PipalInt.transformClass, WriteTransform, ReadTransform];
RegisterClass[PipalInt.translationClass, WriteTransform, ReadTransform];
RegisterClass[PipalInt.orientClass, WriteTransform, ReadTransform];
RegisterClass[PipalInt.abutClass, WriteAbut, ReadAbut];
RegisterClass[PipalMos.boxClass, WriteBox, ReadBox];
RegisterClass[PipalMos.starClass, WriteStar, ReadStar];
RegisterClass[PipalMos.routingClass, WriteRouting, ReadRouting];
RegisterClass[PipalMos.tilingClass, WriteTiling, ReadTiling];
RegisterClass[PipalMos.markerClass, WriteMarker, ReadMarker];
RegisterClass[PipalMos.textClass, WriteText, ReadText];
RegisterClass[PipalMos.textClass, WritePicture, ReadPicture];