ENH: iterator method good() as a synonym for testing validity

- applies to HashTable and Linked-Lists

- deprecate the Linked-List iterator found() method, since this makes
  less sense (linguistically)
This commit is contained in:
Mark Olesen
2019-01-04 14:07:01 +01:00
parent 0dbd05daa4
commit 86e1933057
9 changed files with 73 additions and 22 deletions

View File

@ -75,7 +75,7 @@ Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
Foam::autoPtr<T> Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter) Foam::autoPtr<T> Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
{ {
if (iter.found()) if (iter.good())
{ {
autoPtr<T> aptr(iter.object()); autoPtr<T> aptr(iter.object());
this->parent_type::erase(iter); this->parent_type::erase(iter);
@ -97,7 +97,7 @@ Foam::autoPtr<T> Foam::HashPtrTable<T, Key, Hash>::remove(const Key& key)
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter) bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
{ {
if (iter.found()) if (iter.good())
{ {
T* ptr = iter.object(); T* ptr = iter.object();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -95,7 +95,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators // Forward declarations
template<class T> class List; template<class T> class List;
template<class T> class UList; template<class T> class UList;
@ -678,6 +678,10 @@ protected:
// Member Functions // Member Functions
//- True if iterator points to an entry
// This can be used directly instead of comparing to end()
inline bool good() const;
//- True if iterator points to an entry //- True if iterator points to an entry
// This can be used directly instead of comparing to end() // This can be used directly instead of comparing to end()
inline bool found() const; inline bool found() const;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -107,6 +107,15 @@ Foam::HashTable<T, Key, Hash>::Iterator<Const>::increment()
} }
template<class T, class Key, class Hash>
template<bool Const>
inline bool
Foam::HashTable<T, Key, Hash>::Iterator<Const>::good() const
{
return entry_;
}
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
template<bool Const> template<bool Const>
inline bool inline bool

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,7 +45,7 @@ SourceFiles
#include "label.H" #include "label.H"
#include "uLabel.H" #include "uLabel.H"
#include <utility> #include "stdFoam.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -237,7 +237,15 @@ public:
inline link* get_node() const; inline link* get_node() const;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool found() const; inline bool good() const;
//- Deprecated(2019-01) Pointing at a valid storage node
// \deprecated(2019-01) - use good() method
inline bool found() const
FOAM_DEPRECATED_FOR(2019-01, "good() method")
{
return this->good();
}
//- Move backward through list //- Move backward through list
inline void prev(); inline void prev();
@ -283,7 +291,15 @@ public:
inline const link* get_node() const; inline const link* get_node() const;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool found() const; inline bool good() const;
//- Deprecated(2019-01) Pointing at a valid storage node
// \deprecated(2019-01) - use good() method
inline bool found() const
FOAM_DEPRECATED_FOR(2019-01, "good() method")
{
return this->good();
}
//- Move backward through list //- Move backward through list
inline void prev(); inline void prev();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -245,7 +245,7 @@ Foam::DLListBase::iterator::get_node() const
} }
inline bool Foam::DLListBase::iterator::found() const inline bool Foam::DLListBase::iterator::good() const
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }
@ -351,7 +351,7 @@ Foam::DLListBase::const_iterator::get_node() const
} }
inline bool Foam::DLListBase::const_iterator::found() const inline bool Foam::DLListBase::const_iterator::good() const
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,7 +45,7 @@ SourceFiles
#include "label.H" #include "label.H"
#include "uLabel.H" #include "uLabel.H"
#include <utility> #include "stdFoam.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -213,7 +213,15 @@ public:
inline link* get_node() const; inline link* get_node() const;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool found() const; inline bool good() const;
//- Deprecated(2019-01) Pointing at a valid storage node
// \deprecated(2019-01) - use good() method
inline bool found() const
FOAM_DEPRECATED_FOR(2019-01, "good() method")
{
return this->good();
}
//- Cannot move backward through list //- Cannot move backward through list
inline void prev() = delete; inline void prev() = delete;
@ -257,7 +265,15 @@ public:
inline const link* get_node() const; inline const link* get_node() const;
//- Pointing at a valid storage node //- Pointing at a valid storage node
inline bool found() const; inline bool good() const;
//- Deprecated(2019-01) Pointing at a valid storage node
// \deprecated(2019-01) - use good() method
inline bool found() const
FOAM_DEPRECATED_FOR(2019-01, "good() method")
{
return this->good();
}
//- Cannot move backward through list //- Cannot move backward through list
inline void prev() = delete; inline void prev() = delete;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -189,7 +189,7 @@ Foam::SLListBase::iterator::get_node() const
} }
inline bool Foam::SLListBase::iterator::found() const inline bool Foam::SLListBase::iterator::good() const
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }
@ -288,7 +288,7 @@ Foam::SLListBase::const_iterator::get_node() const
} }
inline bool Foam::SLListBase::const_iterator::found() const inline bool Foam::SLListBase::const_iterator::good() const
{ {
return (node_ != nullptr); return (node_ != nullptr);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -192,6 +192,12 @@ public:
{} {}
//- True if entry was found
inline bool good() const
{
return eptr_;
}
//- True if entry was found //- True if entry was found
inline bool found() const inline bool found() const
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -42,7 +42,7 @@ namespace
ReIterator& reIter ReIterator& reIter
) )
{ {
while (wcIter.found()) while (wcIter.good())
{ {
if if
( (