zero.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::zero
29
30Description
31 A class representing the concept of 0 (zero) that can be used to avoid
32 manipulating objects known to be \em zero at compile-time.
33 It is also used for tagged dispatch.
34
35SourceFiles
36 zero.C
37 zeroI.H
38
39SeeAlso
40 Foam::one
41
42\*---------------------------------------------------------------------------*/
43
44#ifndef zero_H
45#define zero_H
46
47#include "labelFwd.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55class zero;
56class Istream;
57class Ostream;
58
59/*---------------------------------------------------------------------------*\
60 Class zero Declaration
61\*---------------------------------------------------------------------------*/
63class zero
64{
65public:
67 typedef zero value_type;
68
69 // Forward Declarations
70 class null;
71
72 //- Default construct
73 constexpr zero() noexcept {}
74
75 //- Construct from Istream consumes no content.
76 explicit constexpr zero(Istream&) noexcept {}
77
78
79 //- Return false (0) for bool
80 constexpr operator bool() const noexcept
81 {
82 return false;
83 }
84
85 //- Return 0 for label
86 constexpr operator label() const noexcept
87 {
88 return 0;
89 }
90
91 //- Return 0 for float
92 constexpr operator float() const noexcept
93 {
94 return 0;
95 }
96
97 //- Return 0 for double
98 constexpr operator double() const noexcept
99 {
100 return 0;
101 }
102};
103
104
105/*---------------------------------------------------------------------------*\
106 Class zero::null Declaration
107\*---------------------------------------------------------------------------*/
108
109//- A zero class with a null output adapter.
110class zero::null
111:
112 public zero
113{
114public:
116 typedef null value_type;
117
118 //- A static zero::null for dereferencing as a dummy element
119 static null dummy;
120
121 //- Null constructible
122 constexpr null() noexcept {}
123
124 //- Construct from Istream consumes no content.
125 explicit constexpr null(Istream&) noexcept {}
126};
127
128
129// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130
131//- Global zero (0)
132static constexpr const zero Zero;
133
134// IOstream Operators
135
136//- Read from Istream consumes no content
137inline constexpr Istream& operator>>(Istream& is, zero&) noexcept
138{
139 return is;
140}
141
142//- Write to Ostream emits no content
143inline constexpr Ostream& operator<<(Ostream& os, const zero::null&) noexcept
144{
145 return os;
146}
147
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151} // End namespace Foam
152
153// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154
155// Global Operators, Functions
156
157#include "zeroI.H"
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
161#endif
162
163// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A zero class with a null output adapter.
Definition: zero.H:112
static null dummy
A static zero::null for dereferencing as a dummy element.
Definition: zero.H:118
constexpr null() noexcept
Null constructible.
Definition: zero.H:121
constexpr null(Istream &) noexcept
Construct from Istream consumes no content.
Definition: zero.H:124
null value_type
Definition: zero.H:115
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
zero value_type
Definition: zero.H:66
constexpr zero(Istream &) noexcept
Construct from Istream consumes no content.
Definition: zero.H:75
constexpr zero() noexcept
Default construct.
Definition: zero.H:72
bool
Definition: EEqn.H:20
OBJstream os(runTime.globalPath()/outputName)
Typedefs for label/uLabel without requiring label.H.
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
const direction noexcept
Definition: Scalar.H:223