ENH: simplify objectRegistry access names (issue #322)

New name:  findObject(), cfindObject()
  Old name:  lookupObjectPtr()

      Return a const pointer or nullptr on failure.

  New name:  findObject()
  Old name:  --

      Return a non-const pointer or nullptr on failure.

  New name:  getObjectPtr()
  Old name:  lookupObjectRefPtr()

      Return a non-const pointer or nullptr on failure.
      Can be called on a const object and it will perform a
      const_cast.

- use these updated names and functionality in more places

NB: The older methods names are deprecated, but continue to be defined.
This commit is contained in:
Mark Olesen
2018-10-17 16:44:10 +02:00
parent e0255cfff2
commit 8fabc32539
94 changed files with 918 additions and 952 deletions

View File

@ -38,10 +38,16 @@ int Foam::functionObjects::ensightWrite::writeVolField
// State: return 0 (not-processed), -1 (skip), +1 ok
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const VolFieldType* fldPtr;
// Already done
if (state)
{
return state;
}
// Already done, or not available
if (state || !(fldPtr = lookupObjectPtr<VolFieldType>(inputName)))
const VolFieldType* fldPtr = findObject<VolFieldType>(inputName);
// Not available
if (!fldPtr)
{
return state;
}

View File

@ -82,22 +82,18 @@ bool Foam::functionObjects::removeRegisteredObject::read(const dictionary& dict)
bool Foam::functionObjects::removeRegisteredObject::execute()
{
forAll(objectNames_, i)
for (const word& objName : objectNames_)
{
if (foundObject<regIOobject>(objectNames_[i]))
regIOobject* ptr = getObjectPtr<regIOobject>(objName);
if (ptr && ptr->ownedByRegistry())
{
const regIOobject& obj =
lookupObject<regIOobject>(objectNames_[i]);
Log << type() << " " << name() << " output:" << nl
<< " removing object " << ptr->name() << nl
<< endl;
if (obj.ownedByRegistry())
{
Log << type() << " " << name() << " output:" << nl
<< " removing object " << obj.name() << nl
<< endl;
const_cast<regIOobject&>(obj).release();
delete &obj;
}
ptr->release();
delete ptr;
}
}

View File

@ -113,8 +113,7 @@ void Foam::functionObjects::residuals::writeField(const word& fieldName) const
{
const word residualName("initialResidual:" + fieldName);
const IOField<scalar>* residualPtr =
mesh_.lookupObjectPtr<IOField<scalar>>(residualName);
const auto* residualPtr = mesh_.findObject<IOField<scalar>>(residualName);
if (residualPtr)
{

View File

@ -160,10 +160,12 @@ bool Foam::functionObjects::writeDictionary::write()
bool firstDict = true;
forAll(dictNames_, i)
{
if (obr_.foundObject<dictionary>(dictNames_[i]))
const dictionary* dictptr =
obr_.findObject<dictionary>(dictNames_[i]);
if (dictptr)
{
const dictionary& dict =
obr_.lookupObject<dictionary>(dictNames_[i]);
const dictionary& dict = *dictptr;
if (dict.digest() != digests_[i])
{