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