Skip to content
Snippets Groups Projects
Commit a0af9673 authored by mattijs's avatar mattijs Committed by Mattijs Janssens
Browse files

BUG: READ_IF_PRESENT: return false if not read. Fixes #3193

Side effects:
- processors will not call readStream
- return false if not headerOk
parent ab30b030
No related branches found
No related tags found
No related merge requests found
...@@ -34,50 +34,38 @@ License ...@@ -34,50 +34,38 @@ License
template<class T, class BaseType> template<class T, class BaseType>
bool Foam::CompactIOField<T, BaseType>::readIOcontents(bool readOnProc) bool Foam::CompactIOField<T, BaseType>::readIOcontents(bool readOnProc)
{ {
if (readOpt() == IOobject::MUST_READ) if (isReadRequired() || (isReadOptional() && headerOk()))
{ {
// Reading // Do reading
} Istream& is = readStream(word::null, readOnProc);
else if (isReadOptional())
{
if (!headerOk())
{
readOnProc = false;
}
}
else
{
return false;
}
// Do reading if (readOnProc)
Istream& is = readStream(word::null, readOnProc);
if (readOnProc)
{
if (headerClassName() == IOField<T>::typeName)
{ {
is >> static_cast<Field<T>&>(*this); if (headerClassName() == IOField<T>::typeName)
close(); {
} is >> static_cast<Field<T>&>(*this);
else if (headerClassName() == typeName) close();
{ }
is >> *this; else if (headerClassName() == typeName)
close(); {
} is >> *this;
else close();
{ }
FatalIOErrorInFunction(is) else
<< "Unexpected class name " << headerClassName() {
<< " expected " << typeName FatalIOErrorInFunction(is)
<< " or " << IOField<T>::typeName << nl << "Unexpected class name " << headerClassName()
<< " while reading object " << name() << " expected " << typeName
<< exit(FatalIOError); << " or " << IOField<T>::typeName << nl
<< " while reading object " << name()
<< exit(FatalIOError);
}
} }
return true;
} }
return true; return false;
} }
......
...@@ -33,32 +33,20 @@ License ...@@ -33,32 +33,20 @@ License
template<class Type> template<class Type>
bool Foam::IOField<Type>::readIOcontents(bool readOnProc) bool Foam::IOField<Type>::readIOcontents(bool readOnProc)
{ {
if (isReadRequired()) if (isReadRequired() || (isReadOptional() && headerOk()))
{ {
// Reading // Do reading
} Istream& is = readStream(typeName, readOnProc);
else if (isReadOptional())
{ if (readOnProc)
if (!headerOk())
{ {
readOnProc = false; is >> *this;
} }
} close();
else return true;
{
return false;
} }
return false;
// Do reading
Istream& is = readStream(typeName, readOnProc);
if (readOnProc)
{
is >> *this;
}
close();
return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment