From 1d7d5b2d2617e2945d857d30a4e75c45dfbb0b78 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 29 May 2020 15:56:08 +0200
Subject: [PATCH] ENH: provide lightweight labelFwd, scalarFwd headers

- centralizes sizing information and typedefs
  without dependencies beyond <cstdint>

COMP: ensure label typedef exists for nullObject.H
---
 .../Scalar/doubleScalar/doubleScalar.H        |  7 +-
 .../Scalar/floatScalar/floatScalar.H          |  7 +-
 .../primitives/Scalar/scalar/scalar.H         | 18 ++---
 .../primitives/Scalar/scalar/scalarFwd.H      | 76 +++++++++++++++++++
 src/OpenFOAM/primitives/ints/label/label.H    |  8 +-
 src/OpenFOAM/primitives/ints/label/labelFwd.H | 64 ++++++++++++++++
 src/OpenFOAM/primitives/ints/uLabel/uLabel.H  | 10 +--
 .../primitives/nullObject/nullObject.H        |  4 +-
 src/OpenFOAM/primitives/zero/zero.H           |  7 +-
 9 files changed, 166 insertions(+), 35 deletions(-)
 create mode 100644 src/OpenFOAM/primitives/Scalar/scalar/scalarFwd.H
 create mode 100644 src/OpenFOAM/primitives/ints/label/labelFwd.H

diff --git a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H
index b3f328fe230..b3fcf119fe7 100644
--- a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H
+++ b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2015 OpenFOAM Foundation
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -38,19 +38,20 @@ SourceFiles
 #ifndef doubleScalar_H
 #define doubleScalar_H
 
+#include "scalarFwd.H"
 #include "doubleFloat.H"
 #include "direction.H"
 #include "word.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+// Typedef (doubleScalar) in scalarFwd.H
+
 namespace Foam
 {
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-typedef double doubleScalar;
-
 // Largest and smallest scalar values allowed in certain parts of the code.
 // See std::numeric_limits max(), min(), epsilon()
 constexpr doubleScalar doubleScalarGREAT = 1.0e+15;
diff --git a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H
index 109dda9980c..d9dc53db515 100644
--- a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H
+++ b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2015 OpenFOAM Foundation
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -38,19 +38,20 @@ SourceFiles
 #ifndef floatScalar_H
 #define floatScalar_H
 
+#include "scalarFwd.H"
 #include "doubleFloat.H"
 #include "direction.H"
 #include "word.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+// Typedef (floatScalar) in scalarFwd.H
+
 namespace Foam
 {
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-typedef float floatScalar;
-
 // Largest and smallest scalar values allowed in certain parts of the code.
 // See std::numeric_limits max(), min(), epsilon()
 constexpr floatScalar floatScalarGREAT = 1.0e+6;
diff --git a/src/OpenFOAM/primitives/Scalar/scalar/scalar.H b/src/OpenFOAM/primitives/Scalar/scalar/scalar.H
index d87bfca1c8b..74286eb840b 100644
--- a/src/OpenFOAM/primitives/Scalar/scalar/scalar.H
+++ b/src/OpenFOAM/primitives/Scalar/scalar/scalar.H
@@ -44,19 +44,14 @@ SourceFiles
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+// Typedefs (floatScalar, doubleScalar, scalar, solveScalar) in scalarFwd.H
+
 #if defined(WM_SP) || defined(WM_SPDP)
 
-// Define scalar as a float
+// With scalar == (float), solveScalar == (float | double)
 
 namespace Foam
 {
-    typedef floatScalar scalar;
-    #if defined(WM_SPDP)
-    typedef doubleScalar solveScalar;
-    #else
-    typedef floatScalar solveScalar;
-    #endif
-
     constexpr scalar GREAT = floatScalarGREAT;
     constexpr scalar VGREAT = floatScalarVGREAT;
     constexpr scalar ROOTVGREAT = floatScalarROOTVGREAT;
@@ -101,13 +96,10 @@ namespace Foam
 
 #elif defined(WM_DP)
 
-// Define scalar as a double
+// With scalar == (double), solveScalar == (double)
 
 namespace Foam
 {
-    typedef doubleScalar scalar;
-    typedef doubleScalar solveScalar;
-
     constexpr scalar GREAT = doubleScalarGREAT;
     constexpr scalar VGREAT = doubleScalarVGREAT;
     constexpr scalar ROOTVGREAT = doubleScalarROOTVGREAT;
@@ -151,6 +143,8 @@ namespace Foam
     void readRawScalar(Istream& is, scalar* data, size_t nElem = 1);
 }
 
+#else
+//    #error "PRECISION must be set to WM_SP, WM_SPDP or WM_DP"
 #endif
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/primitives/Scalar/scalar/scalarFwd.H b/src/OpenFOAM/primitives/Scalar/scalar/scalarFwd.H
new file mode 100644
index 00000000000..d692b623910
--- /dev/null
+++ b/src/OpenFOAM/primitives/Scalar/scalar/scalarFwd.H
@@ -0,0 +1,76 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | www.openfoam.com
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+    Copyright (C) 2020 OpenCFD Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Description
+    Typedefs for float/double/scalar without requiring scalar.H
+
+    The definition of scalar as a floating-point number depends
+    on pre-processor macros WM_SP, WM_SPDP or WM_DP being defined.
+
+SourceFiles
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef scalarFwd_H
+#define scalarFwd_H
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+//- A typedef for float
+typedef float floatScalar;
+
+//- A typedef for double
+typedef double doubleScalar;
+
+
+#if defined(WM_SP)
+
+typedef floatScalar scalar;
+typedef floatScalar solveScalar;
+
+#elif defined(WM_SPDP)
+
+typedef floatScalar scalar;
+typedef doubleScalar solveScalar;
+
+#elif defined(WM_DP)
+
+typedef doubleScalar scalar;
+typedef doubleScalar solveScalar;
+
+#else
+//    #error "PRECISION must be set to WM_SP, WM_SPDP or WM_DP"
+#endif
+
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/ints/label/label.H b/src/OpenFOAM/primitives/ints/label/label.H
index 36c5906fc69..064de2bf12a 100644
--- a/src/OpenFOAM/primitives/ints/label/label.H
+++ b/src/OpenFOAM/primitives/ints/label/label.H
@@ -40,6 +40,7 @@ Description
 #define label_H
 
 #include "int.H"
+#include "labelFwd.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -47,10 +48,7 @@ Description
 #define INT_ADD_DEF_SIZE(x,s,y) INT_ADD_SIZE(x,s,y)
 #define INT_SIZE(x,y) INT_ADD_DEF_SIZE(x,WM_LABEL_SIZE,y)
 
-#if WM_LABEL_SIZE != 32 && WM_LABEL_SIZE != 64
-    #error "label.H: WM_LABEL_SIZE must be set to either 32 or 64"
-#endif
-
+// Size checks and typedefs (label) in labelFwd.H
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -59,8 +57,6 @@ namespace Foam
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-typedef INT_SIZE(int, _t) label;
-
 constexpr label labelMin = INT_SIZE(INT, _MIN);
 constexpr label labelMax = INT_SIZE(INT, _MAX);
 
diff --git a/src/OpenFOAM/primitives/ints/label/labelFwd.H b/src/OpenFOAM/primitives/ints/label/labelFwd.H
new file mode 100644
index 00000000000..abe2752896b
--- /dev/null
+++ b/src/OpenFOAM/primitives/ints/label/labelFwd.H
@@ -0,0 +1,64 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | www.openfoam.com
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+    Copyright (C) 2020 OpenCFD Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software: you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
+
+Description
+    Typedefs for label/uLabel without requiring label.H
+
+    The definitions of label/uLabel as an integral value depend on the
+    pre-processor macro WM_LABEL_SIZE.
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef labelFwd_H
+#define labelFwd_H
+
+#include <cstdint>
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+#if WM_LABEL_SIZE == 32
+
+typedef int32_t label;
+typedef uint32_t uLabel;
+
+#elif WM_LABEL_SIZE == 64
+
+typedef int64_t label;
+typedef uint64_t uLabel;
+
+#else
+    #error "WM_LABEL_SIZE must be set to either 32 or 64"
+#endif
+
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/ints/uLabel/uLabel.H b/src/OpenFOAM/primitives/ints/uLabel/uLabel.H
index 54158783fb5..96efd2a2e8b 100644
--- a/src/OpenFOAM/primitives/ints/uLabel/uLabel.H
+++ b/src/OpenFOAM/primitives/ints/uLabel/uLabel.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2017 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -40,6 +40,7 @@ Description
 #define uLabel_H
 
 #include "uint.H"
+#include "labelFwd.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -47,10 +48,7 @@ Description
 #define UINT_ADD_DEF_SIZE(x,s,y) UINT_ADD_SIZE(x,s,y)
 #define UINT_SIZE(x,y) UINT_ADD_DEF_SIZE(x,WM_LABEL_SIZE,y)
 
-#if WM_LABEL_SIZE != 32 && WM_LABEL_SIZE != 64
-    #error "uLabel.H: WM_LABEL_SIZE must be set to either 32 or 64"
-#endif
-
+// Size checks and typedefs (uLabel) in labelFwd.H
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -59,8 +57,6 @@ namespace Foam
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-typedef UINT_SIZE(uint, _t) uLabel;
-
 constexpr uLabel uLabelMax = UINT_SIZE(UINT, _MAX);
 
 //- Read uLabel from stream.
diff --git a/src/OpenFOAM/primitives/nullObject/nullObject.H b/src/OpenFOAM/primitives/nullObject/nullObject.H
index 09788dd96ca..d7ca3e006e4 100644
--- a/src/OpenFOAM/primitives/nullObject/nullObject.H
+++ b/src/OpenFOAM/primitives/nullObject/nullObject.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2014 OpenFOAM Foundation
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -42,6 +42,8 @@ SourceFiles
 #ifndef nullObject_H
 #define nullObject_H
 
+#include "labelFwd.H"
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
diff --git a/src/OpenFOAM/primitives/zero/zero.H b/src/OpenFOAM/primitives/zero/zero.H
index 8e64dc00ad1..21a802a1e08 100644
--- a/src/OpenFOAM/primitives/zero/zero.H
+++ b/src/OpenFOAM/primitives/zero/zero.H
@@ -44,7 +44,7 @@ SeeAlso
 #ifndef zero_H
 #define zero_H
 
-#include "label.H"
+#include "labelFwd.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -133,13 +133,13 @@ static constexpr const zero Zero;
 
 // IOstream Operators
 
-//- Read from Istream consumes no content.
+//- Read from Istream consumes no content
 inline constexpr Istream& operator>>(Istream& is, zero&) noexcept
 {
     return is;
 }
 
-//- Write to Ostream emits no content.
+//- Write to Ostream emits no content
 inline constexpr Ostream& operator<<(Ostream& os, const zero::null&) noexcept
 {
     return os;
@@ -153,6 +153,7 @@ inline constexpr Ostream& operator<<(Ostream& os, const zero::null&) noexcept
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 // Global Operators, Functions
+
 #include "zeroI.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-- 
GitLab