"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
Stream subclass:#ActorStream
instanceVariableNames:'nextPutBlock nextPutAllBlock nextBlock'
classVariableNames:''
poolDictionaries:''
category:'Streams'
!
ActorStream comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
$Header: /cvs/stx/stx/libbasic/Attic/ActorStr.st,v 1.6 1994-02-25 12:53:21 claus Exp $
written winter 89 by claus
'!
!ActorStream class methodsFor:'documentation'!
documentation
"
This class provides a hook for general objects to behave like Streams;
To the outside, ActorStreams behave like streams and respond to the
usual streams messages (i.e. nextPut:).
In the inside, for every nextPut-message, the nextPutBlock is evaluated
passing the argument of nextPut: as block argument.
These blocks are to be provided by the user of the ActorStream.
Example use is in the Transcript, which is made Stream-like this way.
Instance variables:
nextPutBlock <Block> the block to evaluate for nextPut:-messages
nextPutAllBlock <Block> same for nextPutAll:-messages
nextBlock <Block> the Block to evaluate for the next element
"
! !
!ActorStream class methodsFor:'instance creation'!
new
"have to re-allow new - it was disabled in Stream"
^ self basicNew
! !
!ActorStream methodsFor:'defining actions'!
nextBlock:aBlock
"define the block to be evaluated for every next-message"
nextBlock := aBlock
!
nextPutBlock:aBlock
"define the block to be evaluated for every nextPut-message"
nextPutBlock := aBlock
!
nextPutAllBlock:aBlock
"define the block to be evaluated for every nextPutAll-message"
nextPutAllBlock := aBlock
! !
!ActorStream methodsFor:'queries'!
atEnd
"return true, if at the end - actorStreams are never"
^ false
! !
!ActorStream methodsFor:'accessing-read/write'!
next
"return the next element from the stream by evaluating the nextBlock"
nextBlock notNil ifTrue:[
^ nextBlock value
].
self error:'action for next is undefined'
!
nextPut:something
"put something onto the stream by evaluating the nextPutBlock with
something as argument"
nextPutBlock notNil ifTrue:[
^ nextPutBlock value:something
].
self error:'action for nextPut: is undefined'
!
nextPutAll:something
"put all elements of something onto the stream by evaluating
the nextPutAllBlock with something as argument"
nextPutAllBlock notNil ifTrue:[
^ nextPutAllBlock value:something
].
super nextPutAll:something
! !