mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -52,10 +52,8 @@ Foam::functionObjects::regionFunctionObject::whichSubRegistry
|
||||
{
|
||||
return obr.lookupObject<objectRegistry>(subName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return obr;
|
||||
}
|
||||
|
||||
return obr;
|
||||
}
|
||||
|
||||
|
||||
@ -71,22 +69,19 @@ bool Foam::functionObjects::regionFunctionObject::writeObject
|
||||
const word& fieldName
|
||||
)
|
||||
{
|
||||
const regIOobject* objPtr =
|
||||
this->lookupObjectPtr<regIOobject>(fieldName);
|
||||
const regIOobject* obj = this->findObject<regIOobject>(fieldName);
|
||||
|
||||
if (objPtr)
|
||||
if (obj)
|
||||
{
|
||||
Log << " functionObjects::" << type() << " " << name()
|
||||
<< " writing field: " << objPtr->name() << endl;
|
||||
<< " writing field: " << obj->name() << endl;
|
||||
|
||||
objPtr->write();
|
||||
obj->write();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -95,12 +90,14 @@ bool Foam::functionObjects::regionFunctionObject::clearObject
|
||||
const word& fieldName
|
||||
)
|
||||
{
|
||||
regIOobject* objPtr = lookupObjectRefPtr<regIOobject>(fieldName);
|
||||
if (objPtr)
|
||||
// Same as getObjectPtr, since the object is already non-const
|
||||
regIOobject* obj = this->findObject<regIOobject>(fieldName);
|
||||
|
||||
if (obj)
|
||||
{
|
||||
if (objPtr->ownedByRegistry())
|
||||
if (obj->ownedByRegistry())
|
||||
{
|
||||
return objPtr->checkOut();
|
||||
return obj->checkOut();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -94,6 +94,35 @@ protected:
|
||||
template<class ObjectType>
|
||||
bool foundObject(const word& fieldName) const;
|
||||
|
||||
//- Return const pointer to the object (eg, a field) in the
|
||||
//- (sub) objectRegistry.
|
||||
//
|
||||
// \return nullptr if the object was not found or had incorrect type.
|
||||
template<class ObjectType>
|
||||
const ObjectType* cfindObject(const word& fieldName) const;
|
||||
|
||||
//- Return const pointer to the object (eg, a field) in the
|
||||
//- (sub) objectRegistry.
|
||||
//
|
||||
// \return nullptr if the object was not found or had incorrect type.
|
||||
template<class ObjectType>
|
||||
const ObjectType* findObject(const word& fieldName) const;
|
||||
|
||||
//- Return non-const pointer to the object of the given Type,
|
||||
//- (sub) objectRegistry.
|
||||
//
|
||||
// \return nullptr if the object was not found or had incorrect type.
|
||||
template<class ObjectType>
|
||||
ObjectType* findObject(const word& fieldName);
|
||||
|
||||
//- Return non-const pointer to the object of the given Type,
|
||||
//- using a const-cast to have it behave like a mutable.
|
||||
// Exercise caution when using.
|
||||
//
|
||||
// \return nullptr if the object was not found or had incorrect type.
|
||||
template<class ObjectType>
|
||||
ObjectType* getObjectPtr(const word& fieldName) const;
|
||||
|
||||
//- Lookup and return object (eg, a field) from the (sub) objectRegistry
|
||||
template<class ObjectType>
|
||||
const ObjectType& lookupObject(const word& fieldName) const;
|
||||
@ -102,18 +131,6 @@ protected:
|
||||
template<class ObjectType>
|
||||
ObjectType& lookupObjectRef(const word& fieldName) const;
|
||||
|
||||
//- Lookup and return pointer to the object,
|
||||
// otherwise nullptr if the object was not found,
|
||||
// or had the incorrect type.
|
||||
template<class ObjectType>
|
||||
const ObjectType* lookupObjectPtr(const word& fieldName) const;
|
||||
|
||||
//- Lookup and return non-const pointer to the object,
|
||||
// otherwise nullptr if the object was not found,
|
||||
// or had the incorrect type.
|
||||
template<class ObjectType>
|
||||
ObjectType* lookupObjectRefPtr(const word& fieldName) const;
|
||||
|
||||
//- Store the field in the (sub) objectRegistry under the given name
|
||||
// Note: sets the fieldName to tfield().name() if not already set
|
||||
template<class ObjectType>
|
||||
@ -177,6 +194,25 @@ public:
|
||||
|
||||
//- Read optional controls
|
||||
virtual bool read(const dictionary& dict);
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- Same as findObject
|
||||
// \deprecated use findObject (OCT-2018)
|
||||
template<class ObjectType>
|
||||
const ObjectType* lookupObjectPtr(const word& fieldName) const
|
||||
{
|
||||
return this->cfindObject<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
//- Same as getObjectPtr
|
||||
// \deprecated use getObjectPtr (OCT-2018)
|
||||
template<class ObjectType>
|
||||
ObjectType* lookupObjectRefPtr(const word& fieldName) const
|
||||
{
|
||||
return this->getObjectPtr<ObjectType>(fieldName);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -38,6 +38,47 @@ bool Foam::functionObjects::regionFunctionObject::foundObject
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
const ObjectType* Foam::functionObjects::regionFunctionObject::cfindObject
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return obr().cfindObject<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
const ObjectType* Foam::functionObjects::regionFunctionObject::findObject
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return obr().findObject<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
ObjectType* Foam::functionObjects::regionFunctionObject::findObject
|
||||
(
|
||||
const word& fieldName
|
||||
)
|
||||
{
|
||||
// Need getObjectPtr to bypass const access on the objectRegistry
|
||||
return obr().getObjectPtr<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
ObjectType* Foam::functionObjects::regionFunctionObject::getObjectPtr
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return obr().getObjectPtr<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject
|
||||
(
|
||||
@ -58,26 +99,6 @@ ObjectType& Foam::functionObjects::regionFunctionObject::lookupObjectRef
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
const ObjectType* Foam::functionObjects::regionFunctionObject::lookupObjectPtr
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return obr().lookupObjectPtr<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
ObjectType* Foam::functionObjects::regionFunctionObject::lookupObjectRefPtr
|
||||
(
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return obr().lookupObjectRefPtr<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
bool Foam::functionObjects::regionFunctionObject::store
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user