#include <ZStreamRPos_StreamR.h>
Inheritance diagram for ZStreamRPos_StreamR:
Public Member Functions | |
ZStreamRPos_StreamR (const ZStreamR &iSource, const ZStreamRWPos &iBuffer) | |
virtual size_t | Imp_CountReadable () |
Returns the number of bytes guaranteed to be readable without blocking. |
ZStreamRPos_StreamR::ZStreamRPos_StreamR | ( | const ZStreamR & | iSource, | |
const ZStreamRWPos & | iBuffer | |||
) |
ZStreamRPos_StreamR takes a source ZStreamR, and a ZStreamRWPos to use as a buffer. Its size and position are taken from the ZStreamRWPos. A read or call to SetPosition that would move beyond the end of the ZStreamRWPos is handled by copying more data from the ZStreamR to the end of the ZStreamRWPos.
The ZStreamRPos_StreamR::Committed() can be called at any time and as often as you like, but once it has been called it is then an error to use any of the position/size methods. Committed returns a ZStreamR reference, which will refer to the ZStreamRPos_StreamR if the buffer stream is not yet exhausted and thus if reads should be satisfied by pulling at least some data from it. If the ZStreamRWPos is known to be exhausted when Committed is called (i.e. if GetPosition() == GetSize()) then Committed is returns a reference to the source ZStreamR, so reads can bypass the indirection that imposed by using the ZStreamRPos_StreamR directly.
This class is useful when you have a ZStreamR to which you need random access for only some amount of data at the head. That might be the case, for example, when handling a graphic format that has fiddly meta-data at the beginning, followed by arbitrary data that need not be accessed randomly.
size_t ZStreamRPos_StreamR::Imp_CountReadable | ( | ) | [virtual] |
Returns the number of bytes guaranteed to be readable without blocking.
If the stream does not or cannot know this information it should return zero. A zero return thus does not mean no data is available, simply that a subsequent Read or Skip may block indefinitely.
Reimplemented from ZStreamRPos.