initial checkin
authorClaus Gittinger <cg@exept.de>
Fri, 22 Dec 2017 15:25:48 +0100
changeset 4541 af34585a0a2f
parent 4540 9f49e01f4e9c
child 4542 aaacc5a84d00
initial checkin
VirtualDictionary.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VirtualDictionary.st	Fri Dec 22 15:25:48 2017 +0100
@@ -0,0 +1,56 @@
+"{ Package: 'stx:libbasic2' }"
+
+"{ NameSpace: Smalltalk }"
+
+Collection subclass:#VirtualDictionary
+	instanceVariableNames:'fetchBlock'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Collections-Unordered'
+!
+
+!VirtualDictionary class methodsFor:'documentation'!
+
+documentation
+"
+    a collection which looks like a (read-only) dictionary to the outside,
+    but invokes a pluggable fetchBlock to retrieve keys.
+
+    [author:]
+        cg
+
+    [instance variables:]
+
+    [class variables:]
+
+    [see also:]
+
+"
+! !
+
+!VirtualDictionary methodsFor:'accessing'!
+
+at:aKey ifAbsent:exceptionValue
+    |value|
+
+    value := fetchBlock value:aKey.
+    value isNil ifTrue:[
+        ^ exceptionValue value
+    ].
+    ^ value
+!
+
+fetchBlock:something
+    fetchBlock := something.
+! !
+
+!VirtualDictionary class methodsFor:'documentation'!
+
+version
+    ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
+! !
+