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