ENH: add syncState() method to serial streams (#2623)

- in places where direct reading from the std::stream is used,
  this method can be used to ensure that the OpenFOAM Sstream state
  is properly updated from the std::stream.

ENH: restrict stream renaming to ISstream

- non-const access was previously declared at the top-level (IOstream)
  but that not only added in potentially odd setting of the static
  fileName, but also meant that the OFstream name() could potentially
  be altered after opening a file and thus be inconsistent with the
  underlying file that had been opened.

  Now restrict name modification to ISstream (and ITstream
  counterpart). Does not affect any existing valid code.

STYLE: non-default OFstream destructor (for future file staging)
This commit is contained in:
Mark Olesen
2022-10-27 14:38:23 +02:00
parent bd000d89e9
commit 278378031e
15 changed files with 142 additions and 155 deletions

View File

@ -149,6 +149,7 @@ Foam::Ostream& Foam::ensightFile::writeString(const char* str)
{
buf[79] = 0; // max 79 in ASCII, ensure it is indeed nul-terminated
stdStream() << buf;
syncState();
}
return *this;
@ -186,6 +187,7 @@ Foam::Ostream& Foam::ensightFile::write
)
{
stdStream().write(buf, count);
syncState();
return *this;
}
@ -204,6 +206,7 @@ Foam::Ostream& Foam::ensightFile::write(const int32_t val)
{
stdStream().width(10);
stdStream() << val;
syncState();
}
return *this;
@ -232,6 +235,7 @@ Foam::Ostream& Foam::ensightFile::write(const float val)
{
stdStream().width(12);
stdStream() << val;
syncState();
}
return *this;
@ -260,6 +264,7 @@ Foam::Ostream& Foam::ensightFile::write
{
stdStream().width(fieldWidth);
stdStream() << value;
syncState();
}
return *this;
@ -271,6 +276,7 @@ void Foam::ensightFile::newline()
if (format() == IOstreamOption::ASCII)
{
stdStream() << nl;
syncState();
}
}