IPPoolImpl.mesa
Last edited by:
Doug Wyatt, February 28, 1984 5:09:55 pm PST
DIRECTORY
Imager USING [Context, DoSave, DoSaveAll],
IP USING [Array, ArrayFromVector, Integer, MasterError, NullVector, Operator, OperatorRep, Pool, PoolRep, PopBool, PopVector, PushOperator, PushVector, SaveEffect, State, Vector, VectorFromArray],
IPBase USING [];
IPPoolImpl: CEDAR PROGRAM
IMPORTS Imager, IP
EXPORTS IP, IPBase
~ BEGIN OPEN IP;
MakePool: PUBLIC PROC[v: Vector, persistent: BOOL] RETURNS[Pool] ~ {
RETURN[NEW[PoolRep ← [persistent: persistent, array: ArrayFromVector[v]]]];
};
emptyVector: Vector ~ NullVector[shape: [l: 0, n: 0]];
noPool: Pool ~ MakePool[v: emptyVector, persistent: FALSE];
NoPool: PUBLIC PROC RETURNS[Pool] ~ { RETURN[noPool] };
CurrentPool: PUBLIC PROC[pool: Pool] RETURNS[Vector] ~ {
RETURN[VectorFromArray[pool.array]];
};
PoolDo: PROC[self: State, data: REF] ~ {
pool: Pool ~ NARROW[data];
PushVector[self, CurrentPool[pool]];
};
OperatorFromPool: PUBLIC PROC[pool: Pool] RETURNS[Operator] ~ {
RETURN[NEW[OperatorRep ← [class: $Pool, do: PoolDo, data: pool]]];
};
PoolFromOperator: PUBLIC PROC[op: Operator] RETURNS[Pool] ~ {
IF op.class#$Pool THEN MasterError[$wrongType, "Operator is not a Pool."];
WITH op.data SELECT FROM pool: Pool => RETURN[pool]; ENDCASE;
MasterError[$bug, "Pool operator data is wrong type or NIL."]; RETURN[NIL];
};
DoWithSaveEffect: PUBLIC PROC[self: State, action: PROC, saveEffect: SaveEffect] ~ {
imager: Imager.Context ~ self.imager;
Eventually, this should worry about other pools than the Imager pool
SELECT saveEffect FROM
$nil => action[];
$save => imager.DoSave[action];
$saveAll => imager.DoSaveAll[action];
ENDCASE => ERROR;
};
ApplyMAKEPOOL: PUBLIC PROC[self: State] ~ {
persistent: BOOL ~ PopBool[self];
v: Vector ~ PopVector[self];
pool: Pool ~ MakePool[v, persistent];
PushOperator[self, OperatorFromPool[pool]];
};
ApplyNOPOOL: PUBLIC PROC[self: State] ~ {
PushOperator[self, OperatorFromPool[noPool]];
};
END.