Universität Ulm,
Fakultät für Mathematik und Wirtschaftswissenschaften,
SAI
WS 97/98 || Entwicklung objekt-orientierter Bibliotheken || Beispiele || Collections-16
DEFINITION Collections
DEFINITION Collections;
IMPORT Disciplines, Events, 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);
FirstProc = PROCEDURE (collection: Collection);
NextProc = PROCEDURE (collection: Collection;
VAR object: Disciplines.Object) : BOOLEAN;
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 *)
first: FirstProc; (* required *)
next: NextProc; (* 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 First(collection: Collection);
PROCEDURE Next(collection: Collection;
VAR object: Disciplines.Object) : BOOLEAN;
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 97/98 || Entwicklung objekt-orientierter Bibliotheken || Beispiele || Collections-16
Andreas Borchert, 12. Januar 1998