From 86e19330579d2b1da383308abc9ca83c11500832 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 4 Jan 2019 14:07:01 +0100
Subject: [PATCH] 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)
---
 .../HashTables/HashPtrTable/HashPtrTable.C    |  4 ++--
 .../HashTables/HashTable/HashTable.H          |  8 +++++--
 .../HashTables/HashTable/HashTableIterI.H     | 11 ++++++++-
 .../linkTypes/DLListBase/DLListBase.H         | 24 +++++++++++++++----
 .../linkTypes/DLListBase/DLListBaseI.H        |  6 ++---
 .../linkTypes/SLListBase/SLListBase.H         | 24 +++++++++++++++----
 .../linkTypes/SLListBase/SLListBaseI.H        |  6 ++---
 src/OpenFOAM/db/dictionary/dictionary.H       |  8 ++++++-
 src/OpenFOAM/db/dictionary/dictionarySearch.C |  4 ++--
 9 files changed, 73 insertions(+), 22 deletions(-)

diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C
index 7ca213778ea..e9626ae2ed3 100644
--- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C
+++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C
@@ -75,7 +75,7 @@ Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
 template<class T, class Key, class Hash>
 Foam::autoPtr<T> Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
 {
-    if (iter.found())
+    if (iter.good())
     {
         autoPtr<T> aptr(iter.object());
         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>
 bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
 {
-    if (iter.found())
+    if (iter.good())
     {
         T* ptr = iter.object();
 
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
index 323d5450f03..8b6f4ae10aa 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    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
     This file is part of OpenFOAM.
@@ -95,7 +95,7 @@ SourceFiles
 namespace Foam
 {
 
-// Forward declaration of friend functions and operators
+// Forward declarations
 
 template<class T> class List;
 template<class T> class UList;
@@ -678,6 +678,10 @@ protected:
 
         // 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
             //  This can be used directly instead of comparing to end()
             inline bool found() const;
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H
index 93132e2bc17..c693df431c7 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableIterI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 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<bool Const>
 inline bool
diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H
index c538e147e21..4bb2825e415 100644
--- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H
+++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,7 +45,7 @@ SourceFiles
 
 #include "label.H"
 #include "uLabel.H"
-#include <utility>
+#include "stdFoam.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -237,7 +237,15 @@ public:
             inline link* get_node() const;
 
             //- 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
             inline void prev();
@@ -283,7 +291,15 @@ public:
             inline const link* get_node() const;
 
             //- 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
             inline void prev();
diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H
index 6f072108218..af3e2b6150f 100644
--- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H
+++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBaseI.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     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);
 }
@@ -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);
 }
diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H
index 7b364137ba7..b79afb0adb7 100644
--- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H
+++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBase.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,7 +45,7 @@ SourceFiles
 
 #include "label.H"
 #include "uLabel.H"
-#include <utility>
+#include "stdFoam.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -213,7 +213,15 @@ public:
             inline link* get_node() const;
 
             //- 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
             inline void prev() = delete;
@@ -257,7 +265,15 @@ public:
             inline const link* get_node() const;
 
             //- 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
             inline void prev() = delete;
diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H
index be940f3ab2f..b4d46b3d410 100644
--- a/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H
+++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/SLListBase/SLListBaseI.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2019 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     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);
 }
@@ -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);
 }
diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H
index e5f79faebe9..30e6c687cf3 100644
--- a/src/OpenFOAM/db/dictionary/dictionary.H
+++ b/src/OpenFOAM/db/dictionary/dictionary.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    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
     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
             inline bool found() const
             {
diff --git a/src/OpenFOAM/db/dictionary/dictionarySearch.C b/src/OpenFOAM/db/dictionary/dictionarySearch.C
index 18057745a0f..28895987365 100644
--- a/src/OpenFOAM/db/dictionary/dictionarySearch.C
+++ b/src/OpenFOAM/db/dictionary/dictionarySearch.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -42,7 +42,7 @@ namespace
         ReIterator& reIter
     )
     {
-        while (wcIter.found())
+        while (wcIter.good())
         {
             if
             (
-- 
GitLab