STYLE: find(), cfind() methods instead of lookupPtr()

- coordinateSystems, DictionaryBase
This commit is contained in:
Mark Olesen
2020-03-11 21:28:01 +01:00
parent a18617bbd1
commit 8e27022ea2
13 changed files with 70 additions and 38 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -94,7 +94,7 @@ bool Foam::DictionaryBase<IDLListType, T>::found(const word& keyword) const
template<class IDLListType, class T>
const T* Foam::DictionaryBase<IDLListType, T>::lookupPtr
const T* Foam::DictionaryBase<IDLListType, T>::cfind
(
const word& keyword
) const
@ -111,7 +111,7 @@ const T* Foam::DictionaryBase<IDLListType, T>::lookupPtr
template<class IDLListType, class T>
T* Foam::DictionaryBase<IDLListType, T>::lookupPtr(const word& keyword)
T* Foam::DictionaryBase<IDLListType, T>::find(const word& keyword)
{
auto iter = hashedTs_.find(keyword);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -58,7 +59,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
template<class IDLListType, class T>
class DictionaryBase;
@ -78,13 +79,13 @@ class DictionaryBase
{
protected:
// Protected data
// Protected Data
//- HashTable of the entries held on the IDLListType for quick lookup
HashTable<T*> hashedTs_;
// Protected Member functions
// Protected Member Functions
// Add the IDLListType entries into the HashTable
void addEntries();
@ -115,16 +116,16 @@ public:
//- Search for given keyword
bool found(const word& keyword) const;
//- Find and return an entry if present, otherwise return nullptr
const T* lookupPtr(const word& keyword) const;
//- Find and return an entry, nullptr on failure.
const T* cfind(const word& keyword) const;
//- Find and return an entry if present, otherwise return nullptr
T* lookupPtr(const word& keyword);
//- Find and return an entry, nullptr on failure.
T* find(const word& keyword);
//- Find and return entry
//- Find and return entry, FatalError on failure.
const T* lookup(const word& keyword) const;
//- Find and return entry
//- Find and return entry, FatalError on failure.
T* lookup(const word& keyword);
//- Return the table of contents (as a sorted list)
@ -183,6 +184,27 @@ public:
Ostream&,
const DictionaryBase<IDLListType, T>&
);
// Housekeeping
//- Deprecated(2020-03) use cfind()
//
// \deprecated(2020-03) - use cfind() method
FOAM_DEPRECATED_FOR(2020-03, "cfind() method")
const T* lookupPtr(const word& keyword) const
{
return this->cfind(keyword);
}
//- Deprecated(2020-03) use find()
//
// \deprecated(2020-03) - use find() method
FOAM_DEPRECATED_FOR(2020-03, "find() method")
T* lookupPtr(const word& keyword)
{
return this->find(keyword);
}
};

View File

@ -230,7 +230,7 @@ void Foam::Time::readDict()
dictionary dict(Foam::dimensionSystems());
dict.merge(*localDict);
simpleObjectRegistryEntry* objPtr = objs.lookupPtr("DimensionSets");
simpleObjectRegistryEntry* objPtr = objs.find("DimensionSets");
if (objPtr)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -124,7 +124,7 @@ static inline void appendNamedEntry
simpleRegIOobject* obj
)
{
simpleObjectRegistryEntry* ptr = obr.lookupPtr(name);
simpleObjectRegistryEntry* ptr = obr.find(name);
if (ptr)
{
ptr->append(obj);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,7 +47,7 @@ void Foam::simpleObjectRegistry::setValues
{
const word& name = dEntry.keyword();
simpleObjectRegistryEntry* objPtr = this->lookupPtr(name);
simpleObjectRegistryEntry* objPtr = this->find(name);
if (objPtr)
{
@ -116,7 +116,7 @@ void Foam::simpleObjectRegistry::setNamedInt
}
simpleObjectRegistryEntry* objPtr = this->lookupPtr(name.c_str());
simpleObjectRegistryEntry* objPtr = this->find(name.c_str());
if (objPtr)
{

View File

@ -330,7 +330,7 @@ bool Foam::coordinateSystems::found(const keyType& key) const
const Foam::coordinateSystem*
Foam::coordinateSystems::lookupPtr(const word& name) const
Foam::coordinateSystems::cfind(const word& name) const
{
const label index = this->findIndex(name);

View File

@ -99,7 +99,7 @@ class coordinateSystems
public:
//- Runtime type information
//- Declare type-name, virtual type (without debug switch)
TypeNameNoDebug("coordinateSystems");
@ -146,12 +146,12 @@ public:
//- Search if given key exists
bool found(const keyType& key) const;
//- Return pointer to named coordinateSystem or nullptr on error
const coordinateSystem* cfind(const word& name) const;
//- Return reference to named coordinateSystem or FatalErrror
const coordinateSystem& lookup(const word& name) const;
//- Return pointer to named coordinateSystem or nullptr on error
const coordinateSystem* lookupPtr(const word& name) const;
//- A list of the coordinate-system names
wordList names() const;
@ -191,6 +191,15 @@ public:
{
return this->indices(key);
}
//- Deprecated(2020-03) find named coordinateSystem or nullptr
//
// \deprecated(2020-03) - use cfind() method
FOAM_DEPRECATED_FOR(2020-03, "cfind() method")
const coordinateSystem* lookupPtr(const word& name) const
{
return this->cfind(name);
}
};

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -57,7 +57,7 @@ Foam::coordSystem::indirect::indirect(indirect&& csys)
{}
// Use lookup() instead of lookupPtr() to trigger FatalError on any problems
// Use lookup() instead of cfind() to trigger FatalError on any problems
Foam::coordSystem::indirect::indirect
(
const objectRegistry& obr,