author | Stefan Vogel <sv@exept.de> |
Wed, 22 Sep 2004 16:42:22 +0200 | |
changeset 8586 | a38e882affa5 |
parent 8517 | c3827ae1ead2 |
child 8830 | df7adfaf1a57 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
12 |
||
5467
248b61f615c8
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
4878
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
248b61f615c8
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
4878
diff
changeset
|
14 |
|
1 | 15 |
Object subclass:#Boolean |
1245 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Kernel-Objects' |
|
1 | 20 |
! |
21 |
||
88 | 22 |
!Boolean class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
40 |
Boolean is an abstract class defining the common protocol for logical |
|
41 |
values. The logical values are represented by its two subclasses True and False. |
|
42 |
||
43 |
There are no instances of Boolean in the system and there is only one |
|
44 |
instance of True (which is the global true) and one of False (false). |
|
1 | 45 |
|
88 | 46 |
Boolean redefines some messages which deal with copying Booleans, |
47 |
to make certain there is only one instance of each. |
|
48 |
The system will behave strange if you fiddle around here and create |
|
49 |
new instances of True or False (i.e. it will not recognize these new |
|
50 |
instances as being true or false). |
|
1294 | 51 |
|
52 |
[author:] |
|
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
53 |
Claus Gittinger |
88 | 54 |
" |
55 |
! ! |
|
1 | 56 |
|
57 |
!Boolean class methodsFor:'instance creation'! |
|
58 |
||
59 |
basicNew |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
60 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
61 |
|
1 | 62 |
"catch instance creation |
2 | 63 |
- there must be exactly one instance of each - no more" |
1 | 64 |
|
65 |
self error:'new instances of True/False are not allowed' |
|
8517 | 66 |
! |
67 |
||
68 |
readFrom:aStringOrStream onError:exceptionBlock |
|
69 |
"return a new Boolean, reading a printed representation from aStringOrStream." |
|
70 |
||
71 |
|str word| |
|
72 |
||
73 |
str := aStringOrStream readStream. |
|
74 |
str skipSeparators. |
|
75 |
word := str nextAlphaNumericWord. |
|
76 |
word = 'true' ifTrue:[^ true]. |
|
77 |
word = 'false' ifTrue:[^ false]. |
|
78 |
^ exceptionBlock value. |
|
79 |
||
80 |
" |
|
81 |
Boolean readFrom:'true' |
|
82 |
Boolean readFrom:'false' |
|
83 |
Boolean readFrom:'xxx' |
|
84 |
Boolean readFrom:' true' |
|
85 |
Boolean readFrom:' false' |
|
86 |
Boolean readFrom:'true xxx' |
|
87 |
Boolean readFrom:'false xxx' |
|
88 |
||
89 |
Boolean readFromString:'true xxx' |
|
90 |
Boolean readFromString:'false xxx' |
|
91 |
" |
|
1 | 92 |
! ! |
93 |
||
3 | 94 |
!Boolean class methodsFor:'queries'! |
95 |
||
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
96 |
hasSharedInstances |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
97 |
"return true if this class has shared instances, that is, instances |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
98 |
with the same value are identical. |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
99 |
False is returned here, only redefined in classes which have unified |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
100 |
instances (or should be treated so)." |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
101 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
102 |
^ true |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
103 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
104 |
! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
105 |
|
3 | 106 |
isBuiltInClass |
1266 | 107 |
"return true if this class is known by the run-time-system. |
108 |
Here, true is returned (for my two subclasses)." |
|
3 | 109 |
|
110 |
^ true |
|
1266 | 111 |
|
112 |
"Modified: 23.4.1996 / 15:58:22 / cg" |
|
3 | 113 |
! ! |
114 |
||
698 | 115 |
!Boolean methodsFor:'binary storage'! |
116 |
||
117 |
hasSpecialBinaryRepresentation |
|
118 |
"return true, if the receiver has a special binary representation" |
|
119 |
||
3070 | 120 |
^ true |
698 | 121 |
! ! |
122 |
||
4878 | 123 |
!Boolean methodsFor:'blocked'! |
124 |
||
125 |
onChangeSend:selector to:someOne |
|
126 |
"/ not really an error ... |
|
127 |
"/ self error:'should not be invoked for booleans' |
|
128 |
! ! |
|
129 |
||
422 | 130 |
!Boolean methodsFor:'converting'! |
131 |
||
5937 | 132 |
asBoolean |
133 |
^ self |
|
134 |
! |
|
135 |
||
2416 | 136 |
decodeAsLiteralArray |
137 |
"given a literalEncoding in the receiver, |
|
138 |
create & return the corresponding object. |
|
139 |
The inverse operation to #literalArrayEncoding." |
|
140 |
||
141 |
^ self |
|
142 |
||
143 |
"Created: 25.2.1997 / 19:16:43 / cg" |
|
144 |
"Modified: 25.2.1997 / 19:17:45 / cg" |
|
145 |
! |
|
146 |
||
422 | 147 |
literalArrayEncoding |
1245 | 148 |
"encode myself as an array literal, from which a copy of the receiver |
149 |
can be reconstructed with #decodeAsLiteralArray." |
|
422 | 150 |
|
151 |
^ self |
|
152 |
||
153 |
"Modified: 5.9.1995 / 22:46:57 / claus" |
|
1245 | 154 |
"Modified: 22.4.1996 / 13:00:05 / cg" |
422 | 155 |
! ! |
156 |
||
1 | 157 |
!Boolean methodsFor:'copying'! |
158 |
||
159 | 159 |
copy |
160 |
"return a shallow copy of the receiver |
|
161 |
- since both true and false are unique, return the receiver" |
|
162 |
||
163 |
^ self |
|
164 |
! |
|
165 |
||
12 | 166 |
deepCopyUsing:aDictionary |
167 |
"return a deep copy of the receiver |
|
168 |
- since both true and false are unique, return the receiver" |
|
169 |
||
170 |
^ self |
|
171 |
! |
|
172 |
||
698 | 173 |
shallowCopy |
174 |
"return a shallow copy of the receiver |
|
175 |
- since both true and false are unique, return the receiver" |
|
176 |
||
177 |
^ self |
|
178 |
! |
|
179 |
||
12 | 180 |
simpleDeepCopy |
181 |
"return a deep copy of the receiver |
|
182 |
- since both true and false are unique, return the receiver" |
|
183 |
||
184 |
^ self |
|
1 | 185 |
! ! |
186 |
||
698 | 187 |
!Boolean methodsFor:'printing & storing'! |
188 |
||
189 |
printOn:aStream |
|
190 |
"append a character sequence representing the receiver to the argument, |
|
191 |
aStream" |
|
192 |
||
193 |
aStream nextPutAll:self printString |
|
194 |
! |
|
195 |
||
196 |
storeOn:aStream |
|
197 |
"append a character sequence to the argument, aStream from which the |
|
198 |
receiver can be reconstructed using readFrom:." |
|
199 |
||
200 |
^ self printOn:aStream |
|
201 |
! |
|
202 |
||
203 |
storeString |
|
204 |
"return a character sequence to the argument, aStream from which the |
|
205 |
receiver can be reconstructed using readFrom:." |
|
206 |
||
207 |
^ self printString |
|
208 |
! ! |
|
209 |
||
5825 | 210 |
!Boolean methodsFor:'testing'! |
211 |
||
212 |
isBoolean |
|
213 |
||
214 |
" |
|
215 |
Return true, because it is a boolean. |
|
216 |
" |
|
217 |
||
218 |
^ true. |
|
8305 | 219 |
! |
220 |
||
221 |
isLiteral |
|
222 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
223 |
(i.e. can be used in constant arrays)" |
|
224 |
||
225 |
^ true |
|
5825 | 226 |
! ! |
4728 | 227 |
|
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
228 |
!Boolean methodsFor:'tracing'! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
229 |
|
4682 | 230 |
traceInto:aRequestor level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
231 |
"double dispatch into tracer, passing my type implicitely in the selector" |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
232 |
|
4682 | 233 |
^ aRequestor traceBoolean:self level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
234 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
235 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
236 |
! ! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
237 |
|
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
238 |
!Boolean methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
239 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
240 |
acceptVisitor:aVisitor with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
241 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
242 |
^ aVisitor visitBoolean:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
243 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
244 |
|
698 | 245 |
!Boolean class methodsFor:'documentation'! |
54 | 246 |
|
698 | 247 |
version |
8517 | 248 |
^ '$Header: /cvs/stx/stx/libbasic/Boolean.st,v 1.32 2004-09-03 17:11:36 cg Exp $' |
1 | 249 |
! ! |