ActorStream.st
changeset 5239 6641e2aad45c
parent 5165 4a704dcb76f9
child 5254 200344d83a87
equal deleted inserted replaced
5238:09078186400b 5239:6641e2aad45c
    60 
    60 
    61     [See also:]
    61     [See also:]
    62         TextCollector
    62         TextCollector
    63 
    63 
    64 "
    64 "
       
    65 !
       
    66 
       
    67 example
       
    68 "
       
    69         |s i|
       
    70 
       
    71         i := 0.
       
    72         s := ActorStream new.
       
    73         s contentsSpecies:OrderedCollection.
       
    74         s nextBlock:[i := i + 1. i].
       
    75         s next.
       
    76         s next:10.
       
    77 "
    65 ! !
    78 ! !
    66 
    79 
    67 !ActorStream class methodsFor:'instance creation'!
    80 !ActorStream class methodsFor:'instance creation'!
    68 
    81 
    69 new
    82 new
    83 
    96 
    84 contentsSpecies:something
    97 contentsSpecies:something
    85     contentsSpecies := something.
    98     contentsSpecies := something.
    86 ! !
    99 ! !
    87 
   100 
    88 !ActorStream methodsFor:'accessing-read/write'!
   101 !ActorStream methodsFor:'converting'!
       
   102 
       
   103 readStream
       
   104     "return a readStream from the receiver. 
       
   105      Since this is (hopefully) already a readStream, return self."
       
   106 
       
   107     ^ self
       
   108 ! !
       
   109 
       
   110 !ActorStream methodsFor:'defining actions'!
       
   111 
       
   112 atEndBlock:aBlock
       
   113     "define the block to be evaluated for every atEnd-message"
       
   114 
       
   115     atEndBlock := aBlock
       
   116 !
       
   117 
       
   118 nextBlock:aBlock
       
   119     "define the block to be evaluated for every next-message"
       
   120 
       
   121     nextBlock := aBlock
       
   122 !
       
   123 
       
   124 nextPutAllBlock:aBlock
       
   125     "define the block to be evaluated for every nextPutAll-message.
       
   126      If undefined, nextPuts will be used (as inherited)"
       
   127 
       
   128     nextPutAllBlock := aBlock
       
   129 !
       
   130 
       
   131 nextPutBlock:aBlock
       
   132     "define the block to be evaluated for every nextPut-message"
       
   133 
       
   134     nextPutBlock := aBlock
       
   135 !
       
   136 
       
   137 nextPutLineBlock:aBlock
       
   138     "define the block to be evaluated for every nextPutLineBlock-message.
       
   139      If undefined, nextPutAll/nextPut will be used (as inherited)"
       
   140 
       
   141     nextPutLineBlock := aBlock
       
   142 !
       
   143 
       
   144 peekBlock:aBlock
       
   145     "define the block to be evaluated for every peek-message"
       
   146 
       
   147     peekBlock := aBlock
       
   148 ! !
       
   149 
       
   150 !ActorStream methodsFor:'queries'!
       
   151 
       
   152 atEnd
       
   153     "return true, if at the end - actorStreams are never"
       
   154 
       
   155     atEndBlock isNil ifTrue:[
       
   156         ^ false
       
   157     ].
       
   158     ^ atEndBlock value
       
   159 ! !
       
   160 
       
   161 !ActorStream methodsFor:'reading'!
    89 
   162 
    90 next
   163 next
    91     "return the next element from the stream by evaluating the nextBlock"
   164     "return the next element from the stream by evaluating the nextBlock"
    92 
   165 
    93     nextBlock notNil ifTrue:[
   166     nextBlock notNil ifTrue:[
    94         ^ nextBlock value
   167         ^ nextBlock value
    95     ].
   168     ].
    96     self error:'action for next is undefined'
   169     self error:'action for next is undefined'
    97 !
   170 !
       
   171 
       
   172 peek
       
   173     "peek ahead for return the next element from the stream by evaluating the peekBlock"
       
   174 
       
   175     peekBlock notNil ifTrue:[
       
   176         ^ peekBlock value
       
   177     ].
       
   178     self error:'action for peek is undefined'
       
   179 ! !
       
   180 
       
   181 !ActorStream methodsFor:'writing'!
    98 
   182 
    99 nextPut:aCharacter
   183 nextPut:aCharacter
   100     "put aCharacter onto the stream by evaluating the nextPutBlock with aCharacter as argument.
   184     "put aCharacter onto the stream by evaluating the nextPutBlock with aCharacter as argument.
   101      Answer anObject"
   185      Answer anObject"
   102 
   186 
   183 
   267 
   184     nextPutLineBlock notNil ifTrue:[    
   268     nextPutLineBlock notNil ifTrue:[    
   185         ^ nextPutLineBlock value:something
   269         ^ nextPutLineBlock value:something
   186     ].
   270     ].
   187     super nextPutLine:something
   271     super nextPutLine:something
   188 !
       
   189 
       
   190 peek
       
   191     "peek ahead for return the next element from the stream by evaluating the peekBlock"
       
   192 
       
   193     peekBlock notNil ifTrue:[
       
   194         ^ peekBlock value
       
   195     ].
       
   196     self error:'action for peek is undefined'
       
   197 ! !
       
   198 
       
   199 !ActorStream methodsFor:'converting'!
       
   200 
       
   201 readStream
       
   202     "return a readStream from the receiver. 
       
   203      Since this is (hopefully) already a readStream, return self."
       
   204 
       
   205     ^ self
       
   206 ! !
       
   207 
       
   208 !ActorStream methodsFor:'defining actions'!
       
   209 
       
   210 atEndBlock:aBlock
       
   211     "define the block to be evaluated for every atEnd-message"
       
   212 
       
   213     atEndBlock := aBlock
       
   214 !
       
   215 
       
   216 nextBlock:aBlock
       
   217     "define the block to be evaluated for every next-message"
       
   218 
       
   219     nextBlock := aBlock
       
   220 !
       
   221 
       
   222 nextPutAllBlock:aBlock
       
   223     "define the block to be evaluated for every nextPutAll-message.
       
   224      If undefined, nextPuts will be used (as inherited)"
       
   225 
       
   226     nextPutAllBlock := aBlock
       
   227 !
       
   228 
       
   229 nextPutBlock:aBlock
       
   230     "define the block to be evaluated for every nextPut-message"
       
   231 
       
   232     nextPutBlock := aBlock
       
   233 !
       
   234 
       
   235 nextPutLineBlock:aBlock
       
   236     "define the block to be evaluated for every nextPutLineBlock-message.
       
   237      If undefined, nextPutAll/nextPut will be used (as inherited)"
       
   238 
       
   239     nextPutLineBlock := aBlock
       
   240 !
       
   241 
       
   242 peekBlock:aBlock
       
   243     "define the block to be evaluated for every peek-message"
       
   244 
       
   245     peekBlock := aBlock
       
   246 ! !
       
   247 
       
   248 !ActorStream methodsFor:'queries'!
       
   249 
       
   250 atEnd
       
   251     "return true, if at the end - actorStreams are never"
       
   252 
       
   253     atEndBlock isNil ifTrue:[
       
   254         ^ false
       
   255     ].
       
   256     ^ atEndBlock value
       
   257 ! !
   272 ! !
   258 
   273 
   259 !ActorStream class methodsFor:'documentation'!
   274 !ActorStream class methodsFor:'documentation'!
   260 
   275 
   261 version
   276 version