Commit 81bd0aa0 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: pass autoPtr for fileHandler and matrix solver as moveable

- clearer than passing a reference to a dummy variable,
  or relying on move occuring within the copy constructor
  (historical, but should be deprecated)

STYLE: consistent autoPtr syntax for uncollated file operations
parent 394a3a9b
......@@ -255,9 +255,9 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlock
realIsPtr->name() = is.name();
// Read header
if (!headerIO.readHeader(realIsPtr()))
if (!headerIO.readHeader(*realIsPtr))
{
FatalIOErrorInFunction(realIsPtr())
FatalIOErrorInFunction(*realIsPtr)
<< "problem while reading header for object "
<< is.name() << exit(FatalIOError);
}
......@@ -319,7 +319,7 @@ bool Foam::decomposedBlockData::readBlocks
if (debug)
{
Pout<< "decomposedBlockData::readBlocks:"
<< " stream:" << (isPtr.valid() ? isPtr().name() : "invalid")
<< " stream:" << (isPtr ? isPtr->name() : "invalid")
<< " commsType:" << Pstream::commsTypeNames[commsType]
<< " comm:" << comm << endl;
}
......@@ -330,7 +330,7 @@ bool Foam::decomposedBlockData::readBlocks
{
if (UPstream::master(comm))
{
Istream& is = isPtr();
Istream& is = *isPtr;
is.fatalCheck("read(Istream&)");
// Read master data
......@@ -387,7 +387,7 @@ bool Foam::decomposedBlockData::readBlocks
if (UPstream::master(comm))
{
Istream& is = isPtr();
Istream& is = *isPtr;
is.fatalCheck("read(Istream&)");
// Read master data
......@@ -440,7 +440,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
if (debug)
{
Pout<< "decomposedBlockData::readBlocks:"
<< " stream:" << (isPtr.valid() ? isPtr().name() : "invalid")
<< " stream:" << (isPtr ? isPtr->name() : "invalid")
<< " commsType:" << Pstream::commsTypeNames[commsType] << endl;
}
......@@ -453,7 +453,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
{
if (UPstream::master(comm))
{
Istream& is = isPtr();
Istream& is = *isPtr;
is.fatalCheck("read(Istream&)");
// Read master data
......@@ -465,9 +465,9 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
realIsPtr->name() = fName;
// Read header
if (!headerIO.readHeader(realIsPtr()))
if (!headerIO.readHeader(*realIsPtr))
{
FatalIOErrorInFunction(realIsPtr())
FatalIOErrorInFunction(*realIsPtr)
<< "problem while reading header for object "
<< is.name() << exit(FatalIOError);
}
......@@ -524,7 +524,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
if (UPstream::master(comm))
{
Istream& is = isPtr();
Istream& is = *isPtr;
is.fatalCheck("read(Istream&)");
// Read master data
......@@ -536,9 +536,9 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
realIsPtr->name() = fName;
// Read header
if (!headerIO.readHeader(realIsPtr()))
if (!headerIO.readHeader(*realIsPtr))
{
FatalIOErrorInFunction(realIsPtr())
FatalIOErrorInFunction(*realIsPtr)
<< "problem while reading header for object "
<< is.name() << exit(FatalIOError);
}
......@@ -769,7 +769,7 @@ bool Foam::decomposedBlockData::writeBlocks
if (debug)
{
Pout<< "decomposedBlockData::writeBlocks:"
<< " stream:" << (osPtr.valid() ? osPtr().name() : "invalid")
<< " stream:" << (osPtr ? osPtr->name() : "invalid")
<< " data:" << data.size()
<< " (master only) slaveData:" << slaveData.size()
<< " commsType:" << Pstream::commsTypeNames[commsType] << endl;
......@@ -786,7 +786,7 @@ bool Foam::decomposedBlockData::writeBlocks
if (UPstream::master(comm))
{
OSstream& os = osPtr();
OSstream& os = *osPtr;
start.setSize(nProcs);
......@@ -819,7 +819,7 @@ bool Foam::decomposedBlockData::writeBlocks
{
start.setSize(nProcs);
OSstream& os = osPtr();
OSstream& os = *osPtr;
// Write master data
{
......@@ -869,7 +869,7 @@ bool Foam::decomposedBlockData::writeBlocks
{
start.setSize(nProcs);
OSstream& os = osPtr();
OSstream& os = *osPtr;
os << nl << "// Processor" << UPstream::masterNo() << nl;
start[UPstream::masterNo()] = os.stdStream().tellp();
......@@ -922,7 +922,7 @@ bool Foam::decomposedBlockData::writeBlocks
if (UPstream::master(comm))
{
OSstream& os = osPtr();
OSstream& os = *osPtr;
// Write slaves
for
......@@ -950,7 +950,7 @@ bool Foam::decomposedBlockData::writeBlocks
if (UPstream::master(comm))
{
ok = osPtr().good();
ok = osPtr->good();
}
}
......@@ -972,7 +972,7 @@ bool Foam::decomposedBlockData::read()
if (UPstream::master(comm_))
{
isPtr.reset(new IFstream(objPath));
IOobject::readHeader(isPtr());
IOobject::readHeader(*isPtr);
}
List<char>& data = *this;
......@@ -1063,7 +1063,7 @@ bool Foam::decomposedBlockData::writeObject
// Note: always write binary. These are strings so readable anyway.
// They have already be tokenised on the sending side.
osPtr.reset(new OFstream(objectPath(), streamOpt));
IOobject::writeHeader(osPtr());
IOobject::writeHeader(*osPtr);
}
labelList recvSizes;
......
......@@ -166,8 +166,7 @@ void Foam::Time::readDict()
controlDict_.watchIndices().clear();
// Installing the new handler
auto handler = fileOperation::New(fileHandlerName, true);
Foam::fileHandler(handler);
Foam::fileHandler(fileOperation::New(fileHandlerName, true));
// Reinstall old watches
fileHandler().addWatches(controlDict_, oldWatched);
......
......@@ -1070,16 +1070,17 @@ void Foam::argList::parse
// 5. '-fileHandler' commmand-line option
{
word handlerType =
options_.lookup("fileHandler", Foam::getEnv("FOAM_FILEHANDLER"));
word handlerType
(
options_.lookup("fileHandler", Foam::getEnv("FOAM_FILEHANDLER"))
);
if (handlerType.empty())
{
handlerType = fileOperation::defaultFileHandler;
}
auto handler = fileOperation::New(handlerType, bannerEnabled());
Foam::fileHandler(handler);
Foam::fileHandler(fileOperation::New(handlerType, bannerEnabled()));
}
......@@ -1549,8 +1550,7 @@ Foam::argList::~argList()
jobInfo.end();
// Delete file handler to flush any remaining IO
autoPtr<fileOperation> dummy(nullptr);
fileHandler(dummy);
Foam::fileHandler(nullptr);
}
......
......@@ -138,9 +138,9 @@ bool Foam::OFstreamCollator::writeFile
false // do not reduce return state
);
if (osPtr.valid() && !osPtr().good())
if (osPtr && !osPtr->good())
{
FatalIOErrorInFunction(osPtr())
FatalIOErrorInFunction(*osPtr)
<< "Failed writing to " << fName << exit(FatalIOError);
}
......@@ -334,13 +334,13 @@ Foam::OFstreamCollator::OFstreamCollator
Foam::OFstreamCollator::~OFstreamCollator()
{
if (thread_.valid())
if (thread_)
{
if (debug)
{
Pout<< "~OFstreamCollator : Waiting for write thread" << endl;
}
thread_().join();
thread_->join();
thread_.clear();
}
......@@ -505,14 +505,14 @@ bool Foam::OFstreamCollator::write
// Start thread if not running
if (!threadRunning_)
{
if (thread_.valid())
if (thread_)
{
if (debug)
{
Pout<< "OFstreamCollator : Waiting for write thread"
<< endl;
}
thread_().join();
thread_->join();
}
if (debug)
......@@ -573,14 +573,14 @@ bool Foam::OFstreamCollator::write
if (!threadRunning_)
{
if (thread_.valid())
if (thread_)
{
if (debug)
{
Pout<< "OFstreamCollator : Waiting for write thread"
<< endl;
}
thread_().join();
thread_->join();
}
if (debug)
......
......@@ -41,8 +41,6 @@ License
namespace Foam
{
autoPtr<fileOperation> fileOperation::fileHandlerPtr_;
defineTypeNameAndDebug(fileOperation, 0);
defineRunTimeSelectionTable(fileOperation, word);
......@@ -59,6 +57,8 @@ namespace Foam
}
Foam::autoPtr<Foam::fileOperation> Foam::fileOperation::fileHandlerPtr_;
Foam::word Foam::fileOperation::processorsBaseDir = "processors";
const Foam::Enum<Foam::fileOperation::pathType>
......@@ -83,7 +83,7 @@ Foam::fileOperation::pathTypeNames_
Foam::fileMonitor& Foam::fileOperation::monitor() const
{
if (!monitorPtr_.valid())
if (!monitorPtr_)
{
monitorPtr_.reset
(
......@@ -1169,7 +1169,7 @@ Foam::label Foam::fileOperation::detectProcessorPath(const fileName& fName)
const Foam::fileOperation& Foam::fileHandler()
{
if (!fileOperation::fileHandlerPtr_.valid())
if (!fileOperation::fileHandlerPtr_)
{
word handler(getEnv("FOAM_FILEHANDLER"));
......@@ -1185,23 +1185,19 @@ const Foam::fileOperation& Foam::fileHandler()
}
void Foam::fileHandler(autoPtr<fileOperation>& newHandler)
void Foam::fileHandler(autoPtr<fileOperation>&& newHandler)
{
if
(
newHandler.valid() && fileOperation::fileHandlerPtr_.valid()
newHandler
&& fileOperation::fileHandlerPtr_
&& newHandler->type() == fileOperation::fileHandlerPtr_->type()
)
{
return;
}
fileOperation::fileHandlerPtr_.clear();
if (newHandler.valid())
{
fileOperation::fileHandlerPtr_ = std::move(newHandler);
}
fileOperation::fileHandlerPtr_ = std::move(newHandler);
}
......
......@@ -58,6 +58,7 @@ Description
namespace Foam
{
// Forward Declarations
class IOobject;
class regIOobject;
class objectRegistry;
......@@ -564,8 +565,8 @@ public:
//- Get current file handler
const fileOperation& fileHandler();
//- Reset file handler
void fileHandler(autoPtr<fileOperation>& newHandler);
//- Replace, reset file handler
void fileHandler(autoPtr<fileOperation>&& newHandler);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -638,9 +638,9 @@ Foam::fileOperations::masterUncollatedFileOperation::read
isPtr.reset(new IFstream(filePaths[0]));
// Read header
if (!io.readHeader(isPtr()))
if (!io.readHeader(*isPtr))
{
FatalIOErrorInFunction(isPtr())
FatalIOErrorInFunction(*isPtr)
<< "problem while reading header for object "
<< io.name() << exit(FatalIOError);
}
......@@ -684,7 +684,7 @@ Foam::fileOperations::masterUncollatedFileOperation::read
{
// This processor needs to return something
if (!isPtr.valid())
if (!isPtr)
{
UIPstream is(Pstream::masterNo(), pBufs);
......@@ -709,9 +709,9 @@ Foam::fileOperations::masterUncollatedFileOperation::read
// With the proper file name
isPtr->name() = filePaths[Pstream::myProcNo(comm)];
if (!io.readHeader(isPtr()))
if (!io.readHeader(*isPtr))
{
FatalIOErrorInFunction(isPtr())
FatalIOErrorInFunction(*isPtr)
<< "problem while reading header for object "
<< io.name() << exit(FatalIOError);
}
......@@ -1918,10 +1918,10 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
isPtr.reset(new IFstream(fName));
if (isPtr().good())
if (isPtr->good())
{
// Read header data (on copy)
headerIO.readHeader(isPtr());
headerIO.readHeader(*isPtr);
if (headerIO.headerClassName() == decomposedBlockData::typeName)
{
......@@ -1986,7 +1986,7 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
if (proci == -1)
{
FatalIOErrorInFunction(isPtr())
FatalIOErrorInFunction(*isPtr)
<< "Could not detect processor number"
<< " from objectPath:" << io.objectPath()
<< exit(FatalIOError);
......@@ -2005,10 +2005,10 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
Pout<< "masterUncollatedFileOperation::readStream :"
<< " For object : " << io.name()
<< " starting input from block " << proci
<< " of " << isPtr().name() << endl;
<< " of " << isPtr->name() << endl;
}
return decomposedBlockData::readBlock(proci, isPtr(), io);
return decomposedBlockData::readBlock(proci, *isPtr, io);
}
else
{
......@@ -2023,17 +2023,17 @@ Foam::fileOperations::masterUncollatedFileOperation::readStream
if (groupStart != -1 && groupSize > 0)
{
readComm = comm_;
if (UPstream::master(comm_) && !isPtr.valid() && !fName.empty())
if (UPstream::master(comm_) && !isPtr && !fName.empty())
{
// In multi-master mode also open the file on the other
// masters
isPtr.reset(new IFstream(fName));
if (isPtr().good())
if (isPtr->good())
{
// Read header data (on copy)
IOobject headerIO(io);
headerIO.readHeader(isPtr());
headerIO.readHeader(*isPtr);
}
}
}
......
......@@ -502,17 +502,17 @@ bool Foam::fileOperations::uncollatedFileOperation::readHeader
autoPtr<ISstream> isPtr(NewIFstream(fName));
if (!isPtr.valid() || !isPtr->good())
if (!isPtr || !isPtr->good())
{
return false;
}
bool ok = io.readHeader(isPtr());
bool ok = io.readHeader(*isPtr);
if (io.headerClassName() == decomposedBlockData::typeName)
{
// Read the header inside the container (master data)
ok = decomposedBlockData::readMasterHeader(io, isPtr());
ok = decomposedBlockData::readMasterHeader(io, *isPtr);
}
if (debug)
......@@ -536,12 +536,9 @@ Foam::fileOperations::uncollatedFileOperation::readStream
const bool valid
) const
{
autoPtr<ISstream> isPtr;
if (!valid)
{
isPtr = autoPtr<ISstream>(new dummyISstream());
return isPtr;
return autoPtr<ISstream>(new dummyISstream());
}
if (fName.empty())
......@@ -551,9 +548,9 @@ Foam::fileOperations::uncollatedFileOperation::readStream
<< exit(FatalError);
}
isPtr = NewIFstream(fName);
autoPtr<ISstream> isPtr = NewIFstream(fName);
if (!isPtr.valid() || !isPtr->good())
if (!isPtr || !isPtr->good())
{
FatalIOError
(
......@@ -565,9 +562,9 @@ Foam::fileOperations::uncollatedFileOperation::readStream
) << "cannot open file"
<< exit(FatalIOError);
}
else if (!io.readHeader(isPtr()))
else if (!io.readHeader(*isPtr))
{
FatalIOErrorInFunction(isPtr())
FatalIOErrorInFunction(*isPtr)
<< "problem while reading header for object " << io.name()
<< exit(FatalIOError);
}
......@@ -584,7 +581,7 @@ Foam::fileOperations::uncollatedFileOperation::readStream
if (proci == -1)
{
FatalIOErrorInFunction(isPtr())
FatalIOErrorInFunction(*isPtr)
<< "could not detect processor number"
<< " from objectPath:" << io.objectPath()
<< " fName:" << fName
......@@ -612,7 +609,7 @@ Foam::fileOperations::uncollatedFileOperation::readStream
}
// Read data and return as stream
return decomposedBlockData::readBlock(proci, isPtr(), io);
return decomposedBlockData::readBlock(proci, *isPtr, io);
}
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -166,10 +167,10 @@ public:
// Constructors
faSolver(faMatrix<Type>& faMat, autoPtr<lduMatrix::solver> sol)
faSolver(faMatrix<Type>& faMat, autoPtr<lduMatrix::solver>&& sol)
:
faMat_(faMat),
solver_(sol)
solver_(std::move(sol))
{}
......
......@@ -231,10 +231,10 @@ public:
// Constructors
fvSolver(fvMatrix<Type>& fvMat, autoPtr<lduMatrix::solver> sol)
fvSolver(fvMatrix<Type>& fvMat, autoPtr<lduMatrix::solver>&& sol)
:
fvMat_(fvMat),
solver_(sol)
solver_(std::move(sol))
{}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment