Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
Disciplines


NAME

Disciplines - attach additional data structures to abstract datatypes

SYNOPSIS

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;

DESCRIPTION

Disciplines allows to attach additional data structures to abstract datatypes like Streams. These added data structures permit to parametrize operations and thus to define disciplines.

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.

EXAMPLE

Streams.Stream is an extension of Disciplines.Object which allows to attach parameters to streams:
   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();
   (* ... *)

SEE ALSO

PersistentDisciplines
support of persistent disciplines
Resources
state changes of objects
Services
major extension of Disciplines.Object
StreamDisciplines
example for a public discipline

Edited by: borchert, last change: 1996/09/16, revision: 1.5, converted to HTML: 1997/04/28

Oberon || Library || Module Index || Search Engine || Definition || Module