ENH: scalar - added readOrDefault(is, defaultValue) function
This commit is contained in:
parent
12ba22bebf
commit
e0f3993045
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user