RopeFile.mesa
Copyright Ó 1985, 1986, 1991, 1992 by Xerox Corporation. All rights reserved.
Russ Atkinson, February 5, 1985 2:15:26 pm PST
Carl Hauser, July 12, 1988 8:35:12 pm PDT
Michael Plass, October 15, 1991 5:20 pm PDT
DIRECTORY
Basics USING [UnsafeBlock],
IO USING [STREAM],
Rope USING [ROPE];
RopeFile: CEDAR DEFINITIONS = BEGIN OPEN Rope;
ByteSequenceObject: TYPE ~ REF ByteSequenceObjectRep;
ByteSequenceObjectRep: TYPE ~ MONITORED RECORD [
The ByteSequenceObject implements the abstraction of an immutable, ordered sequence of bytes. It differs from a ROPE in several ways. First, there is an explicit request to "deactivate" it, which may involve closing a file or otherwise giving up resources; it should be willing to come out of an inactive state when necessary unless final~TRUE. Second, its performance characteristics differ - it is not expected to service small requests particularly fast. Finally, there are provisions for providing status information. The implementor of a ByteSequenceObject is responsible for synchronization.
length: [0..LAST[INT]],
data: REF ANY,
equal: PROC [self: ByteSequenceObject, other: ByteSequenceObject] RETURNS [BOOL],
Only called when self.equal and other.equal are the same procedure
deactivate: PROC [self: ByteSequenceObject, final: BOOL] RETURNS [DeactivateResult],
describe: PROC [self: ByteSequenceObject] RETURNS [fileName: ROPE, created: ROPE, open: BOOL],
describe is useful for status display, not needed for correct operation
move: UNSAFE PROC [self: ByteSequenceObject, block: Basics.UnsafeBlock, start: INT] RETURNS [charsMoved: INT ¬ 0]
];
DeactivateResult: TYPE ~ { ok, cant, alreadyInactive };
CreateByteSequenceObject: PROC [
length: [0..LAST[INT]],
data: REF ANY,
equal: PROC [self: ByteSequenceObject, other: ByteSequenceObject] RETURNS [BOOL],
deactivate: PROC [self: ByteSequenceObject, final: BOOL] RETURNS [DeactivateResult],
describe: PROC [self: ByteSequenceObject]
RETURNS [fileName: ROPE, created: ROPE, open: BOOL],
move: UNSAFE PROC [self: ByteSequenceObject, block: Basics.UnsafeBlock, start: INT] RETURNS [charsMoved: INT ¬ 0]] RETURNS [ByteSequenceObject];
Error: ERROR [ec: ATOM, explanation: ROPE];
Raised when an illegal condition is detected, such as
$BadStream, use of a stream that does not support IO.GetLength, IO.GetIndex, IO.SetIndex
$Closed, use of a closed stream, either in FromStream or a Rope operation
$MultipleUse, use of a stream for more than one rope
FromByteSequenceObject: PROC [byteSequenceObject: ByteSequenceObject, flatten: BOOL ¬ FALSE] RETURNS [ROPE];
FromStream: PROC [stream: IO.STREAM, start: INT ¬ 0, len: INT ¬ LAST[INT], flatten: BOOL ¬ FALSE] RETURNS [rope: ROPE];
Creates a new rope based on the open stream for characters. If flatten, then the stream contents are copied into a rope and the stream is closed. Otherwise, the open stream is retained as a source of the rope contents. The start parameter is used as an index into the stream using IO.SetIndex[...]. If the length is less than the remaining number of characters in the stream, then the lesser of the length and the remainder is used as a length. If the resulting length is less than some implementation-determined length, the result is as if flatten = TRUE.
ByteSequenceObjectFromStream: PROC [stream: IO.STREAM] RETURNS [ByteSequenceObject];
Deactivate: PROC [rope: ROPE];
Asserts that the client does not expect to be touching the rope (or its constituent parts) in the near future; however, the rope remains valid.
LimitActive: PROC [activeLimit: INT];
Closes files until the activeLimit is satisfied; will reopen on demand, so ropes don't become invalid unless the source file goes away.
END.
Russ Atkinson (RRA) January 29, 1985 6:31:15 pm PST
Removed AppendChars (use Rope.AppendChars instead)
Michael Plass, October 14, 1991
Cedar10.0 port. Removed file-system assumptions; merged with RopeTrick. See PFS.RopeOpen.
Added: ByteSequenceObject, Error, FromByteSequenceObject, Deactivate,
Removed:
Create: PROC [name: ROPE, start: INT ¬ 0, len: INT ¬ LAST[INT], bufSize: INT ¬ 512, buffers: NAT ¬ 4, raw: BOOL ¬ TRUE] RETURNS [rope: ROPE];
SubstrCreate: PROC [name: ROPE, start: INT ¬ 0, len: INT ¬ LAST[INT]] RETURNS [rope: ROPE];
SimpleCreate: PROC [name: ROPE] RETURNS [rope: ROPE];