author | Claus Gittinger <cg@exept.de> |
Tue, 17 Dec 2019 17:16:09 +0100 | |
changeset 25149 | 663805b3e3ef |
parent 25029 | c16078bae17f |
child 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 |
||
74 |
|str word| |
|
75 |
||
76 |
str := aStringOrStream readStream. |
|
77 |
str skipSeparators. |
|
78 |
word := str nextAlphaNumericWord. |
|
79 |
word = 'true' ifTrue:[^ true]. |
|
80 |
word = 'false' ifTrue:[^ false]. |
|
81 |
^ exceptionBlock value. |
|
82 |
||
83 |
" |
|
84 |
Boolean readFrom:'true' |
|
85 |
Boolean readFrom:'false' |
|
86 |
Boolean readFrom:'xxx' |
|
87 |
Boolean readFrom:' true' |
|
88 |
Boolean readFrom:' false' |
|
89 |
Boolean readFrom:'true xxx' |
|
90 |
Boolean readFrom:'false xxx' |
|
91 |
||
92 |
Boolean readFromString:'true xxx' |
|
93 |
Boolean readFromString:'false xxx' |
|
94 |
" |
|
1 | 95 |
! ! |
96 |
||
3 | 97 |
!Boolean class methodsFor:'queries'! |
98 |
||
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
99 |
hasSharedInstances |
25029 | 100 |
"return true if this class can share instances when stored binary, |
101 |
that is, instances with the same value can be stored by reference. |
|
9147 | 102 |
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
|
103 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
104 |
^ true |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
105 |
! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
106 |
|
18915 | 107 |
isAbstract |
108 |
^ self == Boolean |
|
109 |
! |
|
110 |
||
3 | 111 |
isBuiltInClass |
1266 | 112 |
"return true if this class is known by the run-time-system. |
113 |
Here, true is returned (for my two subclasses)." |
|
3 | 114 |
|
115 |
^ true |
|
1266 | 116 |
|
117 |
"Modified: 23.4.1996 / 15:58:22 / cg" |
|
3 | 118 |
! ! |
119 |
||
698 | 120 |
|
4878 | 121 |
!Boolean methodsFor:'blocked'! |
122 |
||
13131 | 123 |
addDependent:someOne |
124 |
"/ not really an error ... |
|
125 |
"/ self error:'should not be invoked for booleans' |
|
126 |
||
127 |
"Created: / 17-11-2010 / 13:03:25 / cg" |
|
128 |
! |
|
129 |
||
4878 | 130 |
onChangeSend:selector to:someOne |
131 |
"/ not really an error ... |
|
132 |
"/ self error:'should not be invoked for booleans' |
|
133 |
! ! |
|
134 |
||
422 | 135 |
!Boolean methodsFor:'converting'! |
136 |
||
5937 | 137 |
asBoolean |
138 |
^ self |
|
139 |
! |
|
140 |
||
422 | 141 |
literalArrayEncoding |
1245 | 142 |
"encode myself as an array literal, from which a copy of the receiver |
143 |
can be reconstructed with #decodeAsLiteralArray." |
|
422 | 144 |
|
145 |
^ self |
|
146 |
||
147 |
"Modified: 5.9.1995 / 22:46:57 / claus" |
|
1245 | 148 |
"Modified: 22.4.1996 / 13:00:05 / cg" |
422 | 149 |
! ! |
150 |
||
1 | 151 |
!Boolean methodsFor:'copying'! |
152 |
||
159 | 153 |
copy |
154 |
"return a shallow copy of the receiver |
|
155 |
- since both true and false are unique, return the receiver" |
|
156 |
||
157 |
^ self |
|
158 |
! |
|
159 |
||
10944 | 160 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
12 | 161 |
"return a deep copy of the receiver |
162 |
- since both true and false are unique, return the receiver" |
|
163 |
||
164 |
^ self |
|
165 |
! |
|
166 |
||
698 | 167 |
shallowCopy |
168 |
"return a shallow copy of the receiver |
|
169 |
- since both true and false are unique, return the receiver" |
|
170 |
||
171 |
^ self |
|
172 |
! |
|
173 |
||
12 | 174 |
simpleDeepCopy |
175 |
"return a deep copy of the receiver |
|
176 |
- since both true and false are unique, return the receiver" |
|
177 |
||
178 |
^ self |
|
1 | 179 |
! ! |
180 |
||
16726 | 181 |
|
698 | 182 |
!Boolean methodsFor:'printing & storing'! |
183 |
||
184 |
printOn:aStream |
|
12163
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
185 |
"append a character sequence representing the receiver to the argument, aStream" |
698 | 186 |
|
187 |
aStream nextPutAll:self printString |
|
188 |
! |
|
189 |
||
190 |
storeOn:aStream |
|
191 |
"append a character sequence to the argument, aStream from which the |
|
192 |
receiver can be reconstructed using readFrom:." |
|
193 |
||
194 |
^ self printOn:aStream |
|
195 |
! |
|
196 |
||
197 |
storeString |
|
198 |
"return a character sequence to the argument, aStream from which the |
|
199 |
receiver can be reconstructed using readFrom:." |
|
200 |
||
201 |
^ self printString |
|
202 |
! ! |
|
203 |
||
5825 | 204 |
!Boolean methodsFor:'testing'! |
205 |
||
206 |
isBoolean |
|
9448 | 207 |
"Return true, because it is a boolean." |
5825 | 208 |
|
209 |
^ true. |
|
9448 | 210 |
|
211 |
"Modified: / 17-07-2006 / 14:14:24 / cg" |
|
8305 | 212 |
! |
213 |
||
214 |
isLiteral |
|
215 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
216 |
(i.e. can be used in constant arrays)" |
|
217 |
||
218 |
^ true |
|
5825 | 219 |
! ! |
4728 | 220 |
|
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
221 |
!Boolean methodsFor:'tracing'! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
222 |
|
4682 | 223 |
traceInto:aRequestor level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
224 |
"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
|
225 |
|
4682 | 226 |
^ aRequestor traceBoolean:self level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
227 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
228 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
229 |
! ! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
230 |
|
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
231 |
!Boolean methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
232 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
233 |
acceptVisitor:aVisitor with:aParameter |
16726 | 234 |
"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
|
235 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
236 |
^ aVisitor visitBoolean:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
237 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
238 |
|
698 | 239 |
!Boolean class methodsFor:'documentation'! |
54 | 240 |
|
698 | 241 |
version |
18915 | 242 |
^ '$Header$' |
12163
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
243 |
! |
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
244 |
|
bcb16f2fda53
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
10944
diff
changeset
|
245 |
version_CVS |
18915 | 246 |
^ '$Header$' |
1 | 247 |
! ! |
16726 | 248 |