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:
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user