# PhasicFlow: src/phasicFlow/repository/IOobject/IOobject.cpp Source File

IOobject.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "IOobject.hpp"
#include "repository.hpp"
pFlow::IOobject::IOobject
(
const objectFile& objf,
const repository* owner,
uniquePtr<iObject>&& obj
)
:
IOfileHeader(objf, owner),
object_(obj.release())
{
if(!read(this->readWriteHeader()))
{
fatalErrorInFunction<<
"error in reading " << name() << " from path " << path()<<endl;
fatalExit;
}
}
pFlow::IOobject::IOobject
(
const objectFile& objf,
const repository* owner,
uniquePtr<IOobject>&& obj
)
:
IOfileHeader(objf, owner),
object_( obj->object_.release())
{
}
bool pFlow::IOobject::isObjectValid()const
{
return object_.get() != nullptr;
}
bool pFlow::IOobject::read(bool rdHdr)
{
if( implyRead() )
{
if( auto ptrIS = inStream(); ptrIS )
{
return read( ptrIS(), rdHdr);
}
else
{
warningInFunction<<
"could not open file " << path() <<endl;
return false;
}
}
return true;
}
bool pFlow::IOobject::write() const
{
if(implyWrite())
{
if(auto ptrOS = outStream(); ptrOS )
{
return write(ptrOS());
}
else
{
warningInFunction<<
"error in opening file "<< path() <<endl;
return false;
}
}
return true;
}
bool pFlow::IOobject::read(iIstream& is, bool rdHdr)
{
if(rdHdr)
{
if(!readHeader(is))return false;
}
return object_->read_object_t(is);
}
bool pFlow::IOobject::write(iOstream& os) const
{
if(this->readWriteHeader())
writeHeader(os, typeName());
return (object_->write_object_t(os) && writeSeparator(os));
}
pFlow::IOobject::write
bool write() const
Definition: IOobject.cpp:83
fatalExit
#define fatalExit
Definition: error.hpp:57
IOobject.hpp
warningInFunction
#define warningInFunction
Definition: error.hpp:55
pFlow::IOobject::IOobject
IOobject(const objectFile &objf, const repository *owner, uniquePtr< iObject > &&obj)
Definition: IOobject.cpp:26
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::IOobject::isObjectValid
bool isObjectValid() const
Definition: IOobject.cpp:58
repository.hpp
pFlow::IOobject::object_
uniquePtr< iObject > object_
Definition: IOobject.hpp:110
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::IOobject::read
bool read(bool rdHdr=true)
Definition: IOobject.cpp:63
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::IOfileHeader
Definition: IOfileHeader.hpp:35
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::repository
Definition: repository.hpp:34
pFlow::iOstream
Definition: iOstream.hpp:53