author | Stefan Vogel <sv@exept.de> |
Tue, 28 Apr 2020 16:21:34 +0200 | |
changeset 25373 | f030619565e1 |
parent 24617 | c76a07d160a4 |
permissions | -rw-r--r-- |
24605 | 1 |
"{ Encoding: utf8 }" |
2 |
||
8728 | 3 |
" |
4 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
8538 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17386 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
8538 | 18 |
Object subclass:#SharedPool |
19 |
instanceVariableNames:'' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Kernel-Classes' |
|
23 |
! |
|
24 |
||
25 |
!SharedPool class methodsFor:'documentation'! |
|
26 |
||
8728 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
8538 | 41 |
documentation |
42 |
" |
|
43 |
A shared pool represents a set of bindings which are accessible to all classes |
|
44 |
which import the pool in its 'pool dictionaries'. |
|
45 |
SharedPool is NOT a dictionary but rather a name space. |
|
46 |
Bindings are represented by 'class variables' - as long as we have no better way to represent |
|
12220 | 47 |
them at least. This is done to make stc happy (or at least, to not be forced to adapt it |
48 |
to any new semantics). |
|
8538 | 49 |
" |
50 |
! ! |
|
51 |
||
13682 | 52 |
!SharedPool class methodsFor:'Compatibility-Squeak'! |
53 |
||
54 |
bindingOf: varName |
|
55 |
"Answer the binding of some variable resolved in the scope of the receiver" |
|
56 |
||
57 |
| aSymbol binding | |
|
58 |
||
59 |
"/ self shouldImplement. "not yet finished" |
|
60 |
aSymbol := varName asSymbol. |
|
61 |
||
62 |
"First look in classVar dictionary." |
|
63 |
binding := self classPool bindingOf: aSymbol. |
|
64 |
binding notNil ifTrue:[^binding]. |
|
65 |
||
66 |
"Next look in shared pools." |
|
67 |
self sharedPools do:[:pool | |
|
68 |
binding := pool bindingOf: aSymbol. |
|
69 |
binding notNil ifTrue:[^binding]. |
|
70 |
]. |
|
71 |
||
72 |
"subclassing and environment are not preserved" |
|
73 |
^nil |
|
74 |
||
75 |
"Modified: / 12-09-2011 / 09:40:36 / cg" |
|
76 |
! |
|
77 |
||
78 |
bindingsDo: aBlock |
|
79 |
self classVarNames do:[:eachKey | |
|
80 |
aBlock value:(eachKey -> (self classVarAt:eachKey)) |
|
81 |
]. |
|
82 |
||
83 |
"Modified: / 12-09-2011 / 09:42:00 / cg" |
|
84 |
! ! |
|
85 |
||
9091 | 86 |
!SharedPool class methodsFor:'Compatibility-V''Age'! |
87 |
||
88 |
declareConstant:constantName value:value |
|
89 |
self == SharedPool ifTrue:[ self error ]. |
|
90 |
||
91 |
(self classVarNames includes:constantName) ifFalse:[ |
|
92 |
self addClassVarName:constantName |
|
93 |
]. |
|
94 |
||
95 |
self classVarAt:constantName put:value. |
|
13997 | 96 |
! |
97 |
||
98 |
declareVariable:varName |
|
99 |
self == SharedPool ifTrue:[ self error ]. |
|
100 |
||
101 |
(self classVarNames includes:varName) ifFalse:[ |
|
102 |
self addClassVarName:varName |
|
103 |
]. |
|
104 |
||
105 |
"Created: / 07-02-2012 / 15:57:35 / cg" |
|
9091 | 106 |
! ! |
107 |
||
15633 | 108 |
|
13181 | 109 |
!SharedPool class methodsFor:'code generation'! |
110 |
||
111 |
initializeFrom:aDictionary |
|
13207
5f62183ab0e9
comment/format in: #initializeFrom:
Claus Gittinger <cg@exept.de>
parents:
13181
diff
changeset
|
112 |
"given a dictionary, generate my classvars and the init code" |
13181 | 113 |
|
13211 | 114 |
|sortedNames code| |
13181 | 115 |
|
13211 | 116 |
sortedNames := aDictionary keys asSortedCollection. |
117 |
self addClassVarNames:sortedNames. |
|
13181 | 118 |
|
119 |
code := String streamContents:[:s | |
|
120 |
s nextPutLine:'initialize'. |
|
13211 | 121 |
sortedNames do:[:k | |
13181 | 122 |
|v| |
123 |
||
124 |
v := aDictionary at:k. |
|
125 |
s nextPutLine:(' %1 := %2.' bindWith:k with:v storeString). |
|
126 |
]. |
|
127 |
]. |
|
128 |
self class compile:code classified:'initialization' |
|
129 |
||
130 |
" |
|
131 |
OLEStatusCodeConstants initializeFrom:aDictionary |
|
132 |
" |
|
133 |
||
134 |
"Created: / 21-12-2010 / 17:58:25 / cg" |
|
13211 | 135 |
"Modified: / 15-01-2011 / 14:20:58 / cg" |
13181 | 136 |
! ! |
137 |
||
14049 | 138 |
!SharedPool class methodsFor:'dictionary protocol'! |
139 |
||
15633 | 140 |
associationsDo:aBlock |
141 |
"enumerate all keys (= pool var names) with their value" |
|
142 |
||
24617 | 143 |
self keys do:[:key | aBlock value:(Association key:key value:(self at:key))] |
15633 | 144 |
! |
145 |
||
14049 | 146 |
do:aBlock |
147 |
"enumerate all values" |
|
148 |
||
24605 | 149 |
self keys do:[:key | aBlock value:(self at:key)] |
14049 | 150 |
|
151 |
"Created: / 06-03-2012 / 17:07:54 / cg" |
|
152 |
! |
|
153 |
||
154 |
includesKey:aSymbol |
|
155 |
^ self keys includes:aSymbol |
|
156 |
||
157 |
" |
|
158 |
OpenGLConstants includesKey:#GL3Bytes |
|
159 |
" |
|
160 |
! |
|
161 |
||
162 |
keyAtValue:value ifAbsent:exceptionValue |
|
21364 | 163 |
"return the key (= pool var name) of a value. |
164 |
This is a slow access, since the receiver is searched sequentially. |
|
165 |
NOTICE: |
|
166 |
The value is searched using identity compare; |
|
167 |
use #keyAtEqualValue:ifAbsent: to compare for equality." |
|
168 |
||
14049 | 169 |
self keysDo:[:k | |
170 |
(self at:k) == value ifTrue:[ ^ k ]. |
|
171 |
]. |
|
172 |
^ exceptionValue value |
|
173 |
||
174 |
"Created: / 08-09-2011 / 05:51:10 / cg" |
|
21364 | 175 |
"Modified (comment): / 07-02-2017 / 11:06:57 / cg" |
14049 | 176 |
! |
177 |
||
178 |
keys |
|
179 |
"retrieve all keys (= pool var names)" |
|
180 |
||
181 |
^ self classVarNames |
|
182 |
||
183 |
" |
|
184 |
OpenGLConstants keys |
|
185 |
" |
|
186 |
||
187 |
"Modified (comment): / 06-03-2012 / 17:09:11 / cg" |
|
188 |
! |
|
189 |
||
190 |
keysAndValuesDo:aBlock |
|
191 |
"enumerate all keys (= pool var names) with their value" |
|
192 |
||
17386 | 193 |
self keys do:[:key | aBlock value:key value:(self at:key)] |
14049 | 194 |
|
195 |
"Created: / 06-03-2012 / 17:07:41 / cg" |
|
196 |
! |
|
197 |
||
198 |
keysDo:aBlock |
|
199 |
"enumerate all keys (= pool var names)" |
|
200 |
||
17386 | 201 |
self keys do:aBlock |
14049 | 202 |
|
203 |
"Modified (comment): / 06-03-2012 / 17:08:54 / cg" |
|
204 |
! ! |
|
205 |
||
13097
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
206 |
|
8538 | 207 |
!SharedPool class methodsFor:'name lookup'! |
208 |
||
12169 | 209 |
at:name |
210 |
"retrieve a pool variable by name" |
|
211 |
||
212 |
^ self at:name ifAbsent:[self errorKeyNotFound:name] |
|
213 |
! |
|
214 |
||
10853
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
215 |
at:name ifAbsent:aBlock |
12169 | 216 |
"retrieve a pool variable by name" |
217 |
||
10853
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
218 |
(self includesKey:name) ifFalse:[^ aBlock value]. |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
219 |
^ self classVarAt:name |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
220 |
! |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
221 |
|
13661 | 222 |
at:name put:aValue |
223 |
"set a pool variable by name" |
|
224 |
||
225 |
^ self classVarAt:name put:aValue |
|
226 |
||
227 |
"Created: / 08-09-2011 / 05:48:16 / cg" |
|
228 |
! |
|
229 |
||
8538 | 230 |
classBindingOf: varName |
231 |
"For initialization messages grant the regular scope" |
|
232 |
||
11305
83f14d00b6a7
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
10853
diff
changeset
|
233 |
self shouldImplement. "not yet finished" |
83f14d00b6a7
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
10853
diff
changeset
|
234 |
^ super bindingOf: varName |
8551 | 235 |
! ! |
236 |
||
237 |
!SharedPool class methodsFor:'printing & storing'! |
|
238 |
||
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
239 |
displayOn:aGCOrStream |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
240 |
"Compatibility |
21763 | 241 |
append a printed description on some stream (Dolphin, Squeak) |
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
242 |
OR: |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
243 |
display the receiver in a graphicsContext at 0@0 (ST80). |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
244 |
This method allows for any object to be displayed in some view |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
245 |
(although the fallBack is to display its printString ...)" |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
246 |
|
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
247 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
248 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
249 |
aGCOrStream isStream ifFalse:[ |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
250 |
^ super displayOn:aGCOrStream. |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
251 |
]. |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
252 |
|
21763 | 253 |
"return a printed representation - here, a reminder is appended, |
8551 | 254 |
that this is not a regular class" |
255 |
||
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
256 |
self == NameSpace ifTrue:[ |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
257 |
super displayOn:aGCOrStream. |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
258 |
] ifFalse:[ |
21763 | 259 |
aGCOrStream |
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
260 |
nextPutAll:self name; |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
261 |
nextPutAll:' (* SharedPool *)'. |
8551 | 262 |
]. |
21763 | 263 |
|
264 |
"Modified (comment): / 17-05-2017 / 16:48:54 / mawalch" |
|
8538 | 265 |
! ! |
266 |
||
267 |
!SharedPool class methodsFor:'queries'! |
|
268 |
||
269 |
isSharedPool |
|
270 |
^ self ~~ SharedPool |
|
271 |
! ! |
|
272 |
||
273 |
!SharedPool class methodsFor:'documentation'! |
|
274 |
||
275 |
version |
|
19204
bdb9f988ab4d
comment/format in: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
17386
diff
changeset
|
276 |
^ '$Header$' |
12169 | 277 |
! |
278 |
||
279 |
version_CVS |
|
19204
bdb9f988ab4d
comment/format in: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
17386
diff
changeset
|
280 |
^ '$Header$' |
8538 | 281 |
! ! |
15633 | 282 |