From ef0d15546a40ba4e51371bcee50f125d12c8afb3 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 24 Apr 2019 10:26:41 +0200 Subject: [PATCH] ENH: support checkIn/checkOut with pointers (#1276) --- .../db/objectRegistry/objectRegistry.C | 43 +++++++++++++------ .../db/objectRegistry/objectRegistry.H | 13 ++++-- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 3137457212..ccdae9f380 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -239,25 +239,27 @@ Foam::label Foam::objectRegistry::getEvent() const } -bool Foam::objectRegistry::checkIn(regIOobject& io) const +bool Foam::objectRegistry::checkIn(regIOobject* io) const { + if (!io) return false; + if (objectRegistry::debug) { - Pout<< "objectRegistry::checkIn(regIOobject&) : " - << name() << " : checking in " << io.name() - << " of type " << io.type() + Pout<< "objectRegistry::checkIn : " + << name() << " : checking in " << io->name() + << " of type " << io->type() << endl; } objectRegistry& obr = const_cast(*this); - bool ok = obr.insert(io.name(), &io); + bool ok = obr.insert(io->name(), io); if (!ok && objectRegistry::debug) { WarningInFunction << name() << " : attempted to checkIn object with name " - << io.name() << " which was already checked in" + << io->name() << " which was already checked in" << endl; } @@ -265,22 +267,25 @@ bool Foam::objectRegistry::checkIn(regIOobject& io) const } -bool Foam::objectRegistry::checkOut(regIOobject& io) const +bool Foam::objectRegistry::checkOut(regIOobject* io) const { + if (!io) return false; + objectRegistry& obr = const_cast(*this); - iterator iter = obr.find(io.name()); + iterator iter = obr.find(io->name()); if (iter.found()) { if (objectRegistry::debug) { - Pout<< "objectRegistry::checkOut(regIOobject&) : " - << name() << " : checking out " << io.name() + Pout<< "objectRegistry::checkOut : " + << name() << " : checking out " << io->name() + << " of type " << io->type() << endl; } - if (iter.val() != &io) + if (iter.val() != io) { if (objectRegistry::debug) { @@ -299,8 +304,8 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const if (objectRegistry::debug) { - Pout<< "objectRegistry::checkOut(regIOobject&) : " - << name() << " : could not find " << io.name() << " in registry" + Pout<< "objectRegistry::checkOut : " + << name() << " : could not find " << io->name() << " in registry" << endl; } @@ -308,6 +313,18 @@ bool Foam::objectRegistry::checkOut(regIOobject& io) const } +bool Foam::objectRegistry::checkIn(regIOobject& io) const +{ + return checkIn(&io); +} + + +bool Foam::objectRegistry::checkOut(regIOobject& io) const +{ + return checkOut(&io); +} + + bool Foam::objectRegistry::checkOut(const word& key) const { return const_cast(*this).erase(key); diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index fcfa109875..0c303602c4 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -452,14 +452,21 @@ public: // Edit + //- Add a regIOobject to registry. A nullptr is ignored. + bool checkIn(regIOobject* io) const; + //- Add a regIOobject to registry bool checkIn(regIOobject& io) const; - //- Remove a regIOobject from registry and frees memory if the - //- object is ownedByRegistry + //- Remove a regIOobject from registry and free memory if the + //- object is ownedByRegistry. A nullptr is ignored. + bool checkOut(regIOobject* io) const; + + //- Remove a regIOobject from registry and free memory if the + //- object is ownedByRegistry. bool checkOut(regIOobject& io) const; - //- Remove a regIOobject by name from registry and frees memory if the + //- Remove a regIOobject by name from registry and free memory if the //- object is ownedByRegistry bool checkOut(const word& key) const;