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-2019 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), which can be used to avoid
32  manipulating objects that are known to be \em zero at compile-time.
33 
34 SourceFiles
35  zero.C
36  zeroI.H
37 
38 SeeAlso
39  Foam::one
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef zero_H
44 #define zero_H
45 
46 #include "label.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declarations
54 class zero;
55 class Istream;
56 class Ostream;
57 
58 /*---------------------------------------------------------------------------*\
59  Class zero Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class zero
63 {
64 public:
65  typedef zero value_type;
66 
67  // Forward declarations
68  class null;
69 
70  //- Null constructible
71  constexpr zero() noexcept {}
72 
73  //- Construct from Istream consumes no content.
74  explicit constexpr zero(Istream&) noexcept {}
75 
76 
77  //- Return false (0) for bool
78  inline constexpr operator bool() const noexcept
79  {
80  return false;
81  }
82 
83  //- Return 0 for label
84  inline constexpr operator label() const noexcept
85  {
86  return 0;
87  }
88 
89  //- Return 0 for float
90  inline constexpr operator float() const noexcept
91  {
92  return 0;
93  }
94 
95  //- Return 0 for double
96  inline constexpr operator double() const noexcept
97  {
98  return 0;
99  }
100 };
101 
102 
103 /*---------------------------------------------------------------------------*\
104  Class zero::null Declaration
105 \*---------------------------------------------------------------------------*/
106 
107 //- A zero class with a null output adapter.
108 class zero::null
109 :
110  public zero
111 {
112 public:
113  typedef null value_type;
114 
115  //- A static zero::null for dereferencing as a dummy element
116  static null dummy;
117 
118  //- Null constructible
119  constexpr null() noexcept {}
120 
121  //- Construct from Istream consumes no content.
122  explicit constexpr null(Istream&) noexcept {}
123 };
124 
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 //- Global zero
129 static constexpr const zero Zero;
130 
131 // IOstream Operators
132 
133 //- Read from Istream consumes no content.
134 inline constexpr Istream& operator>>(Istream& is, zero&) noexcept
135 {
136  return is;
137 }
138 
139 //- Write to Ostream emits no content.
140 inline constexpr Ostream& operator<<(Ostream& os, const zero::null&) noexcept
141 {
142  return os;
143 }
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 } // End namespace Foam
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #include "zeroI.H"
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 #endif
157 
158 // ************************************************************************* //
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::zero::zero
constexpr zero() noexcept
Null constructible.
Definition: zero.H:70
Foam::zero::value_type
zero value_type
Definition: zero.H:64
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:112
Foam::zero::zero
constexpr zero(Istream &) noexcept
Construct from Istream consumes no content.
Definition: zero.H:73
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::zero::null
A zero class with a null output adapter.
Definition: zero.H:107
label.H
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:115
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::zero
A class representing the concept of 0 (zero), which can be used to avoid manipulating objects that ar...
Definition: zero.H:61