one.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::one
29 
30 Description
31  A class representing the concept of 1 (one) that can be used to avoid
32  manipulating objects known to be \em one at compile-time.
33  It is also used for tagged dispatch.
34 
35 SourceFiles
36  oneI.H
37 
38 SeeAlso
39  Foam::zero
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Foam_one_H
44 #define Foam_one_H
45 
46 #include "label.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 class one;
55 class Istream;
56 class Ostream;
57 
58 /*---------------------------------------------------------------------------*\
59  Class one Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class one
63 {
64 public:
65 
66  typedef one value_type;
67 
68  // Forward Declarations
69  class minus;
70  class null;
71 
72  //- Default construct
73  constexpr one() noexcept {}
74 
75  //- Construct from Istream consumes no content.
76  explicit constexpr one(Istream&) noexcept {}
77 
78 
79  //- Return 1 for label
80  constexpr operator label() const noexcept
81  {
82  return 1;
83  }
84 
85  //- Return 1 for float
86  constexpr operator float() const noexcept
87  {
88  return 1;
89  }
90 
91  //- Return 1 for double
92  constexpr operator double() const noexcept
93  {
94  return 1;
95  }
96 
97  //- Component-wise or element-wise access returns one
98  one operator[](const label) const noexcept
99  {
100  return one{};
101  }
102 };
103 
104 
105 /*---------------------------------------------------------------------------*\
106  Class one::minus Declaration
107 \*---------------------------------------------------------------------------*/
108 
109 //- A class representing the concept of -1.
110 // \note this class must never be derived from Foam::one, since this could
111 // potentially mask its behaviour.
112 class one::minus
113 {
114 public:
115 
116  typedef minus value_type;
117 
118  //- Default construct
119  constexpr minus() noexcept {}
120 
121  //- Construct from Istream consumes no content.
122  explicit constexpr minus(Istream&) noexcept {}
123 
124 
125  //- Return -1 for label
126  constexpr operator label() const noexcept
127  {
128  return -1;
129  }
130 
131  //- Return -1 for float
132  constexpr operator float() const noexcept
133  {
134  return -1;
135  }
137  //- Return -1 for double
138  constexpr operator double() const noexcept
139  {
140  return -1;
141  }
143  //- Component-wise or element-wise access returns minus one
144  one::minus operator[](const label) const noexcept
145  {
146  return one::minus{};
147  }
148 };
149 
151 /*---------------------------------------------------------------------------*\
152  Class one::null Declaration
153 \*---------------------------------------------------------------------------*/
154 
155 //- A Foam::one class with a null output adapter.
156 class one::null
157 :
158  public one
159 {
160 public:
161 
162  typedef null value_type;
163 
164  //- Default construct
165  constexpr null() noexcept {}
167  //- Construct from Istream consumes no content.
168  explicit constexpr null(Istream&) noexcept {}
169 };
170 
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 //- Global one (1)
175 static constexpr const one One;
176 
177 // IOstream Operators
178 
179 //- Read from Istream consumes no content.
180 inline constexpr Istream& operator>>(Istream& is, one&) noexcept
181 {
182  return is;
183 }
184 
185 //- Read from Istream consumes no content.
186 inline constexpr Istream& operator>>(Istream& is, one::minus&) noexcept
187 {
188  return is;
189 }
190 
191 //- Write to Ostream emits no content.
192 inline constexpr Ostream& operator<<(Ostream& os, const one::null&) noexcept
193 {
194  return os;
195 }
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace Foam
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 // Global Operators, Functions
205 #include "oneI.H"
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #endif
210 
211 // ************************************************************************* //
static constexpr const one One
Global one (1)
Definition: one.H:205
constexpr one() noexcept
Default construct.
Definition: one.H:70
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Istream & operator>>(Istream &, directionInfo &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
A class representing the concept of -1.
Definition: one.H:122
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
minus value_type
Definition: one.H:126
null value_type
Definition: one.H:186
constexpr minus() noexcept
Default construct.
Definition: one.H:131
one operator[](const label) const noexcept
Component-wise or element-wise access returns one.
Definition: one.H:105
constexpr null() noexcept
Default construct.
Definition: one.H:191
one value_type
Definition: one.H:61
one::minus operator[](const label) const noexcept
Component-wise or element-wise access returns minus one.
Definition: one.H:166
Namespace for OpenFOAM.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:57
A Foam::one class with a null output adapter.
Definition: one.H:180