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-------------------------------------------------------------------------------
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::one
29
30Description
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
35SourceFiles
36 oneI.H
37
38SeeAlso
39 Foam::zero
40
41\*---------------------------------------------------------------------------*/
42
43#ifndef one_H
44#define one_H
45
46#include "label.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53// Forward Declarations
54class one;
55class Istream;
56class Ostream;
57
58/*---------------------------------------------------------------------------*\
59 Class one Declaration
60\*---------------------------------------------------------------------------*/
62class one
63{
64public:
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.
106class one::minus
107{
108public:
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.
144class one::null
145:
146 public one
147{
148public:
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)
163static constexpr const one One;
164
165// IOstream Operators
166
167//- Read from Istream consumes no content.
168inline constexpr Istream& operator>>(Istream& is, one&) noexcept
169{
170 return is;
171}
172
173//- Read from Istream consumes no content.
174inline constexpr Istream& operator>>(Istream& is, one::minus&) noexcept
175{
176 return is;
177}
178
179//- Write to Ostream emits no content.
180inline 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// ************************************************************************* //
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 class representing the concept of -1.
Definition: one.H:106
constexpr minus(Istream &) noexcept
Construct from Istream consumes no content.
Definition: one.H:115
minus value_type
Definition: one.H:109
constexpr minus() noexcept
Default construct.
Definition: one.H:112
A Foam::one class with a null output adapter.
Definition: one.H:146
constexpr null() noexcept
Default construct.
Definition: one.H:152
constexpr null(Istream &) noexcept
Construct from Istream consumes no content.
Definition: one.H:155
null value_type
Definition: one.H:149
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
one value_type
Definition: one.H:65
constexpr one(Istream &) noexcept
Construct from Istream consumes no content.
Definition: one.H:75
constexpr one() noexcept
Default construct.
Definition: one.H:72
OBJstream os(runTime.globalPath()/outputName)
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 one One
Global one (1)
Definition: one.H:162
const direction noexcept
Definition: Scalar.H:223