ActorStream.st
author Claus Gittinger <cg@exept.de>
Fri, 20 Sep 1996 09:34:11 +0200
changeset 446 cdc38afc4957
parent 337 a2266ae17d1b
child 554 84eb4d58dd04
permissions -rw-r--r--
code cleanup, comments & removed unused files in Make.proto

"
 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 class methodsFor:'documentation'!

copyright
"
 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.
"
!

documentation
"
    This class provides a hook for general objects to behave like Stream objects.
    To the outside, actorStreams behave like streams and respond to the
    usual stream messages (i.e. nextPut:, nextPutAll: etc).
    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

    [author:]
        Claus Gittinger

    [See also:]
        TextCollector

"
! !

!ActorStream class methodsFor:'instance creation'!

new
    "have to re-allow new - it was disabled in Stream"
    ^ self basicNew
! !

!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
! !

!ActorStream methodsFor:'defining actions'!

nextBlock:aBlock
    "define the block to be evaluated for every next-message"

    nextBlock := aBlock
!

nextPutAllBlock:aBlock
    "define the block to be evaluated for every nextPutAll-message"

    nextPutAllBlock := aBlock
!

nextPutBlock:aBlock
    "define the block to be evaluated for every nextPut-message"

    nextPutBlock := aBlock
! !

!ActorStream methodsFor:'queries'!

atEnd
    "return true, if at the end - actorStreams are never"

    ^ false
! !

!ActorStream class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic2/ActorStream.st,v 1.5 1996-09-20 07:34:04 cg Exp $'
! !