ENH: provide Istream::rewind() implementation

- base implementation drops any putback token
This commit is contained in:
Mark Olesen
2025-09-29 09:17:29 +02:00
parent c6fc90b629
commit a42fa7949b
8 changed files with 21 additions and 3 deletions

View File

@ -275,9 +275,11 @@ const std::istream& Foam::IFstream::stdStream() const
void Foam::IFstream::rewind()
{
Istream::rewind(); // Drop any putback
lineNumber_ = 1; // Reset line number
if (IOstreamOption::COMPRESSED == ifstreamPointer::whichCompression())
{
lineNumber_ = 1; // Reset line number
ifstreamPointer::reopen_gz(this->name());
setState(ifstreamPointer::get()->rdstate());
}

View File

@ -218,6 +218,12 @@ char Foam::Istream::readEndList(const char* funcName)
}
void Foam::Istream::rewind()
{
putBackClear(); // Drop any putback
}
Foam::Istream& Foam::Istream::operator()() const
{
if (!good())

View File

@ -175,7 +175,8 @@ public:
//- operation.
virtual Istream& readRaw(char* data, std::streamsize count) = 0;
//- Rewind the stream so that it may be read again
//- Rewind the stream so that it may be read again.
// The base implementation clears any putback.
virtual void rewind() = 0;

View File

@ -563,6 +563,8 @@ Foam::label Foam::UIPstreamBase::remaining() const noexcept
void Foam::UIPstreamBase::rewind()
{
Istream::rewind(); // Drop any putback
recvBufPos_ = 0; // Assume the entire buffer is for us to read from
setOpened();
setGood();

View File

@ -1084,6 +1084,7 @@ bool Foam::ISstream::endRawRead()
void Foam::ISstream::rewind()
{
Istream::rewind(); // Drop any putback
lineNumber_ = 1; // Reset line number
stdStream().clear(); // Clear the iostate error state flags

View File

@ -531,7 +531,11 @@ public:
virtual bool endRawRead() override { return false; }
//- Rewind the stream so that it may be read again. Same as seek(0)
virtual void rewind() override { ITstream::seek(0); }
virtual void rewind() override
{
Istream::rewind();
ITstream::seek(0);
}
// Output

View File

@ -357,6 +357,7 @@ public:
//- Rewind the stream, clearing any old errors
virtual void rewind() override
{
Istream::rewind();
stream_.rewind();
syncState();
}

View File

@ -419,6 +419,7 @@ public:
//- Rewind the stream, clearing any old errors
virtual void rewind() override
{
Istream::rewind();
stream_.rewind();
syncState();
}