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