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 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), which can be used to avoid
32  manipulating objects that are known to be \em one at compile-time.
33 
34 SourceFiles
35  oneI.H
36 
37 SeeAlso
38  Foam::zero
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef one_H
43 #define one_H
44 
45 #include "label.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declarations
53 class one;
54 class Istream;
55 class Ostream;
56 
57 /*---------------------------------------------------------------------------*\
58  Class one Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class one
62 {
63 public:
64  typedef one value_type;
65 
66  // Forward declarations
67  class minus;
68  class null;
69 
70  //- Null constructible
71  constexpr one() noexcept {}
72 
73  //- Construct from Istream consumes no content.
74  explicit constexpr one(Istream&) noexcept {}
75 
76 
77  //- Return 1 for label
78  inline constexpr operator label() const noexcept
79  {
80  return 1;
81  }
82 
83  //- Return 1 for float
84  inline constexpr operator float() const noexcept
85  {
86  return 1;
87  }
88 
89  //- Return 1 for double
90  inline constexpr operator double() const noexcept
91  {
92  return 1;
93  }
94 };
95 
96 
97 /*---------------------------------------------------------------------------*\
98  Class one::minus Declaration
99 \*---------------------------------------------------------------------------*/
100 
101 //- A class representing the concept of -1.
102 // Note that this class must never be derived from 'one', since this could
103 // potentially mask its behaviour.
104 class one::minus
105 {
106 public:
107  typedef minus value_type;
108 
109  //- Null constructible
110  constexpr minus() noexcept {}
111 
112  //- Construct from Istream consumes no content.
113  explicit constexpr minus(Istream&) noexcept {}
114 
115 
116  //- Return -1 for label
117  inline constexpr operator label() const noexcept
118  {
119  return -1;
120  }
121 
122  //- Return -1 for float
123  inline constexpr operator float() const noexcept
124  {
125  return -1;
126  }
127 
128  //- Return -1 for double
129  inline constexpr operator double() const noexcept
130  {
131  return -1;
132  }
133 };
134 
135 
136 /*---------------------------------------------------------------------------*\
137  Class one::null Declaration
138 \*---------------------------------------------------------------------------*/
139 
140 //- A one class with a null output adapter.
141 class one::null
142 :
143  public one
144 {
145 public:
146  typedef null value_type;
147 
148  //- Null constructible
149  constexpr null() noexcept {}
150 
151  //- Construct from Istream consumes no content.
152  explicit constexpr null(Istream&) noexcept {}
153 };
154 
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 // IOstream Operators
159 
160 //- Read from Istream consumes no content.
161 inline constexpr Istream& operator>>(Istream& is, one&) noexcept
162 {
163  return is;
164 }
165 
166 //- Read from Istream consumes no content.
167 inline constexpr Istream& operator>>(Istream& is, one::minus&) noexcept
168 {
169  return is;
170 }
171 
172 //- Write to Ostream emits no content.
173 inline constexpr Ostream& operator<<(Ostream& os, const one::null&) noexcept
174 {
175  return os;
176 }
177 
178 
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
180 
181 } // End namespace Foam
182 
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 
185 #include "oneI.H"
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
Foam::one::one
constexpr one(Istream &) noexcept
Construct from Istream consumes no content.
Definition: one.H:73
Foam::one::value_type
one value_type
Definition: one.H:63
Foam::one::null
A one class with a null output adapter.
Definition: one.H:140
Foam::one
A class representing the concept of 1 (one), which can be used to avoid manipulating objects that are...
Definition: one.H:60
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::one::null::value_type
null value_type
Definition: one.H:145
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::one::one
constexpr one() noexcept
Null constructible.
Definition: one.H:70
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::one::minus::value_type
minus value_type
Definition: one.H:106
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
label.H
Foam::one::minus::minus
constexpr minus() noexcept
Null constructible.
Definition: one.H:109
oneI.H
Foam::one::minus::minus
constexpr minus(Istream &) noexcept
Construct from Istream consumes no content.
Definition: one.H:112
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:103
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102