ActorStream.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 13:09:26 +0200
changeset 252 d52b05d6637a
parent 166 76948f2bd7e5
child 259 6d36f3ac42a2
permissions -rw-r--r--
commentary

"
 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

    [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:'ignored style messages'!

bold
    "ignored here.
     this allows actorStreams to be used interchangeable with printStreams"

    ^ self
!

italic 
    "ignored here.
     this allows actorStreams to be used interchangeable with printStreams"

    ^ self
!

normal 
    "ignored here.
     this allows actorStreams to be used interchangeable with printStreams"

    ^ self
! !

!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.2 1996-04-25 11:08:53 cg Exp $'
! !