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 one_H
44 #define 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 
98 
99 /*---------------------------------------------------------------------------*\
100  Class one::minus Declaration
101 \*---------------------------------------------------------------------------*/
102 
103 //- A class representing the concept of -1.
104 // \note this class must never be derived from Foam::one, since this could
105 // potentially mask its behaviour.
106 class one::minus
107 {
108 public:
109 
110  typedef minus value_type;
111 
112  //- Default construct
113  constexpr minus() noexcept {}
114 
115  //- Construct from Istream consumes no content.
116  explicit constexpr minus(Istream&) noexcept {}
117 
118 
119  //- Return -1 for label
120  constexpr operator label() const noexcept
121  {
122  return -1;
123  }
124 
125  //- Return -1 for float
126  constexpr operator float() const noexcept
127  {
128  return -1;
129  }
130 
131  //- Return -1 for double
132  constexpr operator double() const noexcept
133  {
134  return -1;
135  }
136 };
137 
138 
139 /*---------------------------------------------------------------------------*\
140  Class one::null Declaration
141 \*---------------------------------------------------------------------------*/
142 
143 //- A Foam::one class with a null output adapter.
144 class one::null
145 :
146  public one
147 {
148 public:
149 
150  typedef null value_type;
151 
152  //- Default construct
153  constexpr null() noexcept {}
154 
155  //- Construct from Istream consumes no content.
156  explicit constexpr null(Istream&) noexcept {}
157 };
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 //- Global one (1)
163 static constexpr const one One;
164 
165 // IOstream Operators
166 
167 //- Read from Istream consumes no content.
168 inline constexpr Istream& operator>>(Istream& is, one&) noexcept
169 {
170  return is;
171 }
172 
173 //- Read from Istream consumes no content.
174 inline constexpr Istream& operator>>(Istream& is, one::minus&) noexcept
175 {
176  return is;
177 }
178 
179 //- Write to Ostream emits no content.
180 inline constexpr Ostream& operator<<(Ostream& os, const one::null&) noexcept
181 {
182  return os;
183 }
184 
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 } // End namespace Foam
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 // Global Operators, Functions
193 #include "oneI.H"
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 #endif
198 
199 // ************************************************************************* //
Foam::one::one
constexpr one(Istream &) noexcept
Construct from Istream consumes no content.
Definition: one.H:75
Foam::one::value_type
one value_type
Definition: one.H:65
Foam::one::null
A Foam::one class with a null output adapter.
Definition: one.H:143
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::one::null::value_type
null value_type
Definition: one.H:149
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::one::one
constexpr one() noexcept
Default construct.
Definition: one.H:72
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::One
static constexpr const one One
Global one (1)
Definition: one.H:162
os
OBJstream os(runTime.globalPath()/outputName)
Foam::one::minus::value_type
minus value_type
Definition: one.H:109
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
label.H
Foam::one::minus::minus
constexpr minus() noexcept
Default construct.
Definition: one.H:112
oneI.H
Foam::one::minus::minus
constexpr minus(Istream &) noexcept
Construct from Istream consumes no content.
Definition: one.H:115
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::one::minus
A class representing the concept of -1.
Definition: one.H:105