1341
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Dictionary subclass:#WeakValueDictionary
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Unordered'
|
|
18 |
!
|
|
19 |
|
|
20 |
!WeakValueDictionary class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
|
36 |
documentation
|
|
37 |
"
|
|
38 |
WeakValueDictionaries behave like Dictionaries,
|
|
39 |
as long as the values are still referenced by some
|
|
40 |
other (non-weak) object.
|
|
41 |
However, once the last non-weak reference ceases to exist,
|
|
42 |
the Dictionary will return nil for the value at position key.
|
|
43 |
(with some delay: it will be removed after the next garbage collect).
|
|
44 |
|
|
45 |
[author:]
|
|
46 |
Stefan Vogel
|
|
47 |
|
|
48 |
[See also:]
|
|
49 |
WeakArray WeakIdentityDictionary WeakIdentitySet
|
|
50 |
"
|
|
51 |
! !
|
|
52 |
|
|
53 |
!WeakValueDictionary methodsFor:'adding & removing'!
|
|
54 |
|
|
55 |
at:key put:anObject
|
|
56 |
"add the argument anObject under key, aKey to the receiver.
|
|
57 |
Return anObject (sigh).
|
|
58 |
Redefined to block interrupts, to avoid trouble when dependencies
|
|
59 |
are added within interrupting high prio processes."
|
|
60 |
|
|
61 |
|wasBlocked|
|
|
62 |
|
|
63 |
wasBlocked := OperatingSystem blockInterrupts.
|
1790
|
64 |
[
|
|
65 |
super at:key put:anObject.
|
|
66 |
] valueNowOrOnUnwindDo:[
|
|
67 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
|
|
68 |
].
|
1341
|
69 |
^ anObject
|
|
70 |
|
|
71 |
"Modified: 6.5.1996 / 12:22:26 / stefan"
|
|
72 |
"Created: 6.5.1996 / 14:47:37 / stefan"
|
1790
|
73 |
"Modified: 20.10.1996 / 14:05:04 / cg"
|
1341
|
74 |
!
|
|
75 |
|
|
76 |
removeKey:aKey ifAbsent:aBlock
|
|
77 |
"remove the association under aKey from the collection,
|
|
78 |
return the value previously stored there..
|
|
79 |
If it was not in the collection return the result
|
|
80 |
from evaluating aBlock.
|
|
81 |
|
|
82 |
Redefined to avoid synchronization problems, in case
|
|
83 |
of interrupts (otherwise, there could be some other operation
|
|
84 |
on the receiver done by another process, which garbles my contents)."
|
|
85 |
|
|
86 |
|wasBlocked ret|
|
|
87 |
|
|
88 |
wasBlocked := OperatingSystem blockInterrupts.
|
|
89 |
[
|
|
90 |
ret := super removeKey:aKey ifAbsent:aBlock
|
|
91 |
] valueNowOrOnUnwindDo:[
|
|
92 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]
|
|
93 |
].
|
|
94 |
^ ret
|
|
95 |
|
|
96 |
"Modified: 6.5.1996 / 12:44:07 / stefan"
|
|
97 |
"Created: 6.5.1996 / 14:47:37 / stefan"
|
|
98 |
!
|
|
99 |
|
|
100 |
removeValue:aKey ifAbsent:aBlock
|
|
101 |
"remove the association under aValue from the collection,
|
1351
|
102 |
return the key previously stored there..
|
1341
|
103 |
If it was not in the collection return the result
|
|
104 |
from evaluating aBlock.
|
|
105 |
|
|
106 |
Redefined to avoid synchronization problems, in case
|
|
107 |
of interrupts (otherwise, there could be some other operation
|
|
108 |
on the receiver done by another process, which garbles my contents)."
|
|
109 |
|
|
110 |
|wasBlocked ret|
|
|
111 |
|
|
112 |
wasBlocked := OperatingSystem blockInterrupts.
|
|
113 |
[
|
|
114 |
ret := super removeValue:aKey ifAbsent:aBlock
|
|
115 |
] valueNowOrOnUnwindDo:[
|
|
116 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]
|
|
117 |
].
|
|
118 |
^ ret.
|
|
119 |
|
|
120 |
"Created: 6.5.1996 / 14:47:37 / stefan"
|
1351
|
121 |
"Modified: 8.5.1996 / 14:54:09 / stefan"
|
1341
|
122 |
! !
|
|
123 |
|
|
124 |
!WeakValueDictionary methodsFor:'private'!
|
|
125 |
|
|
126 |
valueContainerOfSize:n
|
|
127 |
"return a container for values of size n.
|
|
128 |
use WeakArrays here."
|
|
129 |
|
|
130 |
^ WeakArray new:n.
|
|
131 |
|
|
132 |
"Created: 6.5.1996 / 14:47:37 / stefan"
|
|
133 |
! !
|
|
134 |
|
|
135 |
!WeakValueDictionary class methodsFor:'documentation'!
|
|
136 |
|
|
137 |
version
|
1790
|
138 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/WeakVDict.st,v 1.4 1996-10-20 15:23:49 cg Exp $'
|
1341
|
139 |
! !
|