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