Oberon || Library || Module Index || Search Engine || Definition || Module
TYPE Identifier = LONGINT; TYPE Discipline = POINTER TO DisciplineRec; TYPE DisciplineRec = RECORD (Objects.ObjectRec) id: Identifier; END; TYPE Object = POINTER TO ObjectRec; TYPE ObjectRec = RECORD (Objects.ObjectRec) END;
PROCEDURE Unique() : Identifier; PROCEDURE Add(object: Object; discipline: Discipline); PROCEDURE Remove(object: Object; id: Identifier); PROCEDURE Seek(object: Object; id: Identifier; VAR discipline: Discipline) : BOOLEAN;
Every module which implements a discipline should call Unique during its initialization. The returned identifier is needed later to locate the data structures contributed by a specific module.
Adds attaches discipline to object. The identifier is given by the id component of discipline. Adding a discipline with the same identifier twice to the same object causes the discipline to be replaced. One discipline may be attached to any number of objects.
Remove removes the discipline with the given id from object, if it exists.
Seek seeks for a discipline with the given id and returns it in discipline, if it exists. Otherwise, FALSE is returned.
TYPE LineTermDiscipline = POINTER TO LineTermDisciplineRec; LineTermDisciplineRec = RECORD (Disciplines.DisciplineRec) lineterm: CHAR; END; VAR linetermid: Disciplines.Identifier; PROCEDURE SetLineTerminator(s: Streams.Stream; lineterm: CHAR); VAR disc: LineTermDiscipline; BEGIN NEW(disc); disc.id := linetermid; disc.lineterm := lineterm; Disciplines.Add(s, disc); END SetLineTerminator; PROCEDURE WriteLn(s: Streams.Stream) : BOOLEAN; VAR disc: LineTermDiscipline; BEGIN IF Disciplines.Seek(s, linetermid, disc) THEN RETURN Streams.WriteByte(s, disc.lineterm) ELSE (* take default value *) RETURN Streams.WriteByte(s, ASCII.nl) END; END WriteLn; BEGIN (* initialization *) linetermid := Disciplines.Unique(); (* ... *)
Oberon || Library || Module Index || Search Engine || Definition || Module