From 28a8e5a61b5efc62bf4602da438dcada22518452 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 20 Feb 2017 10:32:40 +0100
Subject: [PATCH] STYLE: use flatOutput when reporting known file-extensions

---
 src/surfMesh/MeshedSurface/MeshedSurface.C    | 12 ++++----
 src/surfMesh/MeshedSurface/MeshedSurfaceNew.C | 29 ++++++++++---------
 .../MeshedSurfaceProxy/MeshedSurfaceProxy.C   | 12 ++++----
 .../UnsortedMeshedSurface.C                   | 13 +++++----
 .../UnsortedMeshedSurfaceNew.C                | 29 ++++++++++---------
 .../surfaceFormats/surfaceFormatsCore.C       | 15 ++--------
 .../surfaceFormats/surfaceFormatsCore.H       |  5 ++--
 7 files changed, 55 insertions(+), 60 deletions(-)

diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C
index a51428f8b47..0606860e64a 100644
--- a/src/surfMesh/MeshedSurface/MeshedSurface.C
+++ b/src/surfMesh/MeshedSurface/MeshedSurface.C
@@ -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) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -129,10 +129,10 @@ void Foam::MeshedSurface<Face>::write
 
     if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
     {
-        // no direct writer, delegate to proxy if possible
-        wordHashSet supported = ProxyType::writeTypes();
+        // No direct writer, delegate to proxy if possible
+        const wordHashSet& delegate = ProxyType::writeTypes();
 
-        if (supported.found(ext))
+        if (delegate.found(ext))
         {
             MeshedSurfaceProxy<Face>(surf).write(name);
         }
@@ -140,8 +140,8 @@ void Foam::MeshedSurface<Face>::write
         {
             FatalErrorInFunction
                 << "Unknown file extension " << ext << nl << nl
-                << "Valid types are :" << endl
-                << (supported | writeTypes())
+                << "Valid types:" << nl
+                << flatOutput((delegate | writeTypes()).sortedToc()) << nl
                 << exit(FatalError);
         }
     }
diff --git a/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C b/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C
index 41da2d6a1a5..a8280451ee8 100644
--- a/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C
+++ b/src/surfMesh/MeshedSurface/MeshedSurfaceNew.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -25,6 +25,7 @@ License
 
 #include "MeshedSurface.H"
 #include "UnsortedMeshedSurface.H"
+#include "ListOps.H"
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
@@ -42,25 +43,25 @@ Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext)
 
     if (cstrIter == fileExtensionConstructorTablePtr_->end())
     {
-        // no direct reader, delegate if possible
-        wordHashSet supported = FriendType::readTypes();
-        if (supported.found(ext))
+        // No direct reader, delegate to friend if possible
+        const wordHashSet& delegate = FriendType::readTypes();
+
+        if (delegate.found(ext))
         {
-            // create indirectly
+            // Create indirectly
             autoPtr<MeshedSurface<Face>> surf(new MeshedSurface<Face>);
             surf().transfer(FriendType::New(name, ext)());
 
             return surf;
         }
-
-        // nothing left to try, issue error
-        supported += readTypes();
-
-        FatalErrorInFunction
-            << "Unknown file extension " << ext << nl << nl
-            << "Valid types are :" << nl
-            << supported
-            << exit(FatalError);
+        else
+        {
+            FatalErrorInFunction
+                << "Unknown file extension " << ext << nl << nl
+                << "Valid types:" << nl
+                << flatOutput((delegate | readTypes()).sortedToc()) << nl
+                << exit(FatalError);
+        }
     }
 
     return autoPtr<MeshedSurface<Face>>(cstrIter()(name));
diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C
index d7c92fa620f..168155a5971 100644
--- a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C
+++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.C
@@ -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) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -26,9 +26,9 @@ License
 #include "MeshedSurfaceProxy.H"
 
 #include "Time.H"
+#include "ListOps.H"
 #include "surfMesh.H"
 #include "OFstream.H"
-#include "ListOps.H"
 
 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
 
@@ -65,7 +65,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
         InfoInFunction << "Writing to " << name << endl;
     }
 
-    word ext = name.ext();
+    const word ext = name.ext();
 
     typename writefileExtensionMemberFunctionTable::iterator mfIter =
         writefileExtensionMemberFunctionTablePtr_->find(ext);
@@ -74,8 +74,8 @@ void Foam::MeshedSurfaceProxy<Face>::write
     {
         FatalErrorInFunction
             << "Unknown file extension " << ext << nl << nl
-            << "Valid types are :" << endl
-            << writeTypes()
+            << "Valid types:" << nl
+            << flatOutput(writeTypes().sortedToc()) << nl
             << exit(FatalError);
     }
 
@@ -91,7 +91,7 @@ void Foam::MeshedSurfaceProxy<Face>::write
 ) const
 {
     // the surface name to be used
-    word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
+    const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
 
     if (debug)
     {
diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
index e3975c6b8b1..42a7d1d9fe1 100644
--- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
+++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C
@@ -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) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -29,6 +29,7 @@ License
 #include "IFstream.H"
 #include "OFstream.H"
 #include "Time.H"
+#include "ListOps.H"
 #include "polyBoundaryMesh.H"
 #include "polyMesh.H"
 
@@ -117,10 +118,10 @@ void Foam::UnsortedMeshedSurface<Face>::write
 
     if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
     {
-        // no direct writer, delegate to proxy if possible
-        wordHashSet supported = ProxyType::writeTypes();
+        // No direct writer, delegate to proxy if possible
+        const wordHashSet& delegate = ProxyType::writeTypes();
 
-        if (supported.found(ext))
+        if (delegate.found(ext))
         {
             MeshedSurfaceProxy<Face>(surf).write(name);
         }
@@ -128,8 +129,8 @@ void Foam::UnsortedMeshedSurface<Face>::write
         {
             FatalErrorInFunction
                 << "Unknown file extension " << ext << nl << nl
-                << "Valid types are :" << endl
-                << (supported | writeTypes())
+                << "Valid types:" << nl
+                << flatOutput((delegate | writeTypes()).sortedToc()) << nl
                 << exit(FatalError);
         }
     }
diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C
index e61df5c6fc0..f6f1431a835 100644
--- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C
+++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurfaceNew.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -24,6 +24,7 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "UnsortedMeshedSurface.H"
+#include "ListOps.H"
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
@@ -41,11 +42,12 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
 
     if (cstrIter == fileExtensionConstructorTablePtr_->end())
     {
-        // no direct reader, use the parent if possible
-        wordHashSet supported = ParentType::readTypes();
-        if (supported.found(ext))
+        // No direct reader, delegate to parent if possible
+        const wordHashSet& delegate = ParentType::readTypes();
+
+        if (delegate.found(ext))
         {
-            // create indirectly
+            // Create indirectly
             autoPtr<UnsortedMeshedSurface<Face>> surf
             (
                 new UnsortedMeshedSurface<Face>
@@ -54,15 +56,14 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
 
             return surf;
         }
-
-        // nothing left but to issue an error
-        supported += readTypes();
-
-        FatalErrorInFunction
-            << "Unknown file extension " << ext << nl << nl
-            << "Valid types are:" << nl
-            << supported
-            << exit(FatalError);
+        else
+        {
+            FatalErrorInFunction
+                << "Unknown file extension " << ext << nl << nl
+                << "Valid types:" << nl
+                << flatOutput((delegate | readTypes()).sortedToc()) << nl
+                << exit(FatalError);
+        }
     }
 
     return autoPtr<UnsortedMeshedSurface<Face>>(cstrIter()(name));
diff --git a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C
index c098eaf1b91..cff6e37d141 100644
--- a/src/surfMesh/surfaceFormats/surfaceFormatsCore.C
+++ b/src/surfMesh/surfaceFormats/surfaceFormatsCore.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -26,9 +26,9 @@ License
 #include "surfaceFormatsCore.H"
 
 #include "Time.H"
+#include "ListOps.H"
 #include "IFstream.H"
 #include "OFstream.H"
-#include "SortableList.H"
 #include "surfMesh.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@@ -167,18 +167,9 @@ bool Foam::fileFormats::surfaceFormatsCore::checkSupport
     }
     else if (verbose)
     {
-        wordList toc = available.toc();
-        SortableList<word> known(toc.xfer());
-
         Info<<"Unknown file extension for " << functionName
             << " : " << ext << nl
-            <<"Valid types: (";
-        // compact output:
-        forAll(known, i)
-        {
-            Info<<" " << known[i];
-        }
-        Info<<" )" << endl;
+            << "Valid types: " << flatOutput(available.sortedToc()) << endl;
     }
 
     return false;
diff --git a/src/surfMesh/surfaceFormats/surfaceFormatsCore.H b/src/surfMesh/surfaceFormats/surfaceFormatsCore.H
index 73ccc8eff3b..fe35c5b4b05 100644
--- a/src/surfMesh/surfaceFormats/surfaceFormatsCore.H
+++ b/src/surfMesh/surfaceFormats/surfaceFormatsCore.H
@@ -62,8 +62,8 @@ class surfaceFormatsCore
 {
 protected:
 
-        //- Return a list with a single entry,
-        //  the size corresponds to that of the container
+        //- Return a surfZone list with a single entry, the size of which
+        //  corresponds to that of the container
         template<class Container>
         static List<surfZone> oneZone
         (
@@ -89,6 +89,7 @@ public:
 
     // Static Member Functions
 
+        //- Helper function when checking if a file extension is supported.
         static bool checkSupport
         (
             const wordHashSet& available,
-- 
GitLab