From 9b7ec7180f14388a65f8c134ed0113e2d97c45ab Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 6 Nov 2018 10:06:25 +0100
Subject: [PATCH] ENH: make checkITstream methods public (dictionary, entry)

- permits use of these checks for routines wishing to handle their own
  logic.
---
 src/OpenFOAM/db/dictionary/dictionary.C       | 165 +++++++++---------
 src/OpenFOAM/db/dictionary/dictionary.H       |  11 +-
 .../db/dictionary/dictionaryTemplates.C       |  10 +-
 src/OpenFOAM/db/dictionary/entry/entry.C      |  46 ++---
 src/OpenFOAM/db/dictionary/entry/entry.H      |  17 +-
 5 files changed, 125 insertions(+), 124 deletions(-)

diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C
index 1a66d3ca537..dac9b8d40b6 100644
--- a/src/OpenFOAM/db/dictionary/dictionary.C
+++ b/src/OpenFOAM/db/dictionary/dictionary.C
@@ -46,89 +46,6 @@ bool Foam::dictionary::writeOptionalEntries
 );
 
 
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
-
-void Foam::dictionary::checkITstream
-(
-    const word& keyword,
-    const ITstream& is
-) const
-{
-    if (is.nRemainingTokens())
-    {
-        const label remaining = is.nRemainingTokens();
-
-        // Similar to SafeFatalIOError
-        if (JobInfo::constructed)
-        {
-            OSstream& err =
-                FatalIOError
-                (
-                    "",                 // functionName
-                    "",                 // sourceFileName
-                    0,                  // sourceFileLineNumber
-                    this->name(),       // ioFileName
-                    is.lineNumber()     // ioStartLineNumber
-                );
-
-            err << "'" << keyword << "' has "
-                << remaining << " excess tokens in stream" << nl << nl
-                << "    ";
-            is.writeList(err, 0);
-
-            err << exit(FatalIOError);
-        }
-        else
-        {
-            std::cerr
-                << nl
-                << "--> FOAM FATAL IO ERROR:" << nl;
-
-            std::cerr
-                << "'" << keyword << "' has "
-                << remaining << " excess tokens in stream" << nl << nl;
-
-            std::cerr
-                << "file: " << this->name()
-                << " at line " << is.lineNumber() << '.' << nl
-                << std::endl;
-
-            ::exit(1);
-        }
-    }
-    else if (!is.size())
-    {
-        // Similar to SafeFatalIOError
-        if (JobInfo::constructed)
-        {
-            FatalIOError
-            (
-                "",                 // functionName
-                "",                 // sourceFileName
-                0,                  // sourceFileLineNumber
-                this->name(),       // ioFileName
-                is.lineNumber()     // ioStartLineNumber
-            )
-                << "'" << keyword << "' had no tokens in stream" << nl << nl
-                << exit(FatalIOError);
-        }
-        else
-        {
-            std::cerr
-                << nl
-                << "--> FOAM FATAL IO ERROR:" << nl
-                << "'" << keyword << "' had no tokens in stream" << nl << nl;
-
-            std::cerr
-                << "file: " << this->name()
-                << " at line " << is.lineNumber() << '.' << nl
-                << std::endl;
-
-            ::exit(1);
-        }
-    }
-}
-
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
@@ -308,6 +225,88 @@ Foam::tokenList Foam::dictionary::tokens() const
 }
 
 
+void Foam::dictionary::checkITstream
+(
+    const ITstream& is,
+    const word& keyword
+) const
+{
+    if (is.nRemainingTokens())
+    {
+        const label remaining = is.nRemainingTokens();
+
+        // Similar to SafeFatalIOError
+        if (JobInfo::constructed)
+        {
+            OSstream& err =
+                FatalIOError
+                (
+                    "",                 // functionName
+                    "",                 // sourceFileName
+                    0,                  // sourceFileLineNumber
+                    this->name(),       // ioFileName
+                    is.lineNumber()     // ioStartLineNumber
+                );
+
+            err << "'" << keyword << "' has "
+                << remaining << " excess tokens in stream" << nl << nl
+                << "    ";
+            is.writeList(err, 0);
+
+            err << exit(FatalIOError);
+        }
+        else
+        {
+            std::cerr
+                << nl
+                << "--> FOAM FATAL IO ERROR:" << nl;
+
+            std::cerr
+                << "'" << keyword << "' has "
+                << remaining << " excess tokens in stream" << nl << nl;
+
+            std::cerr
+                << "file: " << this->name()
+                << " at line " << is.lineNumber() << '.' << nl
+                << std::endl;
+
+            ::exit(1);
+        }
+    }
+    else if (!is.size())
+    {
+        // Similar to SafeFatalIOError
+        if (JobInfo::constructed)
+        {
+            FatalIOError
+            (
+                "",                 // functionName
+                "",                 // sourceFileName
+                0,                  // sourceFileLineNumber
+                this->name(),       // ioFileName
+                is.lineNumber()     // ioStartLineNumber
+            )
+                << "'" << keyword << "' had no tokens in stream" << nl << nl
+                << exit(FatalIOError);
+        }
+        else
+        {
+            std::cerr
+                << nl
+                << "--> FOAM FATAL IO ERROR:" << nl
+                << "'" << keyword << "' had no tokens in stream" << nl << nl;
+
+            std::cerr
+                << "file: " << this->name()
+                << " at line " << is.lineNumber() << '.' << nl
+                << std::endl;
+
+            ::exit(1);
+        }
+    }
+}
+
+
 bool Foam::dictionary::found
 (
     const word& keyword,
diff --git a/src/OpenFOAM/db/dictionary/dictionary.H b/src/OpenFOAM/db/dictionary/dictionary.H
index 700b32a827c..1177f8f4834 100644
--- a/src/OpenFOAM/db/dictionary/dictionary.H
+++ b/src/OpenFOAM/db/dictionary/dictionary.H
@@ -357,12 +357,6 @@ private:
         ) const;
 
 
-        //- Check after reading if the input token stream has unconsumed
-        //- tokens remaining or if there were no tokens in the first place.
-        //  Emits FatalIOError
-        void checkITstream(const word& keyword, const ITstream& is) const;
-
-
 public:
 
     // Declare name of the class and its debug switch
@@ -799,6 +793,11 @@ public:
 
     // Read
 
+        //- Check after reading if the input token stream has unconsumed
+        //- tokens remaining or if there were no tokens in the first place.
+        //  Emits FatalIOError
+        void checkITstream(const ITstream& is, const word& keyword) const;
+
         //- Read dictionary from Istream
         bool read(Istream& is);
 
diff --git a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
index a8656dcb085..432bb10e747 100644
--- a/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
+++ b/src/OpenFOAM/db/dictionary/dictionaryTemplates.C
@@ -93,7 +93,7 @@ bool Foam::dictionary::readCompat
         ITstream& is = finder.ptr()->stream();
         is >> val;
 
-        checkITstream(keyword, is);
+        checkITstream(is, keyword);
 
         return true;
     }
@@ -126,7 +126,7 @@ T Foam::dictionary::lookupOrDefault
         ITstream& is = finder.ptr()->stream();
         is >> val;
 
-        checkITstream(keyword, is);
+        checkITstream(is, keyword);
 
         return val;
     }
@@ -159,7 +159,7 @@ T Foam::dictionary::lookupOrAddDefault
         ITstream& is = finder.ptr()->stream();
         is >> val;
 
-        checkITstream(keyword, is);
+        checkITstream(is, keyword);
 
         return val;
     }
@@ -192,7 +192,7 @@ bool Foam::dictionary::readEntry
         ITstream& is = finder.ptr()->stream();
         is >> val;
 
-        checkITstream(keyword, is);
+        checkITstream(is, keyword);
 
         return true;
     }
@@ -239,7 +239,7 @@ T Foam::dictionary::lookupOrDefaultCompat
         ITstream& is = finder.ptr()->stream();
         is >> val;
 
-        checkITstream(keyword, is);
+        checkITstream(is, keyword);
 
         return val;
     }
diff --git a/src/OpenFOAM/db/dictionary/entry/entry.C b/src/OpenFOAM/db/dictionary/entry/entry.C
index c7f8038092f..c90e0511b0f 100644
--- a/src/OpenFOAM/db/dictionary/entry/entry.C
+++ b/src/OpenFOAM/db/dictionary/entry/entry.C
@@ -47,7 +47,29 @@ void Foam::entry::resetInputMode()
 }
 
 
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::entry::entry(const keyType& keyword)
+:
+    IDLList<entry>::link(),
+    keyword_(keyword)
+{}
+
+
+Foam::entry::entry(const entry& e)
+:
+    IDLList<entry>::link(),
+    keyword_(e.keyword_)
+{}
+
+
+Foam::autoPtr<Foam::entry> Foam::entry::clone() const
+{
+    return clone(dictionary::null);
+}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 void Foam::entry::checkITstream(const ITstream& is) const
 {
@@ -129,28 +151,6 @@ void Foam::entry::checkITstream(const ITstream& is) const
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::entry::entry(const keyType& keyword)
-:
-    IDLList<entry>::link(),
-    keyword_(keyword)
-{}
-
-
-Foam::entry::entry(const entry& e)
-:
-    IDLList<entry>::link(),
-    keyword_(e.keyword_)
-{}
-
-
-Foam::autoPtr<Foam::entry> Foam::entry::clone() const
-{
-    return clone(dictionary::null);
-}
-
-
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
 void Foam::entry::operator=(const entry& e)
diff --git a/src/OpenFOAM/db/dictionary/entry/entry.H b/src/OpenFOAM/db/dictionary/entry/entry.H
index 09d73d051ea..a792dc04d66 100644
--- a/src/OpenFOAM/db/dictionary/entry/entry.H
+++ b/src/OpenFOAM/db/dictionary/entry/entry.H
@@ -107,11 +107,6 @@ private:
         //  \return True if it is a valid keyType.
         static bool getKeyword(keyType& keyword, Istream& is);
 
-        //- Check after reading if the input token stream has unconsumed
-        //- tokens remaining or if there were no tokens in the first place.
-        //  Emits FatalIOError
-        void checkITstream(const ITstream& is) const;
-
 
 public:
 
@@ -245,9 +240,12 @@ public:
         virtual dictionary& dict() = 0;
 
 
-        //- Write
-        virtual void write(Ostream& os) const = 0;
+    // Read
 
+        //- Check after reading if the input token stream has unconsumed
+        //- tokens remaining or if there were no tokens in the first place.
+        //  Emits FatalIOError
+        void checkITstream(const ITstream& is) const;
 
         //- Get a T from the stream,
         //- FatalIOError if the number of tokens is incorrect.
@@ -272,6 +270,11 @@ public:
             checkITstream(is);
         }
 
+    // Write
+
+        //- Write
+        virtual void write(Ostream& os) const = 0;
+
 
     // Member Operators
 
-- 
GitLab