Commit 4466daa0 authored by Mattijs Janssens's avatar Mattijs Janssens
Browse files

Merge branch 'feature-token-passing' into 'develop'

ENH: support change of Pstream buffer format via flag modifier

See merge request OpenFOAM-plus!166
parents 073aca91 8f444b71
......@@ -29,6 +29,24 @@ License
#include "token.H"
#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 * * * * * * * * * * * //
......@@ -121,19 +139,48 @@ Foam::UIPstream::~UIPstream()
Foam::Istream& Foam::UIPstream::read(token& t)
{
// Return the put back token if it exists
// - with additional handling for special stream flags
if (Istream::getBack(t))
{
return *this;
if (t.isFlag())
{
processFlags(*this, t.flagToken());
}
else
{
return *this;
}
}
char c;
// Read character, return on error
// - with additional handling for special stream flags
// Return on error
if (!read(c))
char c;
do
{
t.setBad();
return *this;
if (!read(c))
{
t.setBad(); // Error
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
t.lineNumber() = lineNumber();
......
......@@ -193,7 +193,8 @@ bool Foam::UOPstream::write(const token& tok)
{
case token::tokenType::FLAG :
{
// silently consume the flag
writeToBuffer(char(token::tokenType::FLAG));
writeToBuffer(char(tok.flagToken()));
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment