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