mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'feature-token-passing' into 'develop'
ENH: support change of Pstream buffer format via flag modifier See merge request Development/OpenFOAM-plus!166
This commit is contained in:
@ -29,6 +29,24 @@ License
|
|||||||
#include "token.H"
|
#include "token.H"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
// Adjust stream format based on the flagMask
|
||||||
|
inline static void processFlags(Istream& is, int flagMask)
|
||||||
|
{
|
||||||
|
if ((flagMask & token::ASCII))
|
||||||
|
{
|
||||||
|
is.format(IOstream::ASCII);
|
||||||
|
}
|
||||||
|
else if ((flagMask & token::BINARY))
|
||||||
|
{
|
||||||
|
is.format(IOstream::BINARY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -121,20 +139,49 @@ Foam::UIPstream::~UIPstream()
|
|||||||
Foam::Istream& Foam::UIPstream::read(token& t)
|
Foam::Istream& Foam::UIPstream::read(token& t)
|
||||||
{
|
{
|
||||||
// Return the put back token if it exists
|
// Return the put back token if it exists
|
||||||
|
// - with additional handling for special stream flags
|
||||||
if (Istream::getBack(t))
|
if (Istream::getBack(t))
|
||||||
|
{
|
||||||
|
if (t.isFlag())
|
||||||
|
{
|
||||||
|
processFlags(*this, t.flagToken());
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read character, return on error
|
||||||
|
// - with additional handling for special stream flags
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
|
do
|
||||||
// Return on error
|
{
|
||||||
if (!read(c))
|
if (!read(c))
|
||||||
{
|
{
|
||||||
t.setBad();
|
t.setBad(); // Error
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c == token::FLAG)
|
||||||
|
{
|
||||||
|
char flagVal;
|
||||||
|
|
||||||
|
if (read(flagVal))
|
||||||
|
{
|
||||||
|
processFlags(*this, flagVal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t.setBad(); // Error
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (c == token::FLAG);
|
||||||
|
|
||||||
|
|
||||||
// Set the line number of this token to the current stream line number
|
// Set the line number of this token to the current stream line number
|
||||||
t.lineNumber() = lineNumber();
|
t.lineNumber() = lineNumber();
|
||||||
|
|
||||||
|
|||||||
@ -193,7 +193,8 @@ bool Foam::UOPstream::write(const token& tok)
|
|||||||
{
|
{
|
||||||
case token::tokenType::FLAG :
|
case token::tokenType::FLAG :
|
||||||
{
|
{
|
||||||
// silently consume the flag
|
writeToBuffer(char(token::tokenType::FLAG));
|
||||||
|
writeToBuffer(char(tok.flagToken()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user