Oberon || Library || Module Index || Search Engine || Definition || Module
TYPE Text = POINTER TO TextRec; TYPE TextRec = RECORD (PersistentDisciplines.ObjectRec) END;
PROCEDURE Create(VAR text: Text; s: Streams.Stream) : BOOLEAN;
PROCEDURE Open(VAR s: Streams.Stream; text: Text; VAR errors: RelatedEvents.Object) : BOOLEAN;
Create creates a persistent text object representing s. The length of s is measured (by seeking to the end of s and taking the current position), a rewind is performed, and a sub stream (see SubStreams) of s is opened covering the current length. This allows text to keep in touch with s but avoids conflicts regarding shared stream positions if all other parties interested in accessing s create sub streams as well. A termination of s (see Resources) causes text to terminate, too. Likewise, a termination of text causes its connection to s to be dropped.
Open returns a stream that allows to access the contents of text. Multiple open operations are permitted and return different sub streams of the internal base stream of text.
Following procedures show how to convert a graph of persistent objects (represented by one root object) into a text object and vice versa:
PROCEDURE ConvertObjectToText(object: PersistentObjects.Object; VAR text: PersistentTexts.Text; errors: RelatedEvents.Object) : BOOLEAN; VAR textbuf: Texts.Text; BEGIN Texts.Open(textbuf); RelatedEvents.Forward(textbuf, errors); IF ~LinearizedStructures.Write(textbuf, object) THEN RETURN FALSE END; RETURN PersistentTexts.Create(text, textbuf) END ConvertObjectToText; PROCEDURE ConvertTextToObject(text: PersistentTexts.Text; VAR object: PersistentObjects.Object; errors: RelatedEvents.Object) : BOOLEAN; VAR s: Streams.Stream; ok: BOOLEAN; BEGIN IF ~PersistentTexts.Open(s, text, errors) THEN RETURN FALSE END; RelatedEvents.Forward(s, errors); ok := LinearizedStructures.Read(s, object); Streams.Release(s); RETURN ok END ConvertTextToObject;
While the contents of a text object may be changed, its length cannot be modified.
Oberon || Library || Module Index || Search Engine || Definition || Module