TiogaNodeOps.mesa; Written by McGregor, February 1983
edited by McGregor, August 17, 1983 5:02 pm
edited by Paxton, August 10, 1983 4:26 pm
DIRECTORY
Rope USING [ROPE],
TiogaLooks USING [Looks, Runs],
TiogaNode,
TiogaItemClass,
TiogaBasicClass;
TiogaNodeOps: CEDAR DEFINITIONS = BEGIN
OPEN Rope, TiogaNode, TiogaItemClass, TiogaBasicClass;
Item Node Class registration and operations
RegisterItemClass:
PROC [classRec: ItemClassRec, OKToOverwritePrevious:
BOOL
--←
FALSE--]
RETURNS [ItemClassID];
Register a new item class implementation. Iff OKToOverwritePrevious is TRUE then the registry will permit a new implementation to replace another with the same ItemFlavor.
LookupItemID:
PROC [flavor: ItemFlavor, buildNewClassIfLookupFails:
BOOL
--←
FALSE--]
RETURNS [ItemClassID];
Given the name for a item node class, fetch the class ID. Will return invalidItemID if the given class is not registered and buildNewClassIfLookupFails is FALSE. If buildNewClassIfLookupFails is TRUE then a new class will be generated that performs read/write operations as well as a default display.
FetchItemClass:
PROC [id: ItemClassID]
RETURNS [ItemClass];
Given the unique class ID for a item node class, fetch the class information. Will return NIL if the given class is not registered.
Basic Node Class registration and operations
RegisterBasicClass:
PROC [classRec: BasicClassRec, OKToOverwritePrevious:
BOOL
--←
FALSE--]
RETURNS [BasicClassID];
Register a new item class implementation. Iff OKToOverwritePrevious is TRUE then the registry will permit a new implementation to replace another with the same BasicFlavor
LookupBasicID:
PROC [flavor: BasicFlavor, buildNewClassIfLookupFails:
BOOL
--←
FALSE--]
RETURNS [BasicClassID];
Given the name for a basic node class, fetch the class ID. Will return invalidBasicID if the given class is not registered. If buildNewClassIfLookupFails is TRUE then a new class will be generated that performs read/write operations as well as a default display.
FetchBasicClass:
PROC [id: BasicClassID]
RETURNS [BasicClass];
Given the unique class ID for a basic node class, fetch the class information. Will return NIL if the given class is not registered.
Creating new nodes
NewBranchNode:
PROC
RETURNS [br: RefBranchNode];
NewTextNode:
PROC [class: ItemClassID]
RETURNS [tx: RefTextNode];
NewListNode:
PROC [class: ItemClassID]
RETURNS [ls: RefListNode];
NewBoxNode:
PROC [class: ItemClassID]
RETURNS [bx: RefBoxNode];
NewBasicNode: PROC [class: BasicClassID] RETURNS [bs: RefBasicNode];
Text node operations
FetchChar:
PROC [text: RefTextNode, index: Offset]
RETURNS [
CHAR];
fetches the indexed information
FetchLooks:
PROC [text: RefTextNode, index: Offset]
RETURNS [TiogaLooks.Looks];
returns the looks for the character at the given location
use reader's if getting looks for sequence of locations
Fetch:
PROC [text: RefTextNode, index: Offset]
RETURNS [
CHAR, TiogaLooks.Looks];
fetches the indexed information
GetRope, NodeRope: PROC [text: RefTextNode] RETURNS [ROPE];
GetRuns, NodeRuns: PROC [text: RefTextNode] RETURNS [TiogaLooks.Runs];
Size: PROC [text: RefTextNode] RETURNS [Offset];
Operations to create a text node from a rope or a string
FromRope:
PROC [rope:
ROPE, class: ItemClassID ← defaultTextClassID]
RETURNS [RefTextNode];
create a text node with looks from a normal rope
FromString:
PROC [string:
REF
READONLY
TEXT, class: ItemClassID ← defaultTextClassID]
RETURNS [RefTextNode];
copies the contents of the string
Operation to create a document from an item node
DocFromNode:
PROC [child: RefItemNode]
RETURNS [root: RefBranchNode];
child typically created by FromRope or FromString
Operation to free a tree by clearing all REF's
FreeTree:
PROC [root: RefBranchNode];
Node predicates
IsBranch:
PROC [n: Ref]
RETURNS [
BOOL] =
INLINE
{RETURN[n#NIL AND ISTYPE[n, RefBranchNode]]};
IsItem:
PROC [n: Ref]
RETURNS [
BOOL] =
INLINE
{RETURN[n#NIL AND ISTYPE[n, RefItemNode]]};
IsText:
PROC [n: Ref]
RETURNS [
BOOL] =
INLINE
{RETURN[n#NIL AND ISTYPE[n, RefTextNode]]};
IsList:
PROC [n: Ref]
RETURNS [
BOOL] =
INLINE
{RETURN[n#NIL AND ISTYPE[n, RefListNode]]};
IsBox:
PROC [n: Ref]
RETURNS [
BOOL] =
INLINE
{RETURN[n#NIL AND ISTYPE[n, RefBoxNode]]};
IsBasic:
PROC [n: Ref]
RETURNS [
BOOL] =
INLINE
{RETURN[n#NIL AND ISTYPE[n, RefBasicNode]]};
Node narrowing
Return the requested type of node if possible, else return NIL
NarrowToBranchNode:
PROC [n: Ref]
RETURNS [RefBranchNode] =
INLINE
{RETURN [WITH n SELECT FROM br: RefBranchNode => br, ENDCASE => NIL] };
NarrowToItemNode:
PROC [n: Ref]
RETURNS [RefItemNode] =
INLINE
{RETURN [WITH n SELECT FROM it: RefItemNode => it, ENDCASE => NIL] };
NarrowToTextNode:
PROC [n: Ref]
RETURNS [RefTextNode] =
INLINE
{RETURN [WITH n SELECT FROM tx: RefTextNode => tx, ENDCASE => NIL] };
NarrowToListNode:
PROC [n: Ref]
RETURNS [ls: RefListNode] =
INLINE
{RETURN [WITH n SELECT FROM ls: RefListNode => ls, ENDCASE => NIL] };
NarrowToBoxNode:
PROC [n: Ref]
RETURNS [RefBoxNode] =
INLINE
{RETURN [WITH n SELECT FROM bx: RefBoxNode => bx, ENDCASE => NIL] };
NarrowToBasicNode:
PROC [n: Ref]
RETURNS [RefBasicNode] =
INLINE
{RETURN [WITH n SELECT FROM bs: RefBasicNode => bs, ENDCASE => NIL] };
Miscellaneous
MakeNodeLoc:
PROC [n: Ref]
RETURNS [Location];
MakeNodeSpan:
PROC [first, last: Ref]
RETURNS [Span];
NodeSpan:
PROC [span: Span]
RETURNS [Span] =
INLINE {
RETURN
[[[span.start.path,NodeItself],[span.end.path,NodeItself]]] };
NodeLoc:
PROC [loc: Location]
RETURNS [Location] =
INLINE
{ RETURN [[loc.path,NodeItself]] };
EndPos: PROC [n: RefTextNode] RETURNS [Offset]; -- gives offset at end of text node
END.