Universität Ulm, Fakultät für Mathematik und Wirtschaftswissenschaften, SAI

WS 2000/01 || Entwicklung objekt-orientierter Bibliotheken || Beispiele || Rooms

DEFINITION Collections


DEFINITION Collections;

   IMPORT Disciplines, Events, Iterators, PersistentDisciplines, Services;

   TYPE
      Collection = POINTER TO CollectionRec;
      CollectionRec = RECORD (PersistentDisciplines.ObjectRec) END;

   (* error handling *)

   CONST
      objectNotInCollection = 0;
	 (* Collections.Remove failed because
	    the object is not in the collection
	 *)
      badIndex = 1;
	 (* Collections.Get failed because of an invalid index *)
      errors = 2;
   TYPE
      ErrorCode = SHORTINT;
      ErrorEvent = POINTER TO ErrorEventRec;
      ErrorEventRec =
	 RECORD
	    (Events.EventRec)
	    errorcode: ErrorCode; (* what happened...? *)
	    collection: Collections.Collection;
	       (* failed operation was called for this collection *)
	    object: Disciplines.Object;
	       (* the parameter, if present (may be NIL otherwise) *)
	 END;
   VAR
      error: Events.EventType;
      errormsg: ARRAY errors OF Events.Message;
	 (* error message texts for all error codes returned by this module *)

   (* interface for implementations *)

   TYPE
      Message = RECORD END;
      AddProc = PROCEDURE (collection: Collection; object: Disciplines.Object);
      GetIteratorProc = PROCEDURE (collection: Collection;
                                   VAR iterator: Iterators.Iterator);
      GetProc = PROCEDURE (collection: Collection;
			   index: INTEGER; VAR object: Disciplines.Object);
	 (* object must be set to NIL for invalid indices *)

      RemoveProc = PROCEDURE (collection: Collection;
			      object: Disciplines.Object) : BOOLEAN;
	 (* FALSE has to be returned if the object was not in
	    the given collection
	 *)

      HandlerProc = PROCEDURE (collection: Collection;
			       VAR message: Message);
      Interface = POINTER TO InterfaceRec;
      InterfaceRec =
	 RECORD
	    add: AddProc;                 (* required *)
	    getIterator: GetIteratorProc; (* required *)
	    get: GetProc;                 (* optional *)
	    remove: RemoveProc;           (* optional *)
	    handler: HandlerProc;         (* optional *)
	 END;

   CONST
      get = 0; remove = 1; handler = 2;
   TYPE
      Capability = SHORTINT; (* get..handler *)
      CapabilitySet = SET; (* OF Capability *)

   PROCEDURE Init(collection: Collection; if: Interface; caps: CapabilitySet);

   PROCEDURE Send(collection: Collection; VAR message: Message);

   (* interface for clients *)

   PROCEDURE Capabilities(collection: Collection) : CapabilitySet;

   PROCEDURE Add(collection: Collection; object: Disciplines.Object);

   PROCEDURE GetIterator(collection: Collection;
                         VAR iterator: Iterators.Iterator);

   PROCEDURE Get(collection: Collection;
		 index: INTEGER; VAR object: Disciplines.Object);
      (* is not supported by all implementations *)

   PROCEDURE Remove(collection: Collection; object: Disciplines.Object);
      (* is not supported by all implementations *)

END Collections.

WS 2000/01 || Entwicklung objekt-orientierter Bibliotheken || Beispiele || Rooms

Andreas Borchert, 29. Januar 2001