ENH: scalar - added readOrDefault(is, defaultValue) function

This commit is contained in:
Andrew Heather 2022-05-20 17:41:59 +01:00
parent 12ba22bebf
commit e0f3993045
2 changed files with 24 additions and 0 deletions

View File

@ -40,6 +40,24 @@ Foam::scalar Foam::readScalar(Istream& is)
}
Foam::scalar Foam::readScalarOrDefault(Istream& is, const scalar defaultValue)
{
if (is.good())
{
token tok(is);
if (tok.isNumber())
{
return tok.scalarToken();
}
is.putBack(tok);
}
return defaultValue;
}
Foam::scalar Foam::readRawScalar(Istream& is)
{
scalar val(0);

View File

@ -103,6 +103,9 @@ namespace Foam
//- Read scalar from stream.
scalar readScalar(Istream& is);
//- Read scalar from stream if present or return default value
scalar readScalarOrDefault(Istream& is, const scalar defaultValue);
//- Read raw scalar from binary stream.
// \note No internal check for binary vs ascii,
// the caller knows what they are doing
@ -172,6 +175,9 @@ namespace Foam
//- Read scalar from stream.
scalar readScalar(Istream& is);
//- Read scalar from stream if present or return default value
scalar readScalarOrDefault(Istream& is, const scalar defaultValue);
//- Read raw scalar from binary stream.
// \note No internal check for binary vs ascii,
// the caller knows what they are doing