author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 13 Feb 2012 19:19:41 +0000 | |
branch | jv |
changeset 17921 | 4069fe8e9039 |
parent 17911 | a99f15c5efa5 |
child 17928 | 8e8dad2e6269 |
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 |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
43 |
them at least. This is done to make stc happy (or at least, to not be forced to adapt it |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
44 |
to any new semantics). |
8538 | 45 |
" |
46 |
! ! |
|
47 |
||
17862 | 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. |
|
17921 | 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 |
||
17815 | 104 |
!SharedPool class methodsFor:'code generation'! |
105 |
||
106 |
initializeFrom:aDictionary |
|
107 |
"given a dictionary, generate my classvars and the init code" |
|
108 |
||
109 |
|sortedNames code| |
|
110 |
||
111 |
sortedNames := aDictionary keys asSortedCollection. |
|
112 |
self addClassVarNames:sortedNames. |
|
113 |
||
114 |
code := String streamContents:[:s | |
|
115 |
s nextPutLine:'initialize'. |
|
116 |
sortedNames do:[:k | |
|
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" |
|
130 |
"Modified: / 15-01-2011 / 14:20:58 / cg" |
|
131 |
! ! |
|
132 |
||
17807 | 133 |
!SharedPool class methodsFor:'misc ui support'! |
134 |
||
135 |
iconInBrowserSymbol |
|
136 |
<resource: #programImage> |
|
137 |
||
138 |
self == SharedPool ifTrue:[^ super iconInBrowserSymbol]. |
|
139 |
^ #sharedPoolBrowserIcon |
|
140 |
||
141 |
"Created: / 14-10-2010 / 12:04:32 / cg" |
|
142 |
! ! |
|
143 |
||
8538 | 144 |
!SharedPool class methodsFor:'name lookup'! |
145 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
146 |
at:name |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
147 |
"retrieve a pool variable by name" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
148 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
149 |
^ self at:name ifAbsent:[self errorKeyNotFound:name] |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
150 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
151 |
|
10853
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
152 |
at:name ifAbsent:aBlock |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
153 |
"retrieve a pool variable by name" |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
154 |
|
10853
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
155 |
(self includesKey:name) ifFalse:[^ aBlock value]. |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
156 |
^ self classVarAt:name |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
157 |
! |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
158 |
|
17862 | 159 |
at:name put:aValue |
160 |
"set a pool variable by name" |
|
8538 | 161 |
|
17862 | 162 |
^ self classVarAt:name put:aValue |
8538 | 163 |
|
17862 | 164 |
"Created: / 08-09-2011 / 05:48:16 / cg" |
8538 | 165 |
! |
166 |
||
167 |
classBindingOf: varName |
|
168 |
"For initialization messages grant the regular scope" |
|
169 |
||
11305
83f14d00b6a7
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
10853
diff
changeset
|
170 |
self shouldImplement. "not yet finished" |
83f14d00b6a7
Change #halt: to #shouldImplement or #assert:
Stefan Vogel <sv@exept.de>
parents:
10853
diff
changeset
|
171 |
^ super bindingOf: varName |
8551 | 172 |
! |
173 |
||
174 |
includesKey:aSymbol |
|
175 |
^ self keys includes:aSymbol |
|
176 |
||
177 |
" |
|
178 |
OpenGLConstants includesKey:#GL3Bytes |
|
179 |
" |
|
180 |
! |
|
181 |
||
17862 | 182 |
keyAtValue:value ifAbsent:exceptionValue |
183 |
self keysDo:[:k | |
|
184 |
(self at:k) == value ifTrue:[ ^ k ]. |
|
185 |
]. |
|
186 |
^ exceptionValue value |
|
187 |
||
188 |
"Created: / 08-09-2011 / 05:51:10 / cg" |
|
189 |
! |
|
190 |
||
8551 | 191 |
keys |
192 |
^ self classVarNames |
|
193 |
||
194 |
" |
|
195 |
OpenGLConstants keys |
|
196 |
" |
|
10853
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
197 |
! |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
198 |
|
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
199 |
keysDo:aBlock |
72acafda369f
dictionary compatible protocol added
Claus Gittinger <cg@exept.de>
parents:
9091
diff
changeset
|
200 |
^ self keys do:aBlock |
8551 | 201 |
! ! |
202 |
||
203 |
!SharedPool class methodsFor:'printing & storing'! |
|
204 |
||
205 |
displayString |
|
206 |
"return a printed represenation - here, a reminder is appended, |
|
207 |
that this is not a regular class" |
|
208 |
||
209 |
self == SharedPool ifTrue:[ |
|
210 |
^ super displayString |
|
211 |
]. |
|
212 |
^ self name , ' (* SharedPool *)' |
|
8538 | 213 |
! ! |
214 |
||
215 |
!SharedPool class methodsFor:'queries'! |
|
216 |
||
217 |
isSharedPool |
|
218 |
^ self ~~ SharedPool |
|
219 |
! ! |
|
220 |
||
221 |
!SharedPool class methodsFor:'documentation'! |
|
222 |
||
223 |
version |
|
17921 | 224 |
^ '$Header: /cvs/stx/stx/libbasic/SharedPool.st,v 1.19 2012/02/07 14:58:03 cg Exp $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
225 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
226 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
227 |
version_CVS |
17921 | 228 |
^ 'Header: /cvs/stx/stx/libbasic/SharedPool.st,v 1.19 2012/02/07 14:58:03 cg Exp ' |
17865 | 229 |
! |
230 |
||
231 |
version_SVN |
|
17921 | 232 |
^ '$Id: SharedPool.st 10777 2012-02-13 19:19:41Z vranyj1 $' |
17846 | 233 |
! ! |
17892 | 234 |
|
17910 | 235 |
|
17911 | 236 |
|
17921 | 237 |