Commit ef0d1554 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: support checkIn/checkOut with pointers (#1276)

parent 887236a1
......@@ -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<objectRegistry&>(*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<objectRegistry&>(*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<objectRegistry&>(*this).erase(key);
......
......@@ -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;
......
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