0
|
1 |
"
|
3
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
ReadWriteStream subclass:#ActorStream
|
|
14 |
instanceVariableNames:'nextPutBlock nextPutAllBlock nextBlock'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Streams'
|
|
18 |
!
|
|
19 |
|
|
20 |
ActorStream comment:'
|
|
21 |
|
3
|
22 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
0
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
This class provides a hook for general objects to behave like Streams;
|
|
26 |
To the outside, ActorStreams behave like streams and respond to the
|
|
27 |
usual streams messages (i.e. nextPut:).
|
|
28 |
In the inside, for every nextPut-message, the nextPutBlock is evaluated
|
|
29 |
with the argument to perform the put; same is true for nextPutAll: and next;
|
|
30 |
These blocks are to be provided by the user of the ActorStream.
|
|
31 |
|
|
32 |
Instance variables:
|
|
33 |
|
|
34 |
nextPutBlock <Block> the block to evaluate for nextPut:-messages
|
|
35 |
nextPutAllBlock <Block> same for nextPutAll:-messages
|
|
36 |
nextBlock <Block> the Block to evaluate for the next element
|
|
37 |
|
3
|
38 |
$Header: /cvs/stx/stx/libbasic/Attic/ActorStr.st,v 1.3 1993-10-13 00:14:10 claus Exp $
|
0
|
39 |
written winter 89 by claus
|
|
40 |
'!
|
|
41 |
|
|
42 |
!ActorStream class methodsFor:'instance creation'!
|
|
43 |
|
|
44 |
new
|
|
45 |
"have to re-allow new - it was disabled in Stream"
|
|
46 |
^ self basicNew
|
|
47 |
! !
|
|
48 |
|
|
49 |
!ActorStream methodsFor:'defining actions'!
|
|
50 |
|
|
51 |
nextBlock:aBlock
|
|
52 |
"define the block to be evaluated for every next-message"
|
|
53 |
|
|
54 |
nextBlock := aBlock
|
|
55 |
!
|
|
56 |
|
|
57 |
nextPutBlock:aBlock
|
|
58 |
"define the block to be evaluated for every nextPut-message"
|
|
59 |
|
|
60 |
nextPutBlock := aBlock
|
|
61 |
!
|
|
62 |
|
|
63 |
nextPutAllBlock:aBlock
|
|
64 |
"define the block to be evaluated for every nextPutAll-message"
|
|
65 |
|
|
66 |
nextPutAllBlock := aBlock
|
|
67 |
! !
|
|
68 |
|
|
69 |
!ActorStream methodsFor:'accessing-read/write'!
|
|
70 |
|
|
71 |
next
|
|
72 |
"return the next element from the stream by evaluating the nextBlock"
|
|
73 |
|
|
74 |
nextBlock notNil ifTrue:[
|
|
75 |
^ nextBlock value
|
|
76 |
].
|
|
77 |
self error:'action for next is undefined'
|
|
78 |
!
|
|
79 |
|
|
80 |
nextPut:something
|
|
81 |
"put something onto the stream by evaluating the nextPutBlock with
|
|
82 |
something as argument"
|
|
83 |
|
|
84 |
nextPutBlock notNil ifTrue:[
|
|
85 |
^ nextPutBlock value:something
|
|
86 |
].
|
|
87 |
self error:'action for nextPut is undefined'
|
|
88 |
!
|
|
89 |
|
|
90 |
nextPutAll:something
|
|
91 |
"put all elements of something onto the stream by evaluating
|
|
92 |
the nextPutAllBlock with something as argument"
|
|
93 |
|
|
94 |
nextPutAllBlock notNil ifTrue:[
|
|
95 |
^ nextPutAllBlock value:something
|
|
96 |
].
|
|
97 |
super nextPutAll:something
|
|
98 |
! !
|