ENH: additional std::unique_ptr support for regIOobject and IOobjectList

- regIOobject::store(std::unique_ptr<...>&& ptr)
- IOobjectList::add(std::unique_ptr<...>&& ptr)

STYLE: io.globalCaseName() instead of io.time().globalCaseName() [#3007]
This commit is contained in:
Mark Olesen
2024-04-10 11:23:55 +02:00
parent 6ac572a179
commit 0dcc53ab03
8 changed files with 60 additions and 21 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2023 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -228,6 +228,9 @@ public:
// Basic methods // Basic methods
//- Move insert IOobject into the list
inline bool add(std::unique_ptr<IOobject>&& objectPtr);
//- Move insert IOobject into the list //- Move insert IOobject into the list
inline bool add(autoPtr<IOobject>& objectPtr); inline bool add(autoPtr<IOobject>& objectPtr);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022-2023 OpenCFD Ltd. Copyright (C) 2022-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -109,6 +109,17 @@ inline Foam::IOobjectList::IOobjectList
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::IOobjectList::add(std::unique_ptr<IOobject>&& objectPtr)
{
if (objectPtr)
{
return insert(objectPtr->name(), std::move(objectPtr));
}
return false;
}
inline bool Foam::IOobjectList::add(autoPtr<IOobject>& objectPtr) inline bool Foam::IOobjectList::add(autoPtr<IOobject>& objectPtr)
{ {
if (objectPtr) if (objectPtr)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -195,6 +195,12 @@ public:
template<class Type> template<class Type>
inline static Type& store(Type* p); inline static Type& store(Type* p);
//- Transfer pointer ownership to its registry.
// Resets (clears) the parameter.
// \return reference to the stored object
template<class Type>
inline static Type& store(std::unique_ptr<Type>&& ptr);
//- Transfer pointer ownership to its registry. //- Transfer pointer ownership to its registry.
// Resets (clears) the parameter. // Resets (clears) the parameter.
// \return reference to the stored object // \return reference to the stored object

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2018-2023 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -80,6 +80,14 @@ inline Type& Foam::regIOobject::store(Type* p)
} }
template<class Type>
inline Type& Foam::regIOobject::store(std::unique_ptr<Type>&& ptr)
{
// Pass management to objectRegistry
return store(ptr.release());
}
template<class Type> template<class Type>
inline Type& Foam::regIOobject::store(autoPtr<Type>& ptr) inline Type& Foam::regIOobject::store(autoPtr<Type>& ptr)
{ {
@ -182,6 +190,7 @@ inline Type& Foam::regIOobject::store(tmp<Type>&& ptr)
inline void Foam::regIOobject::release(const bool unregister) noexcept inline void Foam::regIOobject::release(const bool unregister) noexcept
{ {
// Note: could also return the old ownedByRegistry_ value
ownedByRegistry_ = false; ownedByRegistry_ = false;
if (unregister) if (unregister)
{ {

View File

@ -1413,7 +1413,7 @@ Foam::fileName Foam::fileOperation::processorsCasePath
const word& procsDir const word& procsDir
) const ) const
{ {
return io.rootPath()/io.time().globalCaseName()/procsDir; return io.rootPath()/io.globalCaseName()/procsDir;
} }

View File

@ -198,8 +198,10 @@ Foam::fileOperations::masterUncollatedFileOperation::filePathInfo
) )
{ {
fileName parentPath = fileName parentPath =
io.rootPath()/io.time().globalCaseName() (
/io.instance()/io.db().dbDir()/io.local()/io.name(); io.rootPath()/io.globalCaseName()
/io.instance()/io.db().dbDir()/io.local()/io.name()
);
if (isFileOrDir(isFile, parentPath)) if (isFileOrDir(isFile, parentPath))
{ {
@ -356,7 +358,7 @@ Foam::fileOperations::masterUncollatedFileOperation::localObjectPath
case fileOperation::PARENTOBJECT: case fileOperation::PARENTOBJECT:
{ {
return return
io.rootPath()/io.time().globalCaseName() io.rootPath()/io.globalCaseName()
/io.instance()/io.db().dbDir()/io.local()/io.name(); /io.instance()/io.db().dbDir()/io.local()/io.name();
} }
break; break;

View File

@ -108,13 +108,15 @@ Foam::fileName Foam::fileOperations::uncollatedFileOperation::filePathInfo
{ {
// Constant & system can come from global case // Constant & system can come from global case
fileName parentObjectPath = fileName parentPath =
io.rootPath()/io.time().globalCaseName() (
/io.instance()/io.db().dbDir()/io.local()/io.name(); io.rootPath()/io.globalCaseName()
/io.instance()/io.db().dbDir()/io.local()/io.name()
);
if (isFileOrDir(isFile, parentObjectPath)) if (isFileOrDir(isFile, parentPath))
{ {
return parentObjectPath; return parentPath;
} }
} }

View File

@ -250,8 +250,10 @@ Foam::word Foam::distributedTriSurfaceMesh::findLocalInstance
// Search in parent directory // Search in parent directory
fileName parentDir = fileName parentDir =
io.rootPath()/io.time().globalCaseName() (
/io.instance()/io.db().dbDir()/io.local()/io.name(); io.rootPath()/io.globalCaseName()
/io.instance()/io.db().dbDir()/io.local()/io.name()
);
if (fileHandler().isDir(parentDir)) if (fileHandler().isDir(parentDir))
{ {
@ -280,9 +282,11 @@ Foam::word Foam::distributedTriSurfaceMesh::findLocalInstance
continue; continue;
} }
fileName parentDir = parentDir =
io.rootPath()/io.time().globalCaseName() (
/ts[instanceI].name()/io.db().dbDir()/io.local()/io.name(); io.rootPath()/io.globalCaseName()
/ts[instanceI].name()/io.db().dbDir()/io.local()/io.name()
);
if (fileHandler().isDir(parentDir)) if (fileHandler().isDir(parentDir))
{ {
@ -301,9 +305,11 @@ Foam::word Foam::distributedTriSurfaceMesh::findLocalInstance
// constant function of the time, because the latter points to // constant function of the time, because the latter points to
// the case constant directory in parallel cases // the case constant directory in parallel cases
fileName parentDir = parentDir =
io.rootPath()/io.time().globalCaseName() (
/io.time().constant()/io.db().dbDir()/io.local()/io.name(); io.rootPath()/io.globalCaseName()
/io.time().constant()/io.db().dbDir()/io.local()/io.name()
);
if (fileHandler().isDir(parentDir)) if (fileHandler().isDir(parentDir))
{ {