author | Claus Gittinger <cg@exept.de> |
Wed, 23 Aug 2006 16:04:18 +0200 | |
changeset 9642 | d537d90286d4 |
parent 9448 | d7fd5533b1cb |
child 9656 | 453ccfd5be16 |
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. |
9147 | 99 |
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
|
100 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
101 |
^ true |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
102 |
! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
103 |
|
3 | 104 |
isBuiltInClass |
1266 | 105 |
"return true if this class is known by the run-time-system. |
106 |
Here, true is returned (for my two subclasses)." |
|
3 | 107 |
|
108 |
^ true |
|
1266 | 109 |
|
110 |
"Modified: 23.4.1996 / 15:58:22 / cg" |
|
3 | 111 |
! ! |
112 |
||
698 | 113 |
|
4878 | 114 |
!Boolean methodsFor:'blocked'! |
115 |
||
116 |
onChangeSend:selector to:someOne |
|
117 |
"/ not really an error ... |
|
118 |
"/ self error:'should not be invoked for booleans' |
|
119 |
! ! |
|
120 |
||
422 | 121 |
!Boolean methodsFor:'converting'! |
122 |
||
5937 | 123 |
asBoolean |
124 |
^ self |
|
125 |
! |
|
126 |
||
422 | 127 |
literalArrayEncoding |
1245 | 128 |
"encode myself as an array literal, from which a copy of the receiver |
129 |
can be reconstructed with #decodeAsLiteralArray." |
|
422 | 130 |
|
131 |
^ self |
|
132 |
||
133 |
"Modified: 5.9.1995 / 22:46:57 / claus" |
|
1245 | 134 |
"Modified: 22.4.1996 / 13:00:05 / cg" |
422 | 135 |
! ! |
136 |
||
1 | 137 |
!Boolean methodsFor:'copying'! |
138 |
||
159 | 139 |
copy |
140 |
"return a shallow copy of the receiver |
|
141 |
- since both true and false are unique, return the receiver" |
|
142 |
||
143 |
^ self |
|
144 |
! |
|
145 |
||
12 | 146 |
deepCopyUsing:aDictionary |
147 |
"return a deep copy of the receiver |
|
148 |
- since both true and false are unique, return the receiver" |
|
149 |
||
150 |
^ self |
|
151 |
! |
|
152 |
||
698 | 153 |
shallowCopy |
154 |
"return a shallow copy of the receiver |
|
155 |
- since both true and false are unique, return the receiver" |
|
156 |
||
157 |
^ self |
|
158 |
! |
|
159 |
||
12 | 160 |
simpleDeepCopy |
161 |
"return a deep copy of the receiver |
|
162 |
- since both true and false are unique, return the receiver" |
|
163 |
||
164 |
^ self |
|
1 | 165 |
! ! |
166 |
||
698 | 167 |
!Boolean methodsFor:'printing & storing'! |
168 |
||
169 |
printOn:aStream |
|
170 |
"append a character sequence representing the receiver to the argument, |
|
171 |
aStream" |
|
172 |
||
173 |
aStream nextPutAll:self printString |
|
174 |
! |
|
175 |
||
176 |
storeOn:aStream |
|
177 |
"append a character sequence to the argument, aStream from which the |
|
178 |
receiver can be reconstructed using readFrom:." |
|
179 |
||
180 |
^ self printOn:aStream |
|
181 |
! |
|
182 |
||
183 |
storeString |
|
184 |
"return a character sequence to the argument, aStream from which the |
|
185 |
receiver can be reconstructed using readFrom:." |
|
186 |
||
187 |
^ self printString |
|
188 |
! ! |
|
189 |
||
5825 | 190 |
!Boolean methodsFor:'testing'! |
191 |
||
192 |
isBoolean |
|
9448 | 193 |
"Return true, because it is a boolean." |
5825 | 194 |
|
195 |
^ true. |
|
9448 | 196 |
|
197 |
"Modified: / 17-07-2006 / 14:14:24 / cg" |
|
8305 | 198 |
! |
199 |
||
200 |
isLiteral |
|
201 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
202 |
(i.e. can be used in constant arrays)" |
|
203 |
||
204 |
^ true |
|
5825 | 205 |
! ! |
4728 | 206 |
|
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
207 |
!Boolean methodsFor:'tracing'! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
208 |
|
4682 | 209 |
traceInto:aRequestor level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
210 |
"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
|
211 |
|
4682 | 212 |
^ aRequestor traceBoolean:self level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
213 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
214 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
215 |
! ! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
216 |
|
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
217 |
!Boolean methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
218 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
219 |
acceptVisitor:aVisitor with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
220 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
221 |
^ aVisitor visitBoolean:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
222 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
223 |
|
698 | 224 |
!Boolean class methodsFor:'documentation'! |
54 | 225 |
|
698 | 226 |
version |
9642 | 227 |
^ '$Header: /cvs/stx/stx/libbasic/Boolean.st,v 1.36 2006-08-23 14:04:18 cg Exp $' |
1 | 228 |
! ! |