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