author | Stefan Vogel <sv@exept.de> |
Tue, 28 Apr 2020 16:22:26 +0200 | |
changeset 25375 | b784fc06a5eb |
parent 25337 | a072fff084de |
permissions | -rw-r--r-- |
25029 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5467
248b61f615c8
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
4878
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
248b61f615c8
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
4878
diff
changeset
|
15 |
|
18915 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
Object subclass:#Boolean |
1245 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Kernel-Objects' |
|
1 | 23 |
! |
24 |
||
88 | 25 |
!Boolean class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 30 |
All Rights Reserved |
1 | 31 |
|
88 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
1 | 40 |
|
88 | 41 |
documentation |
42 |
" |
|
43 |
Boolean is an abstract class defining the common protocol for logical |
|
44 |
values. The logical values are represented by its two subclasses True and False. |
|
45 |
||
46 |
There are no instances of Boolean in the system and there is only one |
|
47 |
instance of True (which is the global true) and one of False (false). |
|
1 | 48 |
|
88 | 49 |
Boolean redefines some messages which deal with copying Booleans, |
50 |
to make certain there is only one instance of each. |
|
51 |
The system will behave strange if you fiddle around here and create |
|
52 |
new instances of True or False (i.e. it will not recognize these new |
|
53 |
instances as being true or false). |
|
1294 | 54 |
|
55 |
[author:] |
|
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
56 |
Claus Gittinger |
88 | 57 |
" |
58 |
! ! |
|
1 | 59 |
|
60 |
!Boolean class methodsFor:'instance creation'! |
|
61 |
||
62 |
basicNew |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
63 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
64 |
|
1 | 65 |
"catch instance creation |
2 | 66 |
- there must be exactly one instance of each - no more" |
1 | 67 |
|
68 |
self error:'new instances of True/False are not allowed' |
|
8517 | 69 |
! |
70 |
||
71 |
readFrom:aStringOrStream onError:exceptionBlock |
|
72 |
"return a new Boolean, reading a printed representation from aStringOrStream." |
|
73 |
||
25337 | 74 |
|word| |
8517 | 75 |
|
25337 | 76 |
word := aStringOrStream readStream nextAlphaNumericWord. |
8517 | 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 |
" |
|
25337 | 93 |
|
94 |
"Modified: / 18-03-2020 / 15:09:11 / Stefan Vogel" |
|
1 | 95 |
! ! |
96 |
||
25337 | 97 |
|
98 |
||
99 |
||
100 |
||
3 | 101 |
!Boolean class methodsFor:'queries'! |
102 |
||
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
103 |
hasSharedInstances |
25029 | 104 |
"return true if this class can share instances when stored binary, |
105 |
that is, instances with the same value can be stored by reference. |
|
9147 | 106 |
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
|
107 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
108 |
^ true |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
109 |
! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
110 |
|
18915 | 111 |
isAbstract |
112 |
^ self == Boolean |
|
113 |
! |
|
114 |
||
3 | 115 |
isBuiltInClass |
1266 | 116 |
"return true if this class is known by the run-time-system. |
117 |
Here, true is returned (for my two subclasses)." |
|
3 | 118 |
|
119 |
^ true |
|
1266 | 120 |
|
121 |
"Modified: 23.4.1996 / 15:58:22 / cg" |
|
3 | 122 |
! ! |
123 |
||
698 | 124 |
|
25337 | 125 |
|
126 |
||
4878 | 127 |
!Boolean methodsFor:'blocked'! |
128 |
||
13131 | 129 |
addDependent:someOne |
130 |
"/ not really an error ... |
|
131 |
"/ self error:'should not be invoked for booleans' |
|
132 |
||
133 |
"Created: / 17-11-2010 / 13:03:25 / cg" |
|
134 |
! |
|
135 |
||
4878 | 136 |
onChangeSend:selector to:someOne |
137 |
"/ not really an error ... |
|
138 |
"/ self error:'should not be invoked for booleans' |
|
139 |
! ! |
|
140 |
||
422 | 141 |
!Boolean methodsFor:'converting'! |
142 |
||
5937 | 143 |
asBoolean |
144 |
^ self |
|
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 |
||
10944 | 166 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
12 | 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 |
||
16726 | 187 |
|
698 | 188 |
!Boolean methodsFor:'printing & storing'! |
189 |
||
190 |
printOn:aStream |
|
12163
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
191 |
"append a character sequence representing the receiver to the argument, aStream" |
698 | 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 |
||
25337 | 210 |
|
5825 | 211 |
!Boolean methodsFor:'testing'! |
212 |
||
213 |
isBoolean |
|
9448 | 214 |
"Return true, because it is a boolean." |
5825 | 215 |
|
216 |
^ true. |
|
9448 | 217 |
|
218 |
"Modified: / 17-07-2006 / 14:14:24 / cg" |
|
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 |
16726 | 241 |
"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
|
242 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
243 |
^ aVisitor visitBoolean:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
244 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
245 |
|
25337 | 246 |
|
698 | 247 |
!Boolean class methodsFor:'documentation'! |
54 | 248 |
|
698 | 249 |
version |
18915 | 250 |
^ '$Header$' |
12163
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
251 |
! |
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
252 |
|
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
253 |
version_CVS |
18915 | 254 |
^ '$Header$' |
1 | 255 |
! ! |
16726 | 256 |