Class TPeekCharStream

Unit

Declaration

type TPeekCharStream = class(TStream)

Description

Abstract class to read another stream, always being able to back one character. This is a purely sequential read-only stream. This means that calling Write, Seek (changing Position) or setting Size will always cause an exception with appropriate descendant of EStreamNotImplemented.

Getting Size and Position is allowed. Getting Size is simply implemented by getting SourceStream.Size (so it works if the underlying source stream supports getting Size). Getting Position always works correctly, as it's just the number of characters read from this stream. The fact that we may read ahead in the underlying source stream (for buffering, for peeking) is completely hidden.

We do not assume anything about the underlying source stream, in particular the underlying source stream may also be purely sequential (so we can only read from it, and we cannot predict when it ends).

The main advantage of using this class is that you get PeekChar routine: you can always peek ahead one character in the stream, without reading it (i.e. next time you will call Read or ReadBuffer you will still get that char). And it works for all source streams, including the ones where seeking is not allowed (so Seek(-1, soCurrent) would not work).

Another advantage is the Line and Column information.

Source: base/castleclassutils.pas (line 283).

Hierarchy

  • TObject
  • TStream
  • TPeekCharStream

Generated by PasDoc 0.17.0.snapshot.