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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::zero
29 
30 Description
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 
35 SourceFiles
36  zero.C
37  zeroI.H
38 
39 SeeAlso
40  Foam::one
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef zero_H
45 #define zero_H
46 
47 #include "labelFwd.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class zero;
56 class Istream;
57 class Ostream;
58 
59 /*---------------------------------------------------------------------------*\
60  Class zero Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class zero
64 {
65 public:
66 
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.
110 class zero::null
111 :
112  public zero
113 {
114 public:
115 
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)
132 static constexpr const zero Zero;
133 
134 // IOstream Operators
135 
136 //- Read from Istream consumes no content
137 inline constexpr Istream& operator>>(Istream& is, zero&) noexcept
138 {
139  return is;
140 }
141 
142 //- Write to Ostream emits no content
143 inline 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 // ************************************************************************* //
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::zero::zero
constexpr zero() noexcept
Default construct.
Definition: zero.H:72
Foam::zero::value_type
zero value_type
Definition: zero.H:66
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::zero::null::value_type
null value_type
Definition: zero.H:115
labelFwd.H
Typedefs for label/uLabel without requiring label.H.
os
OBJstream os(runTime.globalPath()/outputName)
Foam::zero::zero
constexpr zero(Istream &) noexcept
Construct from Istream consumes no content.
Definition: zero.H:75
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::zero::null
A zero class with a null output adapter.
Definition: zero.H:109
zeroI.H
bool
bool
Definition: EEqn.H:20
Foam::zero::null::dummy
static null dummy
A static zero::null for dereferencing as a dummy element.
Definition: zero.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62