IPPoolImpl.mesa
Copyright © 1984 Xerox Corporation. All rights reserved.
Doug Wyatt, August 16, 1984 2:19:38 pm PDT
DIRECTORY
Imager USING [Context, DoSave, DoSaveAll],
IP;
IPPoolImpl: CEDAR PROGRAM
IMPORTS Imager, IP
EXPORTS IP
~ BEGIN OPEN IP;
MakePool: PUBLIC PROC[v: Vector, persistent: BOOL] RETURNS[Pool] ~ {
RETURN[NEW[PoolRep ← [persistent: persistent, array: ArrayFromVector[v]]]];
};
noPool: Pool ~ MakePool[v: NullVector[shape: [l: 0, n: 0]], persistent: FALSE];
NoPool: PUBLIC PROC RETURNS[Pool] ~ { RETURN[noPool] };
PoolValue: PUBLIC PROC[pool: Pool] RETURNS[Vector] ~ {
RETURN[VectorFromArray[pool.array]];
};
poolClass: OperatorClass ~ NEW[OperatorClassRep ← [type: $Pool, apply: PoolApply]];
PoolApply: PROC[op: Operator, state: State] ~ {
PushVector[state, PoolValue[op.pool]];
};
OperatorFromPool: PUBLIC PROC[pool: Pool] RETURNS[Operator] ~ {
RETURN[NEW[OperatorRep ← [class: poolClass, data: NIL, pool: pool]]];
};
PoolFromOperator: PUBLIC PROC[op: Operator] RETURNS[Pool] ~ {
IF op.pool#NIL THEN RETURN[op.pool]
ELSE {
MasterError[$wrongType, "Operator is not a Pool."];
ERROR Error;
};
};
DoWithSaveEffect: PUBLIC PROC[self: State, action: PROC, saveEffect: SaveEffect] ~ {
Eventually, this should worry about pools other than the Imager pool
IF saveEffect=$nil THEN action[]
ELSE {
showVec: Vector ~ self.showVec;
mediumSize: VEC ~ self.mediumSize;
fieldMin: VEC ~ self.fieldMin;
fieldMax: VEC ~ self.fieldMax;
Restore: PROC ~ {
self.showVec ← showVec;
self.mediumSize ← mediumSize;
self.fieldMin ← fieldMin;
self.fieldMax ← fieldMax;
};
SELECT saveEffect FROM
$nil => action[];
$save => { self.imager.DoSave[action ! UNWIND => Restore[]]; Restore[] };
$saveAll => { self.imager.DoSaveAll[action ! UNWIND => Restore[]]; Restore[] };
ENDCASE => ERROR;
};
};
END.