FitStateUtilsImpl.mesa
Maureen Stone November 28, 1984 4:55:35 pm PST
DIRECTORY
FitStateUtils,
FitBasic USING [Handle, SampleHandle, LinkHandle, SListHandle, TrajHandle, Contour];
FitStateUtilsImpl: CEDAR PROGRAM EXPORTS FitStateUtils =
BEGIN OPEN FitBasic, FitStateUtils;
SampleProc: TYPE = PROC[s: SampleHandle] RETURNS [done: BOOLEAN];
LinkProc: TYPE =PROC[l: LinkHandle] RETURNS [done: BOOLEAN];
SListProc: TYPE =PROC[slist: SListHandle] RETURNS [done: BOOLEAN];
TrajProc: TYPE =PROC[traj: TrajHandle] RETURNS [done: BOOLEAN];
SLists have a header and samples are circularly linked
ForAllSamples: PUBLIC PROC [slist: SListHandle, do: SampleProc] = {
IF slist#NIL AND (slist.first=NIL OR slist.last=NIL) THEN
FOR s: SampleHandle ← slist.header.next, s.next WHILE s#slist.header DO
IF do[s] THEN EXIT;
ENDLOOP;
IF slist#NIL AND slist.first#NIL AND slist.last#NIL THEN
FOR s: SampleHandle ← slist.first, s.next UNTIL s=slist.last.next DO
IF s#slist.header THEN IF do[s] THEN EXIT;
ENDLOOP;
};
If the sample list is closed these will wrap around. Otherwise they signal AtEnd
AtEnd: PUBLIC SIGNAL = CODE;
NextSa: PUBLIC PROC [slist: SListHandle, s: SampleHandle, closed: BOOLEAN] RETURNS [SampleHandle] = {
ret: SampleHandle ← s.next;
IF ret=slist.header THEN ret ← ret.next;
IF s=slist.last AND NOT closed THEN SIGNAL AtEnd;
RETURN[ret];
};
PrevSa: PUBLIC PROC [slist: SListHandle, s: SampleHandle, closed: BOOLEAN] RETURNS [SampleHandle] = {
ret: SampleHandle ← s.prev;
IF ret=slist.header THEN ret ← ret.prev;
IF s=slist.first AND NOT closed THEN SIGNAL AtEnd;
RETURN[ret];
};
Links do not have headers
ForAllLinks: PUBLIC PROC [traj: TrajHandle, do: LinkProc] = {
FOR l: LinkHandle ← traj.links, l.next UNTIL l=NIL DO
IF do[l] THEN EXIT;
ENDLOOP;
};
ForAllSLists: PUBLIC PROC [handle: Handle, do: SListProc] = { --all samples in handle
IF handle.slist=NIL THEN ForAllOtherSLists[handle,do]
ELSE IF ~do[handle.slist] THEN ForAllOtherSLists[handle,do];
};
ForAllTrajs: PUBLIC PROC [handle: Handle, do: TrajProc] = { --all links in handle
IF handle.traj=NIL THEN ForAllOtherTrajs[handle,do]
ELSE IF ~do[handle.traj] THEN ForAllOtherTrajs[handle,do];
};
ForAllOtherSLists: PUBLIC PROC [handle: Handle, do: SListProc] = {
all samples in handle.otherContours
IF handle.otherContours#NIL THEN
FOR ts: LIST OF Contour ← handle.otherContours, ts.rest UNTIL ts=NIL DO
IF do[ts.first.slist] THEN EXIT;
ENDLOOP;
};
ForAllOtherTrajs: PUBLIC PROC [handle: Handle, do: TrajProc] = { --all links in handle.otherContours
IF handle.otherContours#NIL THEN
FOR ts: LIST OF Contour ← handle.otherContours, ts.rest UNTIL ts=NIL DO
IF do[ts.first.traj] THEN EXIT;
ENDLOOP;
};
END.