author | Claus Gittinger <cg@exept.de> |
Sat, 04 May 2019 12:32:23 +0200 | |
changeset 4940 | d5d7391bc875 |
parent 4790 | bacf758a10cc |
child 4968 | 99de1b56d09f |
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:[ |
|
4790 | 145 |
nextPutAllBlock value:(something copyFrom:start to:stop). |
146 |
^ self. |
|
3469 | 147 |
]. |
148 |
super nextPutAll:something startingAt:start to:stop |
|
4768 | 149 |
|
150 |
"Modified: / 22-11-2018 / 12:52:51 / Stefan Vogel" |
|
4790 | 151 |
"Modified: / 14-01-2019 / 18:23:40 / Claus Gittinger" |
3469 | 152 |
! |
153 |
||
554
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
154 |
nextPutByte:something |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
155 |
"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
|
156 |
something as argument" |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
157 |
|
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
158 |
self nextPut:(something asCharacter) |
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
159 |
|
84eb4d58dd04
allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents:
446
diff
changeset
|
160 |
"Created: 6.8.1997 / 00:44:32 / cg" |
987 | 161 |
! |
162 |
||
163 |
nextPutLine:something |
|
164 |
"put the line onto the stream by evaluating |
|
165 |
the nextPutLineBlock with something as argument. |
|
166 |
If there is no nextPutLineBlock, nextPutAll/nextPut will be used (as inherited)" |
|
167 |
||
168 |
nextPutLineBlock notNil ifTrue:[ |
|
169 |
^ nextPutLineBlock value:something |
|
170 |
]. |
|
171 |
super nextPutLine:something |
|
1621 | 172 |
! |
173 |
||
174 |
peek |
|
175 |
"peek ahead for return the next element from the stream by evaluating the peekBlock" |
|
176 |
||
177 |
peekBlock notNil ifTrue:[ |
|
178 |
^ peekBlock value |
|
179 |
]. |
|
180 |
self error:'action for peek is undefined' |
|
181 |
! ! |
|
182 |
||
183 |
!ActorStream methodsFor:'converting'! |
|
184 |
||
185 |
readStream |
|
186 |
"return a readStream from the receiver. |
|
187 |
Since this is (hopefully) already a readStream, return self." |
|
188 |
||
189 |
^ self |
|
166 | 190 |
! ! |
191 |
||
192 |
!ActorStream methodsFor:'defining actions'! |
|
193 |
||
936 | 194 |
atEndBlock:aBlock |
195 |
"define the block to be evaluated for every atEnd-message" |
|
196 |
||
197 |
atEndBlock := aBlock |
|
198 |
! |
|
199 |
||
166 | 200 |
nextBlock:aBlock |
201 |
"define the block to be evaluated for every next-message" |
|
202 |
||
203 |
nextBlock := aBlock |
|
204 |
! |
|
205 |
||
206 |
nextPutAllBlock:aBlock |
|
987 | 207 |
"define the block to be evaluated for every nextPutAll-message. |
208 |
If undefined, nextPuts will be used (as inherited)" |
|
166 | 209 |
|
210 |
nextPutAllBlock := aBlock |
|
211 |
! |
|
212 |
||
213 |
nextPutBlock:aBlock |
|
214 |
"define the block to be evaluated for every nextPut-message" |
|
215 |
||
216 |
nextPutBlock := aBlock |
|
987 | 217 |
! |
218 |
||
219 |
nextPutLineBlock:aBlock |
|
220 |
"define the block to be evaluated for every nextPutLineBlock-message. |
|
221 |
If undefined, nextPutAll/nextPut will be used (as inherited)" |
|
222 |
||
223 |
nextPutLineBlock := aBlock |
|
1621 | 224 |
! |
225 |
||
226 |
peekBlock:aBlock |
|
227 |
"define the block to be evaluated for every peek-message" |
|
228 |
||
229 |
peekBlock := aBlock |
|
166 | 230 |
! ! |
231 |
||
232 |
!ActorStream methodsFor:'queries'! |
|
233 |
||
234 |
atEnd |
|
235 |
"return true, if at the end - actorStreams are never" |
|
236 |
||
936 | 237 |
atEndBlock isNil ifTrue:[ |
238 |
^ false |
|
239 |
]. |
|
240 |
^ atEndBlock value |
|
166 | 241 |
! ! |
242 |
||
243 |
!ActorStream class methodsFor:'documentation'! |
|
244 |
||
245 |
version |
|
4768 | 246 |
^ '$Header$' |
166 | 247 |
! ! |
3089 | 248 |