Universität Ulm,
Fakultät für Mathematik und Wirtschaftswissenschaften,
SAI
WS 97/98 || Entwicklung objekt-orientierter Bibliotheken || Übungen || Lösung 6
DEFINITION Dictionaries
(*
* Entwicklung objekt-orientierter Bibliotheken, Aufgabe 10
*
* Abstraktion fuer assoziative Arrays.
*)
DEFINITION Dictionaries;
IMPORT ConstStrings, Disciplines, Iterators, Objects;
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: Objects.Object;
END;
Dictionary = POINTER TO DictionaryRec;
DictionaryRec =
RECORD
(Disciplines.ObjectRec)
END;
AddProc = PROCEDURE (dict: Dictionary; key: Key; object: Objects.Object);
RemoveProc = PROCEDURE (dict: Dictionary; key: Key);
GetProc = PROCEDURE (dict: Dictionary; key: Key;
VAR object: Objects.Object): BOOLEAN;
CardProc = PROCEDURE (dict: Dictionary): INTEGER;
GetEntriesProc = PROCEDURE (dict: Dictionary; order: Order;
VAR it: Iterators.Iterator);
Interface = POINTER TO InterfaceRec;
InterfaceRec =
RECORD
(Objects.ObjectRec)
add: AddProc; (* mandatory *)
remove: RemoveProc; (* optional *)
get: GetProc; (* mandatory *)
card: CardProc; (* mandatory *)
getEntries: GetEntriesProc; (* optional *)
END;
CONST
remove = 0;
getEntries = 1;
sortEntries = 2; (* specifying order makes sense *)
TYPE
CapabilitySet = SET; (* OF remove..sortEntries *)
PROCEDURE Init(dict: Dictionary; if: Interface; caps: CapabilitySet);
PROCEDURE Add(dict: Dictionary; key: Key; object: Objects.Object);
PROCEDURE Remove(dict: Dictionary; key: Key);
PROCEDURE Get(dict: Dictionary;
key: Key; VAR object: Objects.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 *)
END Dictionaries.
WS 97/98 || Entwicklung objekt-orientierter Bibliotheken || Übungen || Lösung 6
Martin Hasch, 5. Dezember 1997