|
Class: MultiReadStream
Object
|
+--Stream
|
+--PeekableStream
|
+--MultiReadStream
- Package:
- stx:libbasic2
- Category:
- Streams-Misc
- Version:
- rev:
1.14
date: 2019/12/13 20:35:43
- user: cg
- file: MultiReadStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
Stacked streams.
At any time, another stream can be stacked onto a stream stack.
Making this stream's contents to be returned before the rest.
To the stream reader, this looks like a single stream delivering the
embedded stream contents sequentially.
Useful when reading files which include each other,
or to handle define-macro expansion in a c-parser.
[instance variables:]
copyrightCOPYRIGHT (c) 2018 by eXept Software AG
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.
instance creation
-
on: aReadStream
-
accessing
-
readStream
-
obsolete positioning
-
position0Based
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
position1Based
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
private
-
checkCurrentStreamAtEnd
-
keep the last stream, so that the #position kludge will work
queries
-
atEnd
-
(comment from inherited method)
return true if the end of the stream has been reached;
- we do not know here how to do it, it must be redefined in subclass
-
contentsSpecies
-
return a class of which instances will be returned, when
parts of the collection are asked for.
(see upTo-kind of methods in Stream)
-
position
-
that's debatable !
reading
-
next
-
(comment from inherited method)
return the next element of the stream
- we do not know here how to do it, it must be redefined in subclass
-
peek
-
(comment from inherited method)
return the next element of the stream without advancing (i.e.
the following send of next will return this element again.)
- we do not know here how to do it, it must be redefined in subclass
stream stacking
-
popInputStream
-
-
pushInputStream: aReadStream
-
|s|
s := MultiReadStream on:('abcd' readStream).
self assert:(s peek == $a).
self assert:(s next == $a).
s pushInputStream:('1234' readStream).
self assert:(s next == $1).
self assert:(s next == $2).
s pushInputStream:('aa' readStream).
self assert:(s next == $a).
self assert:(s next == $a).
self assert:(s atEnd not).
self assert:(s next == $3).
self assert:(s next == $4).
self assert:(s next == $b).
self assert:(s next == $c).
self assert:(s next == $d).
self assert:(s atEnd).
self assert:(s peek == nil).
self assert:(s next == nil).
|