diff --git a/applications/test/HashSet/Test-hashSet.C b/applications/test/HashSet/Test-hashSet.C
index 781c6ceabd..7ead0c4285 100644
--- a/applications/test/HashSet/Test-hashSet.C
+++ b/applications/test/HashSet/Test-hashSet.C
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
- \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
+ \\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -26,6 +26,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "hashedWordList.H"
+#include "nil.H"
#include "HashSet.H"
#include "Map.H"
#include "labelPairHashes.H"
@@ -69,6 +70,8 @@ int main(int argc, char *argv[])
Info<< "tableA keys: "; tableA.writeKeys(Info) << endl;
+ Info<< "tableB content: " << tableB << endl;
+
auto keyIterPair = tableA.keys();
for (const auto& i : keyIterPair)
{
diff --git a/applications/test/sizeof/Test-sizeof.C b/applications/test/sizeof/Test-sizeof.C
index a884d87fde..93358f7af7 100644
--- a/applications/test/sizeof/Test-sizeof.C
+++ b/applications/test/sizeof/Test-sizeof.C
@@ -61,6 +61,10 @@ int main(int argc, char *argv[])
nil x;
cout<<"nil:" << sizeof(x) << nl;
}
+ {
+ zero x;
+ cout<<"zero:" << sizeof(x) << nl;
+ }
{
bool x(0);
cout<<"bool:" << sizeof(x) << nl;
@@ -93,6 +97,10 @@ int main(int argc, char *argv[])
cout<<"double:" << sizeof(double) << nl;
}
+ {
+ cout<<"string:" << sizeof(Foam::string) << nl;
+ }
+
Info << "---\nEnd\n" << endl;
diff --git a/src/OpenFOAM/primitives/nil/nil.H b/src/OpenFOAM/primitives/nil/nil.H
deleted file mode 100644
index 3e5ae948e9..0000000000
--- a/src/OpenFOAM/primitives/nil/nil.H
+++ /dev/null
@@ -1,97 +0,0 @@
-/*---------------------------------------------------------------------------*\
- ========= |
- \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
- \\ / O peration |
- \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
- \\/ M anipulation |
--------------------------------------------------------------------------------
-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 .
-
-Class
- Foam::nil
-
-Description
- A zero-sized class without any storage. Used, for example, in HashSet.
-
-Note
- A zero-sized class actually does still require at least 1 byte storage.
-
-\*---------------------------------------------------------------------------*/
-
-#ifndef nil_H
-#define nil_H
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-namespace Foam
-{
-
-// Forward declaration of classes
-class Istream;
-class Ostream;
-
-// Forward declaration of friend functions and operators
-
-class nil;
-
-Istream& operator>>(Istream&, nil&);
-Ostream& operator<<(Ostream&, const nil&);
-
-
-/*---------------------------------------------------------------------------*\
- Class nil Declaration
-\*---------------------------------------------------------------------------*/
-
-class nil
-{
-
-public:
-
- // Constructors
-
- //- Construct null
- nil()
- {}
-
- //- Construct from Istream
- nil(Istream&)
- {}
-
-
- // IOstream Operators
-
- friend Istream& operator>>(Istream& is, nil&)
- {
- return is;
- }
-
- friend Ostream& operator<<(Ostream& os, const nil&)
- {
- return os;
- }
-};
-
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#endif
-
-// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/nullObject/nullObject.H b/src/OpenFOAM/primitives/nullObject/nullObject.H
index e0ab12029e..d2316fa5d3 100644
--- a/src/OpenFOAM/primitives/nullObject/nullObject.H
+++ b/src/OpenFOAM/primitives/nullObject/nullObject.H
@@ -22,12 +22,13 @@ License
along with OpenFOAM. If not, see .
Class
- Foam::nullObject
+ Foam::NullObject
Description
Singleton null-object class and instance.
- It occupies enough space to reinterpret its content as a class with
- a null pointer for its content.
+ Its contents occupy just enough space to also be reinterpreted
+ as another class with a null pointer or zero long for its first
+ member.
SourceFiles
nullObjectI.H
@@ -43,8 +44,14 @@ SourceFiles
namespace Foam
{
+// Forward declarations
+class Istream;
+class Ostream;
+
+class NullObject;
+
/*---------------------------------------------------------------------------*\
- Class nullObject Declaration
+ Class NullObject Declaration
\*---------------------------------------------------------------------------*/
class NullObject
@@ -55,12 +62,12 @@ class NullObject
{
void* ptr;
unsigned long val;
- } null;
+ } content;
- //- Private constructor
+ //- Private constructor for singleton only
NullObject()
:
- null{nullptr}
+ content{nullptr}
{}
//- Disallow default bitwise copy construct
@@ -70,23 +77,44 @@ class NullObject
void operator=(const NullObject&) = delete;
public:
- //- The unique null object
- static const NullObject nullObject;
- //- A nullptr pointer content
- inline const void* pointer() const
- {
- return null.ptr;
- }
+ // Static Data
- //- A zero value content
- inline unsigned long value() const
- {
- return null.val;
- }
+ //- A unique null object
+ static const NullObject nullObject;
+
+
+ // Member Functions
+
+ //- A nullptr pointer content
+ inline const void* pointer() const
+ {
+ return content.ptr;
+ }
+
+ //- Zero valued integer content
+ inline unsigned long value() const
+ {
+ return content.val;
+ }
};
+// IOstream Operators
+
+//- Read from Istream consumes no content.
+inline Istream& operator>>(Istream& is, NullObject&)
+{
+ return is;
+}
+
+//- Write to Ostream emits no content.
+inline Ostream& operator<<(Ostream& os, const NullObject&)
+{
+ return os;
+}
+
+
//- Pointer to the unique nullObject
extern const NullObject* nullObjectPtr;
diff --git a/src/OpenFOAM/primitives/one/one.H b/src/OpenFOAM/primitives/one/one.H
index a184af000d..350db36483 100644
--- a/src/OpenFOAM/primitives/one/one.H
+++ b/src/OpenFOAM/primitives/one/one.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 |
+ \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -25,9 +25,8 @@ Class
Foam::one
Description
- A class representing the concept of 1 (scalar(1.0)) used to avoid
- unnecessary manipulations for objects which are known to be one at
- compile-time.
+ A class representing the concept of 1 (or 1.0) used to avoid unnecessary
+ manipulations for objects that are known to be one at compile-time.
SourceFiles
oneI.H
@@ -44,6 +43,11 @@ SourceFiles
namespace Foam
{
+// Forward declaration of classes, friend functions and operators
+class Istream;
+class Ostream;
+class one;
+
/*---------------------------------------------------------------------------*\
Class one Declaration
\*---------------------------------------------------------------------------*/
@@ -51,15 +55,22 @@ namespace Foam
class one
{
public:
-
typedef one value_type;
+ // Forward declaration
+ class null;
+
+
// Constructors
- //- Construct null
+ //- Null constructible
one()
{}
+ //- Construct null from Istream. Consumes no content.
+ explicit one(Istream&)
+ {}
+
// Member operators
@@ -83,6 +94,43 @@ public:
};
+/*---------------------------------------------------------------------------*\
+ Class one::null Declaration
+\*---------------------------------------------------------------------------*/
+
+//- A one class with a null output adapter.
+class one::null
+:
+ public one
+{
+public:
+ typedef null value_type;
+
+ //- Null constructible
+ null()
+ {}
+
+ //- Construct null from Istream without consuming any content.
+ explicit null(Istream&)
+ {}
+};
+
+
+// IOstream Operators
+
+//- Read from Istream consumes no content.
+inline Istream& operator>>(Istream& is, one&)
+{
+ return is;
+}
+
+//- Write to Ostream emits no content.
+inline Ostream& operator<<(Ostream& os, const one::null&)
+{
+ return os;
+}
+
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
diff --git a/src/OpenFOAM/primitives/strings/wordRes/wordReListMatcher.H b/src/OpenFOAM/primitives/strings/wordRes/wordReListMatcher.H
index b7b63a5680..d456dfbd36 100644
--- a/src/OpenFOAM/primitives/strings/wordRes/wordReListMatcher.H
+++ b/src/OpenFOAM/primitives/strings/wordRes/wordReListMatcher.H
@@ -39,13 +39,11 @@ Description
namespace Foam
{
-
typedef wordRes wordReListMatcher;
+}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-} // End namespace Foam
-
#endif
// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/zero/nil.H b/src/OpenFOAM/primitives/zero/nil.H
new file mode 100644
index 0000000000..b331b89636
--- /dev/null
+++ b/src/OpenFOAM/primitives/zero/nil.H
@@ -0,0 +1,24 @@
+/*---------------------------------------------------------------------------*\
+Compatibility include
+
+Typedef
+ Foam::nil
+
+Description
+ The older name for Foam::zero::null.
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef nil_H
+#define nil_H
+
+#include "zero.H"
+
+namespace Foam
+{
+ typedef zero::null nil;
+}
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/zero/zero.H b/src/OpenFOAM/primitives/zero/zero.H
index b0156929b6..84cbf2c362 100644
--- a/src/OpenFOAM/primitives/zero/zero.H
+++ b/src/OpenFOAM/primitives/zero/zero.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 |
+ \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -43,6 +43,12 @@ SourceFiles
namespace Foam
{
+// Forward declarations
+class Istream;
+class Ostream;
+
+class zero;
+
/*---------------------------------------------------------------------------*\
Class zero Declaration
\*---------------------------------------------------------------------------*/
@@ -50,15 +56,22 @@ namespace Foam
class zero
{
public:
-
typedef zero value_type;
+ // Forward declaration
+ class null;
+
+
// Constructors
- //- Construct null
+ //- Null constructible
zero()
{}
+ //- Construct null from Istream. Consumes no content.
+ explicit zero(Istream&)
+ {}
+
// Member operators
@@ -85,9 +98,47 @@ public:
{
return 0;
}
+
};
+/*---------------------------------------------------------------------------*\
+ Class zero::null Declaration
+\*---------------------------------------------------------------------------*/
+
+//- A zero class with a null output adapter.
+class zero::null
+:
+ public zero
+{
+public:
+ typedef null value_type;
+
+ //- Null constructible
+ null()
+ {}
+
+ //- Construct null from Istream without consuming any content.
+ explicit null(Istream&)
+ {}
+};
+
+
+// IOstream Operators
+
+//- Read from Istream consumes no content.
+inline Istream& operator>>(Istream& is, zero&)
+{
+ return is;
+}
+
+//- Write to Ostream emits no content.
+inline Ostream& operator<<(Ostream& os, const zero::null&)
+{
+ return os;
+}
+
+
// Global zero
static const zero Zero;