mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: dummy I/O for nullObject, additional null subclass for zero/one
- the zero::null and one::null sub-classes add an additional null output adapter. The function of the nil class (special-purpose class only used for HashSet) is now taken by zero::null.
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -26,6 +26,7 @@ Description
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "hashedWordList.H"
|
#include "hashedWordList.H"
|
||||||
|
#include "nil.H"
|
||||||
#include "HashSet.H"
|
#include "HashSet.H"
|
||||||
#include "Map.H"
|
#include "Map.H"
|
||||||
#include "labelPairHashes.H"
|
#include "labelPairHashes.H"
|
||||||
@ -69,6 +70,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< "tableA keys: "; tableA.writeKeys(Info) << endl;
|
Info<< "tableA keys: "; tableA.writeKeys(Info) << endl;
|
||||||
|
|
||||||
|
Info<< "tableB content: " << tableB << endl;
|
||||||
|
|
||||||
auto keyIterPair = tableA.keys();
|
auto keyIterPair = tableA.keys();
|
||||||
for (const auto& i : keyIterPair)
|
for (const auto& i : keyIterPair)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -61,6 +61,10 @@ int main(int argc, char *argv[])
|
|||||||
nil x;
|
nil x;
|
||||||
cout<<"nil:" << sizeof(x) << nl;
|
cout<<"nil:" << sizeof(x) << nl;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
zero x;
|
||||||
|
cout<<"zero:" << sizeof(x) << nl;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
bool x(0);
|
bool x(0);
|
||||||
cout<<"bool:" << sizeof(x) << nl;
|
cout<<"bool:" << sizeof(x) << nl;
|
||||||
@ -93,6 +97,10 @@ int main(int argc, char *argv[])
|
|||||||
cout<<"double:" << sizeof(double) << nl;
|
cout<<"double:" << sizeof(double) << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
cout<<"string:" << sizeof(Foam::string) << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Info << "---\nEnd\n" << endl;
|
Info << "---\nEnd\n" << endl;
|
||||||
|
|
||||||
|
|||||||
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -22,12 +22,13 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Class
|
Class
|
||||||
Foam::nullObject
|
Foam::NullObject
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Singleton null-object class and instance.
|
Singleton null-object class and instance.
|
||||||
It occupies enough space to reinterpret its content as a class with
|
Its contents occupy just enough space to also be reinterpreted
|
||||||
a null pointer for its content.
|
as another class with a null pointer or zero long for its first
|
||||||
|
member.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
nullObjectI.H
|
nullObjectI.H
|
||||||
@ -43,8 +44,14 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
class Istream;
|
||||||
|
class Ostream;
|
||||||
|
|
||||||
|
class NullObject;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class nullObject Declaration
|
Class NullObject Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class NullObject
|
class NullObject
|
||||||
@ -55,12 +62,12 @@ class NullObject
|
|||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
unsigned long val;
|
unsigned long val;
|
||||||
} null;
|
} content;
|
||||||
|
|
||||||
//- Private constructor
|
//- Private constructor for singleton only
|
||||||
NullObject()
|
NullObject()
|
||||||
:
|
:
|
||||||
null{nullptr}
|
content{nullptr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
@ -70,23 +77,44 @@ class NullObject
|
|||||||
void operator=(const NullObject&) = delete;
|
void operator=(const NullObject&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//- The unique null object
|
|
||||||
|
// Static Data
|
||||||
|
|
||||||
|
//- A unique null object
|
||||||
static const NullObject nullObject;
|
static const NullObject nullObject;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
//- A nullptr pointer content
|
//- A nullptr pointer content
|
||||||
inline const void* pointer() const
|
inline const void* pointer() const
|
||||||
{
|
{
|
||||||
return null.ptr;
|
return content.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- A zero value content
|
//- Zero valued integer content
|
||||||
inline unsigned long value() const
|
inline unsigned long value() const
|
||||||
{
|
{
|
||||||
return null.val;
|
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
|
//- Pointer to the unique nullObject
|
||||||
extern const NullObject* nullObjectPtr;
|
extern const NullObject* nullObjectPtr;
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,9 +25,8 @@ Class
|
|||||||
Foam::one
|
Foam::one
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A class representing the concept of 1 (scalar(1.0)) used to avoid
|
A class representing the concept of 1 (or 1.0) used to avoid unnecessary
|
||||||
unnecessary manipulations for objects which are known to be one at
|
manipulations for objects that are known to be one at compile-time.
|
||||||
compile-time.
|
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
oneI.H
|
oneI.H
|
||||||
@ -44,6 +43,11 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declaration of classes, friend functions and operators
|
||||||
|
class Istream;
|
||||||
|
class Ostream;
|
||||||
|
class one;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class one Declaration
|
Class one Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -51,15 +55,22 @@ namespace Foam
|
|||||||
class one
|
class one
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef one value_type;
|
typedef one value_type;
|
||||||
|
|
||||||
|
// Forward declaration
|
||||||
|
class null;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Null constructible
|
||||||
one()
|
one()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
//- Construct null from Istream. Consumes no content.
|
||||||
|
explicit one(Istream&)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// Member operators
|
// 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
|
} // End namespace Foam
|
||||||
|
|||||||
@ -39,13 +39,11 @@ Description
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef wordRes wordReListMatcher;
|
typedef wordRes wordReListMatcher;
|
||||||
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
24
src/OpenFOAM/primitives/zero/nil.H
Normal file
24
src/OpenFOAM/primitives/zero/nil.H
Normal file
@ -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
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -43,6 +43,12 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
class Istream;
|
||||||
|
class Ostream;
|
||||||
|
|
||||||
|
class zero;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class zero Declaration
|
Class zero Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -50,15 +56,22 @@ namespace Foam
|
|||||||
class zero
|
class zero
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef zero value_type;
|
typedef zero value_type;
|
||||||
|
|
||||||
|
// Forward declaration
|
||||||
|
class null;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null
|
//- Null constructible
|
||||||
zero()
|
zero()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
//- Construct null from Istream. Consumes no content.
|
||||||
|
explicit zero(Istream&)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
@ -85,9 +98,47 @@ public:
|
|||||||
{
|
{
|
||||||
return 0;
|
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
|
// Global zero
|
||||||
static const zero Zero;
|
static const zero Zero;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user