ActorStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5461 2bf7d49fb682
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3531
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
     1
"{ Encoding: utf8 }"
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
     2
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
1624
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
     5
              All Rights Reserved
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
936
78dd80467275 added atEnd block (optional)
Claus Gittinger <cg@exept.de>
parents: 554
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
78dd80467275 added atEnd block (optional)
Claus Gittinger <cg@exept.de>
parents: 554
diff changeset
    15
3469
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
    16
"{ NameSpace: Smalltalk }"
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
    17
1621
Claus Gittinger <cg@exept.de>
parents: 1008
diff changeset
    18
PeekableStream subclass:#ActorStream
3089
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    19
	instanceVariableNames:'nextPutBlock nextPutAllBlock nextPutLineBlock nextBlock
4968
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
    20
		atEndBlock peekBlock contentsSpecies bufferedLine'
3089
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    21
	classVariableNames:''
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    22
	poolDictionaries:''
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    23
	category:'Streams'
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
!ActorStream class methodsFor:'documentation'!
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
copyright
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
"
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 COPYRIGHT (c) 1989 by Claus Gittinger
1624
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    31
              All Rights Reserved
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 This software is furnished under a license and may be used
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 only in accordance with the terms of that license and with the
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 inclusion of the above copyright notice.   This software may not
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 be provided or otherwise made available to, or used by, any
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 other person.  No title to or ownership of the software is
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 hereby transferred.
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
!
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
documentation
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    This class provides a hook for general objects to behave like Stream objects.
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    To the outside, actorStreams behave like streams and respond to the
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    usual stream messages (i.e. nextPut:, nextPutAll: etc).
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    In the inside, for every nextPut-message, the nextPutBlock is evaluated
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    passing the argument of nextPut: as block argument.
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    These blocks are to be provided by the user of the ActorStream.
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    Example use is in the Transcript, which is made Stream-like this way.
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
252
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    53
    [Instance variables:]
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    54
        nextPutBlock    <Block>   the block to evaluate for nextPut:-messages
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    55
        nextPutAllBlock <Block>   same for nextPutAll:-messages
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    56
        nextBlock       <Block>   the Block to evaluate for the next element
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    57
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    58
    [author:]
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    59
        Claus Gittinger
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    60
252
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    61
    [See also:]
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    62
        TextCollector
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
    63
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
5239
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    65
!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    66
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    67
example
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    68
"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    69
        |s i|
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    70
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    71
        i := 0.
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    72
        s := ActorStream new.
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    73
        s contentsSpecies:OrderedCollection.
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    74
        s nextBlock:[i := i + 1. i].
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    75
        s next.
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    76
        s next:10.
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
    77
"
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
! !
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
!ActorStream class methodsFor:'instance creation'!
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
new
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    "have to re-allow new - it was disabled in Stream"
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    ^ self basicNew
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
! !
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
1624
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    87
!ActorStream methodsFor:'accessing'!
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    88
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    89
contentsSpecies
3089
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    90
    "return a class of which instances will be returned, when
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    91
     parts of the collection are asked for. 
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    92
     (see upTo-kind of methods in Stream)"
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
    93
1624
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    94
    ^ contentsSpecies ? String
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    95
!
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    96
5254
200344d83a87 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5239
diff changeset
    97
contentsSpecies:aCollectionClass
200344d83a87 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5239
diff changeset
    98
    contentsSpecies := aCollectionClass.
1624
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
    99
! !
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
   100
5239
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   101
!ActorStream methodsFor:'converting'!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   102
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   103
readStream
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   104
    "return a readStream from the receiver. 
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   105
     Since this is (hopefully) already a readStream, return self."
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   106
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   107
    ^ self
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   108
! !
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   109
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   110
!ActorStream methodsFor:'defining actions'!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   111
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   112
atEndBlock:aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   113
    "define the block to be evaluated for every atEnd-message"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   114
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   115
    atEndBlock := aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   116
!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   117
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   118
nextBlock:aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   119
    "define the block to be evaluated for every next-message"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   120
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   121
    nextBlock := aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   122
!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   123
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   124
nextPutAllBlock:aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   125
    "define the block to be evaluated for every nextPutAll-message.
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   126
     If undefined, nextPuts will be used (as inherited)"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   127
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   128
    nextPutAllBlock := aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   129
!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   130
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   131
nextPutBlock:aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   132
    "define the block to be evaluated for every nextPut-message"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   133
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   134
    nextPutBlock := aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   135
!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   136
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   137
nextPutLineBlock:aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   138
    "define the block to be evaluated for every nextPutLineBlock-message.
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   139
     If undefined, nextPutAll/nextPut will be used (as inherited)"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   140
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   141
    nextPutLineBlock := aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   142
!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   143
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   144
peekBlock:aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   145
    "define the block to be evaluated for every peek-message"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   146
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   147
    peekBlock := aBlock
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   148
! !
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   149
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   150
!ActorStream methodsFor:'queries'!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   151
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   152
atEnd
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   153
    "return true, if at the end - actorStreams are never"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   154
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   155
    atEndBlock isNil ifTrue:[
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   156
        ^ false
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   157
    ].
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   158
    ^ atEndBlock value
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   159
! !
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   160
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   161
!ActorStream methodsFor:'reading'!
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
next
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
    "return the next element from the stream by evaluating the nextBlock"
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    nextBlock notNil ifTrue:[
1624
1af2724496b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1621
diff changeset
   167
        ^ nextBlock value
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    ].
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    self error:'action for next is undefined'
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
!
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
5239
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   172
peek
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   173
    "peek ahead for return the next element from the stream by evaluating the peekBlock"
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   174
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   175
    peekBlock notNil ifTrue:[
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   176
        ^ peekBlock value
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   177
    ].
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   178
    self error:'action for peek is undefined'
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   179
! !
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   180
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   181
!ActorStream methodsFor:'writing'!
6641e2aad45c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5165
diff changeset
   182
5461
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   183
flush
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   184
    "any buffered, but not yet written partial line?
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   185
     This only happens if the actorStream has only a nextPutLine action,
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   186
     but no nextPutAll/nextPut action,
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   187
     and no linefeed appeared.
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   188
     Useful to ensure that any remaining data is processed."
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   189
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   190
    bufferedLine isEmptyOrNil ifTrue:[  
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   191
        ^ self.
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   192
    ].
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   193
    self nextPutLine:bufferedLine.
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   194
    bufferedLine := ''.
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   195
!
2bf7d49fb682 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5254
diff changeset
   196
4968
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   197
nextPut:aCharacter
5165
4a704dcb76f9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 5157
diff changeset
   198
    "put aCharacter onto the stream by evaluating the nextPutBlock with aCharacter as argument.
4a704dcb76f9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 5157
diff changeset
   199
     Answer anObject"
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
987
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   201
    nextPutBlock notNil ifTrue:[  
5151
bfed222dcaad #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 4968
diff changeset
   202
        nextPutBlock value:aCharacter.
5165
4a704dcb76f9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 5157
diff changeset
   203
        ^ aCharacter.
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    ].
1008
67f75385259a allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents: 987
diff changeset
   205
    nextPutAllBlock notNil ifTrue:[    
67f75385259a allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents: 987
diff changeset
   206
        "/ fallBack to nextPutAll.
4968
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   207
        self nextPutAll:(aCharacter asString).
5165
4a704dcb76f9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 5157
diff changeset
   208
        ^ aCharacter
1008
67f75385259a allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents: 987
diff changeset
   209
    ].
4968
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   210
    "/ if there is a nextPutLineBlock, then collect the line in a buffer and wait for the cr
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   211
    nextPutLineBlock notNil ifTrue:[
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   212
        aCharacter == Character cr ifFalse:[
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   213
            bufferedLine := (bufferedLine ? '') , aCharacter.
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   214
        ] ifTrue:[
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   215
            self nextPutLine:(bufferedLine ? '').
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   216
            bufferedLine := ''.
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   217
        ].
5165
4a704dcb76f9 #OTHER by exept
Claus Gittinger <cg@exept.de>
parents: 5157
diff changeset
   218
        ^ aCharacter
4968
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   219
    ].
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   220
    
1008
67f75385259a allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents: 987
diff changeset
   221
    self error:'action for nextPut:/nextPutAll: are undefined'
67f75385259a allow for single nextPutAll block
Michael Beyl <mb@exept.de>
parents: 987
diff changeset
   222
4968
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   223
    "Modified: / 28-01-2002 / 20:59:32 / micha"
99de1b56d09f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4790
diff changeset
   224
    "Modified: / 29-05-2019 / 23:28:34 / Claus Gittinger"
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
!
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
nextPutAll:something
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    "put all elements of something onto the stream by evaluating
987
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   229
     the nextPutAllBlock with something as argument.
5157
ad4d06ecfb6c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   230
     If there is no nextPutAllBlock, nextPuts will be used (as inherited).
ad4d06ecfb6c #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5153
diff changeset
   231
     Answer the receiver."
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
987
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   233
    nextPutAllBlock notNil ifTrue:[    
5151
bfed222dcaad #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 4968
diff changeset
   234
        nextPutAllBlock value:something.
bfed222dcaad #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 4968
diff changeset
   235
    ] ifFalse:[
bfed222dcaad #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 4968
diff changeset
   236
        super nextPutAll:something
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    ].
554
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   238
!
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   239
3531
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   240
nextPutAll:count from:buffer startingAt:start
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   241
    "put some elements of something onto the stream by evaluating
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   242
     the nextPutAllBlock with something as argument.
5151
bfed222dcaad #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 4968
diff changeset
   243
     If there is no nextPutAllBlock, individual nextPuts will be used (as inherited).
bfed222dcaad #QUALITY by exept
Claus Gittinger <cg@exept.de>
parents: 4968
diff changeset
   244
     Answer the number of elements that were appended."
3531
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   245
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   246
    nextPutAllBlock notNil ifTrue:[    
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   247
        nextPutAllBlock value:(buffer copyFrom:start to:start+count-1).
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   248
        ^ count
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   249
    ].
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   250
    ^ super nextPutAll:count from:buffer startingAt:start
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   251
!
88c3aa9a14fc class: ActorStream
Stefan Vogel <sv@exept.de>
parents: 3469
diff changeset
   252
3469
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   253
nextPutAll:something startingAt:start to:stop
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   254
    "put some elements of something onto the stream by evaluating
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   255
     the nextPutAllBlock with something as argument.
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   256
     If there is no nextPutAllBlock, nextPuts will be used (as inherited)"
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   257
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   258
    nextPutAllBlock notNil ifTrue:[    
4790
bacf758a10cc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4768
diff changeset
   259
        nextPutAllBlock value:(something copyFrom:start to:stop).
bacf758a10cc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4768
diff changeset
   260
        ^ self.
3469
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   261
    ].
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   262
    super nextPutAll:something startingAt:start to:stop
4768
a03651751649 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3531
diff changeset
   263
a03651751649 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3531
diff changeset
   264
    "Modified: / 22-11-2018 / 12:52:51 / Stefan Vogel"
4790
bacf758a10cc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4768
diff changeset
   265
    "Modified: / 14-01-2019 / 18:23:40 / Claus Gittinger"
3469
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   266
!
f8a8860f7253 class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 3089
diff changeset
   267
554
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   268
nextPutByte:something
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   269
    "put something onto the stream by evaluating the nextPutBlock with
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   270
     something as argument"
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   271
5153
9bf4a6f51b33 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5151
diff changeset
   272
    self nextPut:(something asCharacter).
554
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   273
84eb4d58dd04 allow binary data to be sent via #nextPutByte:.
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   274
    "Created: 6.8.1997 / 00:44:32 / cg"
987
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   275
!
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   276
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   277
nextPutLine:something
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   278
    "put the line onto the stream by evaluating
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   279
     the nextPutLineBlock with something as argument.
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   280
     If there is no nextPutLineBlock, nextPutAll/nextPut will be used (as inherited)"
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   281
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   282
    nextPutLineBlock notNil ifTrue:[    
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   283
        ^ nextPutLineBlock value:something
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   284
    ].
686f04a472ff added nextPutLineBlock support.
md
parents: 936
diff changeset
   285
    super nextPutLine:something
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
! !
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
!ActorStream class methodsFor:'documentation'!
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
version
4768
a03651751649 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 3531
diff changeset
   291
    ^ '$Header$'
5153
9bf4a6f51b33 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5151
diff changeset
   292
!
9bf4a6f51b33 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5151
diff changeset
   293
9bf4a6f51b33 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5151
diff changeset
   294
version_CVS
9bf4a6f51b33 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5151
diff changeset
   295
    ^ '$Header$'
166
76948f2bd7e5 ActorStream moved from libbasic
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
! !
3089
c0936306138e class: ActorStream
Claus Gittinger <cg@exept.de>
parents: 1624
diff changeset
   297