ActorStr.st
author claus
Thu, 10 Aug 1995 14:32:31 +0200
changeset 379 5b5a130ccd09
parent 155 edd7fc34e104
child 384 cc3d110ea879
permissions -rw-r--r--
revision added

"
 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.11 1995-08-10 12:25:37 claus Exp $
'!

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

version
"
$Header: /cvs/stx/stx/libbasic/Attic/ActorStr.st,v 1.11 1995-08-10 12:25:37 claus Exp $
$Revision: 1.11 $
"
!

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

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

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

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

    ^ self
! !

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