author | Stefan Vogel <sv@exept.de> |
Fri, 03 Aug 2012 17:52:47 +0200 | |
changeset 14284 | da05376dea2d |
parent 14049 | 7f32280587a8 |
child 15633 | d08f9fa63cc2 |
child 18011 | deb0c3355881 |
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 |
||
13181 | 104 |
!SharedPool class methodsFor:'code generation'! |
105 |
||
106 |
initializeFrom:aDictionary |
|
13207
5f62183ab0e9
comment/format in: #initializeFrom:
Claus Gittinger <cg@exept.de>
parents:
13181
diff
changeset
|
107 |
"given a dictionary, generate my classvars and the init code" |
13181 | 108 |
|
13211 | 109 |
|sortedNames code| |
13181 | 110 |
|
13211 | 111 |
sortedNames := aDictionary keys asSortedCollection. |
112 |
self addClassVarNames:sortedNames. |
|
13181 | 113 |
|
114 |
code := String streamContents:[:s | |
|
115 |
s nextPutLine:'initialize'. |
|
13211 | 116 |
sortedNames do:[:k | |
13181 | 117 |
|v| |
118 |
||
119 |
v := aDictionary at:k. |
|
120 |
s nextPutLine:(' %1 := %2.' bindWith:k with:v storeString). |
|
121 |
]. |
|
122 |
]. |
|
123 |
self class compile:code classified:'initialization' |
|
124 |
||
125 |
" |
|
126 |
OLEStatusCodeConstants initializeFrom:aDictionary |
|
127 |
" |
|
128 |
||
129 |
"Created: / 21-12-2010 / 17:58:25 / cg" |
|
13211 | 130 |
"Modified: / 15-01-2011 / 14:20:58 / cg" |
13181 | 131 |
! ! |
132 |
||
14049 | 133 |
!SharedPool class methodsFor:'dictionary protocol'! |
134 |
||
135 |
do:aBlock |
|
136 |
"enumerate all values" |
|
137 |
||
138 |
^ self keys do:[:key | aBlock value:(self at:key)] |
|
139 |
||
140 |
"Created: / 06-03-2012 / 17:07:54 / cg" |
|
141 |
! |
|
142 |
||
143 |
includesKey:aSymbol |
|
144 |
^ self keys includes:aSymbol |
|
145 |
||
146 |
" |
|
147 |
OpenGLConstants includesKey:#GL3Bytes |
|
148 |
" |
|
149 |
! |
|
150 |
||
151 |
keyAtValue:value ifAbsent:exceptionValue |
|
152 |
self keysDo:[:k | |
|
153 |
(self at:k) == value ifTrue:[ ^ k ]. |
|
154 |
]. |
|
155 |
^ exceptionValue value |
|
156 |
||
157 |
"Created: / 08-09-2011 / 05:51:10 / cg" |
|
158 |
! |
|
159 |
||
160 |
keys |
|
161 |
"retrieve all keys (= pool var names)" |
|
162 |
||
163 |
^ self classVarNames |
|
164 |
||
165 |
" |
|
166 |
OpenGLConstants keys |
|
167 |
" |
|
168 |
||
169 |
"Modified (comment): / 06-03-2012 / 17:09:11 / cg" |
|
170 |
! |
|
171 |
||
172 |
keysAndValuesDo:aBlock |
|
173 |
"enumerate all keys (= pool var names) with their value" |
|
174 |
||
175 |
^ self keys do:[:key | aBlock value:key value:(self at:key)] |
|
176 |
||
177 |
"Created: / 06-03-2012 / 17:07:41 / cg" |
|
178 |
! |
|
179 |
||
180 |
keysDo:aBlock |
|
181 |
"enumerate all keys (= pool var names)" |
|
182 |
||
183 |
^ self keys do:aBlock |
|
184 |
||
185 |
"Modified (comment): / 06-03-2012 / 17:08:54 / cg" |
|
186 |
! ! |
|
187 |
||
13097
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
188 |
!SharedPool class methodsFor:'misc ui support'! |
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
189 |
|
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
190 |
iconInBrowserSymbol |
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
191 |
<resource: #programImage> |
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
192 |
|
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
193 |
self == SharedPool ifTrue:[^ super iconInBrowserSymbol]. |
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
194 |
^ #sharedPoolBrowserIcon |
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
195 |
|
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
196 |
"Created: / 14-10-2010 / 12:04:32 / cg" |
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
197 |
! ! |
d07ec91b3105
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
13005
diff
changeset
|
198 |
|
8538 | 199 |
!SharedPool class methodsFor:'name lookup'! |
200 |
||
12169 | 201 |
at:name |
202 |
"retrieve a pool variable by name" |
|
203 |
||
204 |
^ self at:name ifAbsent:[self errorKeyNotFound:name] |
|
205 |
! |
|
206 |
||
10853
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
207 |
at:name ifAbsent:aBlock |
12169 | 208 |
"retrieve a pool variable by name" |
209 |
||
10853
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
210 |
(self includesKey:name) ifFalse:[^ aBlock value]. |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
211 |
^ self classVarAt:name |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
212 |
! |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
213 |
|
13661 | 214 |
at:name put:aValue |
215 |
"set a pool variable by name" |
|
216 |
||
217 |
^ self classVarAt:name put:aValue |
|
218 |
||
219 |
"Created: / 08-09-2011 / 05:48:16 / cg" |
|
220 |
! |
|
221 |
||
8538 | 222 |
classBindingOf: varName |
223 |
"For initialization messages grant the regular scope" |
|
224 |
||
11305
83f14d00b6a7
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
10853
diff
changeset
|
225 |
self shouldImplement. "not yet finished" |
83f14d00b6a7
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
10853
diff
changeset
|
226 |
^ super bindingOf: varName |
8551 | 227 |
! ! |
228 |
||
229 |
!SharedPool class methodsFor:'printing & storing'! |
|
230 |
||
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
231 |
displayOn:aGCOrStream |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
232 |
"Compatibility |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
233 |
append a printed desription on some stream (Dolphin, Squeak) |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
234 |
OR: |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
235 |
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
|
236 |
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
|
237 |
(although the fallBack is to display its printString ...)" |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
238 |
|
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
239 |
"/ 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
|
240 |
"/ 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
|
241 |
aGCOrStream isStream ifFalse:[ |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
242 |
^ super displayOn:aGCOrStream. |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
243 |
]. |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
244 |
|
8551 | 245 |
"return a printed represenation - here, a reminder is appended, |
246 |
that this is not a regular class" |
|
247 |
||
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
248 |
self == NameSpace ifTrue:[ |
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 |
] ifFalse:[ |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
251 |
aGCOrStream |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
252 |
nextPutAll:self name; |
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
253 |
nextPutAll:' (* SharedPool *)'. |
8551 | 254 |
]. |
8538 | 255 |
! ! |
256 |
||
257 |
!SharedPool class methodsFor:'queries'! |
|
258 |
||
259 |
isSharedPool |
|
260 |
^ self ~~ SharedPool |
|
261 |
! ! |
|
262 |
||
263 |
!SharedPool class methodsFor:'documentation'! |
|
264 |
||
265 |
version |
|
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
266 |
^ '$Header: /cvs/stx/stx/libbasic/SharedPool.st,v 1.21 2012-08-03 15:52:47 stefan Exp $' |
12169 | 267 |
! |
268 |
||
269 |
version_CVS |
|
14284
da05376dea2d
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14049
diff
changeset
|
270 |
^ '$Header: /cvs/stx/stx/libbasic/SharedPool.st,v 1.21 2012-08-03 15:52:47 stefan Exp $' |
8538 | 271 |
! ! |