Universität Ulm,
Fakultät für Mathematik und Wirtschaftswissenschaften,
SAI
WS 97/98 || Entwicklung objekt-orientierter Bibliotheken || Übungen || Lösung 8
DEFINITION Dictionaries
(*
* Entwicklung objekt-orientierter Bibliotheken, Aufgabe 15
*
* Abstraktion fuer assoziative Arrays.
*)
DEFINITION Dictionaries;
IMPORT
ConstStrings, Disciplines, Events, Iterators, Objects, Services;
CONST
any = 0;
sorted = 1;
reverse = 2;
TYPE
Order = Iterators.Mode; (* any, sorted, reverse *)
Key = ConstStrings.String;
Entry = POINTER TO EntryRec;
EntryRec =
RECORD
(Disciplines.ObjectRec)
key: Key;
object: Disciplines.Object;
END;
CompareProc = PROCEDURE (entry1, entry2: Entry): INTEGER;
Dictionary = POINTER TO DictionaryRec;
DictionaryRec =
RECORD
(Services.ObjectRec)
END;
AddProc = PROCEDURE (dict: Dictionary; key: Key;
object: Disciplines.Object): BOOLEAN;
RemoveProc = PROCEDURE (dict: Dictionary; key: Key): BOOLEAN;
GetProc = PROCEDURE (dict: Dictionary; key: Key;
VAR object: Disciplines.Object): BOOLEAN;
CardProc = PROCEDURE (dict: Dictionary): INTEGER;
GetEntriesProc = PROCEDURE (dict: Dictionary; order: Order;
VAR it: Iterators.Iterator);
GetCompareProc = PROCEDURE (dict: Dictionary; VAR compare: CompareProc);
Interface = POINTER TO InterfaceRec;
InterfaceRec =
RECORD
(Objects.ObjectRec)
add: AddProc; (* mandatory *)
remove: RemoveProc; (* optional *)
get: GetProc; (* mandatory *)
card: CardProc; (* mandatory *)
getEntries: GetEntriesProc; (* optional *)
getCompare: GetCompareProc; (* optional *)
END;
CONST
remove = 0;
getEntries = 1;
sortEntries = 2; (* specifying order makes sense *)
TYPE
CapabilitySet = SET; (* OF remove..sortEntries *)
CONST
keyExists = 0; (* key exists *)
keyNotFound = 1; (* key not found *)
errors = 2;
TYPE
ErrorCode = SHORTINT; (* keyExists, keyNotFound *)
ErrorEvent = POINTER TO ErrorEventRec;
ErrorEventRec =
RECORD
(Events.EventRec)
errorcode: ErrorCode;
dictionary: Dictionary;
key: Key;
END;
VAR
error: Events.EventType;
errormsg: ARRAY errors OF Events.Message;
PROCEDURE CompareKeys(entry1, entry2: Entry): INTEGER;
PROCEDURE Init(dict: Dictionary; if: Interface; caps: CapabilitySet);
PROCEDURE Capabilities(dict: Dictionary): CapabilitySet;
PROCEDURE Add(dict: Dictionary;
key: Key; object: Disciplines.Object): BOOLEAN;
PROCEDURE Remove(dict: Dictionary; key: Key): BOOLEAN;
PROCEDURE Get(dict: Dictionary;
key: Key; VAR object: Disciplines.Object): BOOLEAN;
PROCEDURE Card(dict: Dictionary): INTEGER;
PROCEDURE GetEntries(dict: Dictionary; order: Order;
VAR it: Iterators.Iterator);
(* iteration must not be carried on over change operations *)
PROCEDURE GetCompare(dict: Dictionary; VAR compare: CompareProc);
END Dictionaries.
WS 97/98 || Entwicklung objekt-orientierter Bibliotheken || Übungen || Lösung 8
Martin Hasch, 16. Januar 1998