/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "IOField.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template
void Foam::IOField::readFromStream(const bool readOnProc)
{
Istream& is = readStream(typeName, readOnProc);
if (readOnProc)
{
is >> *this;
}
close();
}
template
bool Foam::IOField::readContents()
{
if (isReadRequired() || (isReadOptional() && headerOk()))
{
readFromStream();
return true;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::IOField::IOField(const IOobject& io)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading>();
readContents();
}
template
Foam::IOField::IOField(const IOobject& io, const bool readOnProc)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading>();
if (isReadRequired())
{
readFromStream(readOnProc);
}
else if (isReadOptional())
{
const bool haveFile = headerOk();
readFromStream(readOnProc && haveFile);
}
}
template
Foam::IOField::IOField(const IOobject& io, Foam::zero)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading>();
readContents();
}
template
Foam::IOField::IOField(const IOobject& io, const label len)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading>();
if (!readContents())
{
Field::resize(len);
}
}
template
Foam::IOField::IOField(const IOobject& io, const UList& content)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading>();
if (!readContents())
{
Field::operator=(content);
}
}
template
Foam::IOField::IOField(const IOobject& io, Field&& content)
:
regIOobject(io)
{
// Check for MUST_READ_IF_MODIFIED
warnNoRereading>();
Field::transfer(content);
readContents();
}
template
Foam::IOField::IOField(const IOobject& io, const tmp>& tfld)
:
regIOobject(io)
{
const bool reuse = tfld.movable();
if (reuse)
{
Field::transfer(tfld.ref());
}
if (!readContents() && !reuse)
{
Field::operator=(tfld());
}
tfld.clear();
}
template
Foam::IOFieldRef::IOFieldRef
(
const IOobject& io,
const Field& content
)
:
regIOobject(io),
contentRef_(content) // cref
{}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template
Foam::Field Foam::IOField::readContents(const IOobject& io)
{
IOobject rio(io, IOobjectOption::NO_REGISTER);
if (rio.readOpt() == IOobjectOption::MUST_READ_IF_MODIFIED)
{
rio.readOpt(IOobjectOption::MUST_READ);
}
IOField reader(rio);
return Field(std::move(static_cast&>(reader)));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
bool Foam::IOField::writeData(Ostream& os) const
{
os << static_cast&>(*this);
return os.good();
}
template
bool Foam::IOFieldRef::writeData(Ostream& os) const
{
os << contentRef_.cref();
return os.good();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template
void Foam::IOField::operator=(const IOField& rhs)
{
Field::operator=(rhs);
}
// ************************************************************************* //