author | Claus Gittinger <cg@exept.de> |
Tue, 26 Feb 2008 11:29:14 +0100 | |
changeset 1930 | 935b2870be2e |
parent 1624 | 1af2724496b2 |
child 3089 | c0936306138e |
permissions | -rw-r--r-- |
166 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
1624 | 3 |
All Rights Reserved |
166 | 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 |
||
936 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
1621 | 15 |
PeekableStream subclass:#ActorStream |
1624 | 16 |
instanceVariableNames:'nextPutBlock nextPutAllBlock nextPutLineBlock nextBlock |
17 |
atEndBlock peekBlock contentsSpecies' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Streams' |
|
166 | 21 |
! |
22 |
||
23 |
!ActorStream class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
1624 | 28 |
All Rights Reserved |
166 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
This class provides a hook for general objects to behave like Stream objects. |
|
42 |
To the outside, actorStreams behave like streams and respond to the |
|
43 |
usual stream messages (i.e. nextPut:, nextPutAll: etc). |
|
44 |
In the inside, for every nextPut-message, the nextPutBlock is evaluated |
|
45 |
passing the argument of nextPut: as block argument. |
|
46 |
||
47 |
These blocks are to be provided by the user of the ActorStream. |
|
48 |
Example use is in the Transcript, which is made Stream-like this way. |
|
49 |
||
252 | 50 |
[Instance variables:] |
51 |
nextPutBlock <Block> the block to evaluate for nextPut:-messages |
|
52 |
nextPutAllBlock <Block> same for nextPutAll:-messages |
|
53 |
nextBlock <Block> the Block to evaluate for the next element |
|
54 |
||
259 | 55 |
[author:] |
56 |
Claus Gittinger |
|
57 |
||
252 | 58 |
[See also:] |
59 |
TextCollector |
|
60 |
||
166 | 61 |
" |
62 |
! ! |
|
63 |
||
64 |
!ActorStream class methodsFor:'instance creation'! |
|
65 |
||
66 |
new |
|
67 |
"have to re-allow new - it was disabled in Stream" |
|
68 |
^ self basicNew |
|
69 |
! ! |
|
70 |
||
1624 | 71 |
!ActorStream methodsFor:'accessing'! |
72 |
||
73 |
contentsSpecies |
|
74 |
^ contentsSpecies ? String |
|
75 |
! |
|
76 |
||
77 |
contentsSpecies:something |
|
78 |
contentsSpecies := something. |
|
79 |
! ! |
|
80 |
||
166 | 81 |
!ActorStream methodsFor:'accessing-read/write'! |
82 |
||
83 |
next |
|
84 |
"return the next element from the stream by evaluating the nextBlock" |
|
85 |
||
86 |
nextBlock notNil ifTrue:[ |
|
1624 | 87 |
^ nextBlock value |
166 | 88 |
]. |
89 |
self error:'action for next is undefined' |
|
90 |
! |
|
91 |
||
92 |
nextPut:something |
|
93 |
"put something onto the stream by evaluating the nextPutBlock with |
|
94 |
something as argument" |
|
95 |
||
987 | 96 |
nextPutBlock notNil ifTrue:[ |
97 |
^ nextPutBlock value:something |
|
166 | 98 |
]. |
1008
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
99 |
nextPutAllBlock notNil ifTrue:[ |
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
100 |
"/ fallBack to nextPutAll. |
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
101 |
self nextPutAll:(something asString). |
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
102 |
^ self |
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
103 |
]. |
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
104 |
self error:'action for nextPut:/nextPutAll: are undefined' |
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
105 |
|
67f75385259a
allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents:
987
diff
changeset
|
106 |
"Modified: / 28.1.2002 / 20:59:32 / micha" |
166 | 107 |
! |
108 |
||
109 |
nextPutAll:something |
|
110 |
"put all elements of something onto the stream by evaluating |
|
987 | 111 |
the nextPutAllBlock with something as argument. |
112 |
If there is no nextPutAllBlock, nextPuts will be used (as inherited)" |
|
166 | 113 |
|
987 | 114 |
nextPutAllBlock notNil ifTrue:[ |
115 |
^ nextPutAllBlock value:something |
|
166 | 116 |
]. |
117 |
super nextPutAll:something |
|
554
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
118 |
! |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
119 |
|
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
120 |
nextPutByte:something |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
121 |
"put something onto the stream by evaluating the nextPutBlock with |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
122 |
something as argument" |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
123 |
|
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
124 |
self nextPut:(something asCharacter) |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
125 |
|
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
126 |
"Created: 6.8.1997 / 00:44:32 / cg" |
987 | 127 |
! |
128 |
||
129 |
nextPutLine:something |
|
130 |
"put the line onto the stream by evaluating |
|
131 |
the nextPutLineBlock with something as argument. |
|
132 |
If there is no nextPutLineBlock, nextPutAll/nextPut will be used (as inherited)" |
|
133 |
||
134 |
nextPutLineBlock notNil ifTrue:[ |
|
135 |
^ nextPutLineBlock value:something |
|
136 |
]. |
|
137 |
super nextPutLine:something |
|
1621 | 138 |
! |
139 |
||
140 |
peek |
|
141 |
"peek ahead for return the next element from the stream by evaluating the peekBlock" |
|
142 |
||
143 |
peekBlock notNil ifTrue:[ |
|
144 |
^ peekBlock value |
|
145 |
]. |
|
146 |
self error:'action for peek is undefined' |
|
147 |
! ! |
|
148 |
||
149 |
!ActorStream methodsFor:'converting'! |
|
150 |
||
151 |
readStream |
|
152 |
"return a readStream from the receiver. |
|
153 |
Since this is (hopefully) already a readStream, return self." |
|
154 |
||
155 |
^ self |
|
166 | 156 |
! ! |
157 |
||
158 |
!ActorStream methodsFor:'defining actions'! |
|
159 |
||
936 | 160 |
atEndBlock:aBlock |
161 |
"define the block to be evaluated for every atEnd-message" |
|
162 |
||
163 |
atEndBlock := aBlock |
|
164 |
! |
|
165 |
||
166 | 166 |
nextBlock:aBlock |
167 |
"define the block to be evaluated for every next-message" |
|
168 |
||
169 |
nextBlock := aBlock |
|
170 |
! |
|
171 |
||
172 |
nextPutAllBlock:aBlock |
|
987 | 173 |
"define the block to be evaluated for every nextPutAll-message. |
174 |
If undefined, nextPuts will be used (as inherited)" |
|
166 | 175 |
|
176 |
nextPutAllBlock := aBlock |
|
177 |
! |
|
178 |
||
179 |
nextPutBlock:aBlock |
|
180 |
"define the block to be evaluated for every nextPut-message" |
|
181 |
||
182 |
nextPutBlock := aBlock |
|
987 | 183 |
! |
184 |
||
185 |
nextPutLineBlock:aBlock |
|
186 |
"define the block to be evaluated for every nextPutLineBlock-message. |
|
187 |
If undefined, nextPutAll/nextPut will be used (as inherited)" |
|
188 |
||
189 |
nextPutLineBlock := aBlock |
|
1621 | 190 |
! |
191 |
||
192 |
peekBlock:aBlock |
|
193 |
"define the block to be evaluated for every peek-message" |
|
194 |
||
195 |
peekBlock := aBlock |
|
166 | 196 |
! ! |
197 |
||
198 |
!ActorStream methodsFor:'queries'! |
|
199 |
||
200 |
atEnd |
|
201 |
"return true, if at the end - actorStreams are never" |
|
202 |
||
936 | 203 |
atEndBlock isNil ifTrue:[ |
204 |
^ false |
|
205 |
]. |
|
206 |
^ atEndBlock value |
|
166 | 207 |
! ! |
208 |
||
209 |
!ActorStream class methodsFor:'documentation'! |
|
210 |
||
211 |
version |
|
1624 | 212 |
^ '$Header: /cvs/stx/stx/libbasic2/ActorStream.st,v 1.11 2006-04-03 07:37:08 cg Exp $' |
166 | 213 |
! ! |