Commit 8e27022e authored by Mark Olesen's avatar Mark Olesen
Browse files

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

- coordinateSystems, DictionaryBase
parent a18617bb
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -191,7 +192,7 @@ int main(int argc, char *argv[])
scalarDict.transfer(scalarDict2);
Scalar* p = scalarDict.lookupPtr("ent8");
const Scalar* p = scalarDict.cfind("ent8");
// This does not (yet) work
// Scalar* q = scalarDict.remove("ent10");
......@@ -210,7 +211,6 @@ int main(int argc, char *argv[])
// Info<< " = " << *iter << endl;
Info<< nl << "Done." << endl;
return 0;
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -86,7 +87,7 @@ int main(int argc, char *argv[])
Info<< "elem " << i << " = " << scalarDict[i] << endl;
}
Scalar* ent8Ptr = scalarDict.lookupPtr("ent8");
const Scalar* ent8Ptr = scalarDict.lookup("ent8");
Info<< "ent8 = " << *ent8Ptr << endl;
......@@ -104,7 +105,7 @@ int main(int argc, char *argv[])
scalarDict.transfer(scalarDict2);
Scalar* p = scalarDict.lookupPtr("ent8");
const Scalar* p = scalarDict.cfind("ent8");
if (p)
{
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
if (args.found("from"))
{
const word csName(args["from"]);
const auto* csPtr = globalCoords.lookupPtr(csName);
const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr)
{
......@@ -201,7 +201,7 @@ int main(int argc, char *argv[])
if (args.found("to"))
{
const word csName(args["to"]);
const auto* csPtr = globalCoords.lookupPtr(csName);
const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr)
{
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
if (args.found("from"))
{
const word csName(args["from"]);
const auto* csPtr = globalCoords.lookupPtr(csName);
const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr)
{
......@@ -189,7 +189,7 @@ int main(int argc, char *argv[])
if (args.found("to"))
{
const word csName(args["to"]);
const auto* csPtr = globalCoords.lookupPtr(csName);
const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr)
{
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -185,7 +185,7 @@ int main(int argc, char *argv[])
if (args.found("from"))
{
const word csName(args["from"]);
const auto* csPtr = globalCoords.lookupPtr(csName);
const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr)
{
......@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
if (args.found("to"))
{
const word csName(args["to"]);
const auto* csPtr = globalCoords.lookupPtr(csName);
const auto* csPtr = globalCoords.cfind(csName);
if (!csPtr)
{
......
......@@ -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);
......
......@@ -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);
}
};
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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);
}
};
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment