author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 16 Jun 2010 21:12:05 +0100 | |
branch | jv |
changeset 17767 | a4a32df3aa5e |
parent 17761 | b0e5971141bc |
child 17772 | 6e0b3c06c364 |
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 |
||
115 |
onChangeSend:selector to:someOne |
|
116 |
"/ not really an error ... |
|
117 |
"/ self error:'should not be invoked for booleans' |
|
118 |
! ! |
|
119 |
||
422 | 120 |
!Boolean methodsFor:'converting'! |
121 |
||
5937 | 122 |
asBoolean |
123 |
^ self |
|
124 |
! |
|
125 |
||
422 | 126 |
literalArrayEncoding |
1245 | 127 |
"encode myself as an array literal, from which a copy of the receiver |
128 |
can be reconstructed with #decodeAsLiteralArray." |
|
422 | 129 |
|
130 |
^ self |
|
131 |
||
132 |
"Modified: 5.9.1995 / 22:46:57 / claus" |
|
1245 | 133 |
"Modified: 22.4.1996 / 13:00:05 / cg" |
422 | 134 |
! ! |
135 |
||
1 | 136 |
!Boolean methodsFor:'copying'! |
137 |
||
159 | 138 |
copy |
139 |
"return a shallow copy of the receiver |
|
140 |
- since both true and false are unique, return the receiver" |
|
141 |
||
142 |
^ self |
|
143 |
! |
|
144 |
||
10944 | 145 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
12 | 146 |
"return a deep copy of the receiver |
147 |
- since both true and false are unique, return the receiver" |
|
148 |
||
149 |
^ self |
|
150 |
! |
|
151 |
||
698 | 152 |
shallowCopy |
153 |
"return a shallow copy of the receiver |
|
154 |
- since both true and false are unique, return the receiver" |
|
155 |
||
156 |
^ self |
|
157 |
! |
|
158 |
||
12 | 159 |
simpleDeepCopy |
160 |
"return a deep copy of the receiver |
|
161 |
- since both true and false are unique, return the receiver" |
|
162 |
||
163 |
^ self |
|
1 | 164 |
! ! |
165 |
||
698 | 166 |
!Boolean methodsFor:'printing & storing'! |
167 |
||
168 |
printOn:aStream |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
169 |
"append a character sequence representing the receiver to the argument, aStream" |
698 | 170 |
|
171 |
aStream nextPutAll:self printString |
|
172 |
! |
|
173 |
||
174 |
storeOn:aStream |
|
175 |
"append a character sequence to the argument, aStream from which the |
|
176 |
receiver can be reconstructed using readFrom:." |
|
177 |
||
178 |
^ self printOn:aStream |
|
179 |
! |
|
180 |
||
181 |
storeString |
|
182 |
"return a character sequence to the argument, aStream from which the |
|
183 |
receiver can be reconstructed using readFrom:." |
|
184 |
||
185 |
^ self printString |
|
186 |
! ! |
|
187 |
||
5825 | 188 |
!Boolean methodsFor:'testing'! |
189 |
||
190 |
isBoolean |
|
9448 | 191 |
"Return true, because it is a boolean." |
5825 | 192 |
|
193 |
^ true. |
|
9448 | 194 |
|
195 |
"Modified: / 17-07-2006 / 14:14:24 / cg" |
|
8305 | 196 |
! |
197 |
||
198 |
isLiteral |
|
199 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
200 |
(i.e. can be used in constant arrays)" |
|
201 |
||
202 |
^ true |
|
5825 | 203 |
! ! |
4728 | 204 |
|
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
205 |
!Boolean methodsFor:'tracing'! |
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
206 |
|
4682 | 207 |
traceInto:aRequestor level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
208 |
"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
|
209 |
|
4682 | 210 |
^ aRequestor traceBoolean:self level:level from:referrer |
4656
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
211 |
|
aa895a9835a2
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
3070
diff
changeset
|
212 |
|
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 |
|
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
215 |
!Boolean methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
216 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8305
diff
changeset
|
217 |
acceptVisitor:aVisitor with:aParameter |
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 |
^ aVisitor visitBoolean:self 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 |
|
698 | 222 |
!Boolean class methodsFor:'documentation'! |
54 | 223 |
|
698 | 224 |
version |
17767 | 225 |
^ '$Id: Boolean.st 10527 2010-06-16 20:12:05Z vranyj1 $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
226 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
227 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
228 |
version_CVS |
17767 | 229 |
^ 'Header: /cvs/stx/stx/libbasic/Boolean.st,v 1.40 2010-01-21 11:48:59 cg Exp ยง' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17747
diff
changeset
|
230 |
! |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17732
diff
changeset
|
231 |
|
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17747
diff
changeset
|
232 |
version_SVN |
17767 | 233 |
^ '$Id: Boolean.st 10527 2010-06-16 20:12:05Z vranyj1 $' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17747
diff
changeset
|
234 |
! ! |
17767 | 235 |