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,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -191,7 +192,7 @@ int main(int argc, char *argv[])
scalarDict.transfer(scalarDict2); scalarDict.transfer(scalarDict2);
Scalar* p = scalarDict.lookupPtr("ent8"); const Scalar* p = scalarDict.cfind("ent8");
// This does not (yet) work // This does not (yet) work
// Scalar* q = scalarDict.remove("ent10"); // Scalar* q = scalarDict.remove("ent10");
@ -210,7 +211,6 @@ int main(int argc, char *argv[])
// Info<< " = " << *iter << endl; // Info<< " = " << *iter << endl;
Info<< nl << "Done." << endl; Info<< nl << "Done." << endl;
return 0; return 0;
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -86,7 +87,7 @@ int main(int argc, char *argv[])
Info<< "elem " << i << " = " << scalarDict[i] << endl; Info<< "elem " << i << " = " << scalarDict[i] << endl;
} }
Scalar* ent8Ptr = scalarDict.lookupPtr("ent8"); const Scalar* ent8Ptr = scalarDict.lookup("ent8");
Info<< "ent8 = " << *ent8Ptr << endl; Info<< "ent8 = " << *ent8Ptr << endl;
@ -104,7 +105,7 @@ int main(int argc, char *argv[])
scalarDict.transfer(scalarDict2); scalarDict.transfer(scalarDict2);
Scalar* p = scalarDict.lookupPtr("ent8"); const Scalar* p = scalarDict.cfind("ent8");
if (p) if (p)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -184,7 +184,7 @@ int main(int argc, char *argv[])
if (args.found("from")) if (args.found("from"))
{ {
const word csName(args["from"]); const word csName(args["from"]);
const auto* csPtr = globalCoords.lookupPtr(csName); const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr) if (!csPtr)
{ {
@ -201,7 +201,7 @@ int main(int argc, char *argv[])
if (args.found("to")) if (args.found("to"))
{ {
const word csName(args["to"]); const word csName(args["to"]);
const auto* csPtr = globalCoords.lookupPtr(csName); const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr) if (!csPtr)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -172,7 +172,7 @@ int main(int argc, char *argv[])
if (args.found("from")) if (args.found("from"))
{ {
const word csName(args["from"]); const word csName(args["from"]);
const auto* csPtr = globalCoords.lookupPtr(csName); const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr) if (!csPtr)
{ {
@ -189,7 +189,7 @@ int main(int argc, char *argv[])
if (args.found("to")) if (args.found("to"))
{ {
const word csName(args["to"]); const word csName(args["to"]);
const auto* csPtr = globalCoords.lookupPtr(csName); const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr) if (!csPtr)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -185,7 +185,7 @@ int main(int argc, char *argv[])
if (args.found("from")) if (args.found("from"))
{ {
const word csName(args["from"]); const word csName(args["from"]);
const auto* csPtr = globalCoords.lookupPtr(csName); const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr) if (!csPtr)
{ {
@ -202,7 +202,7 @@ int main(int argc, char *argv[])
if (args.found("to")) if (args.found("to"))
{ {
const word csName(args["to"]); const word csName(args["to"]);
const auto* csPtr = globalCoords.lookupPtr(csName); const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr) if (!csPtr)
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -99,7 +99,7 @@ class coordinateSystems
public: public:
//- Runtime type information //- Declare type-name, virtual type (without debug switch)
TypeNameNoDebug("coordinateSystems"); TypeNameNoDebug("coordinateSystems");
@ -146,12 +146,12 @@ public:
//- Search if given key exists //- Search if given key exists
bool found(const keyType& key) const; 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 //- Return reference to named coordinateSystem or FatalErrror
const coordinateSystem& lookup(const word& name) const; 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 //- A list of the coordinate-system names
wordList names() const; wordList names() const;
@ -191,6 +191,15 @@ public:
{ {
return this->indices(key); 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 \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. 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 Foam::coordSystem::indirect::indirect
( (
const objectRegistry& obr, const objectRegistry& obr,