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-2023 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 "labelFwd.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 class Istream;
55 class Ostream;
56 
57 /*---------------------------------------------------------------------------*\
58  Class one Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class one
62 {
63 public:
64 
65  //- The value type
66  typedef one value_type;
67 
68  //- Default construct
69  constexpr one() noexcept {}
70 
71  //- Construct from Istream consumes no content.
72  explicit constexpr one(Istream&) noexcept {}
73 
74 
75  //- Return 1 for label
76  constexpr operator label() const noexcept
77  {
78  return 1;
79  }
80 
81  //- Return 1 for float
82  constexpr operator float() const noexcept
83  {
84  return 1;
85  }
86 
87  //- Return 1 for double
88  constexpr operator double() const noexcept
89  {
90  return 1;
91  }
92 
93  //- Component-wise or element-wise access returns one
94  one operator[](const label) const noexcept
95  {
96  return one{};
97  }
98 };
99 
100 
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102 
103 //- Global one (1)
104 static constexpr const one One;
105 
106 // IOstream Operators
107 
108 //- Read from Istream consumes no content.
109 inline constexpr Istream& operator>>(Istream& is, one&) noexcept
110 {
111  return is;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 } // End namespace Foam
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 // Global Operators, Functions
122 #include "oneI.H"
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 #endif
127 
128 // ************************************************************************* //
static constexpr const one One
Global one (1)
Definition: one.H:115
constexpr one() noexcept
Default construct.
Definition: one.H:68
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Typedefs for label/uLabel without requiring label.H.
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition: Scalar.H:258
one operator[](const label) const noexcept
Component-wise or element-wise access returns one.
Definition: one.H:103
one value_type
The value type.
Definition: one.H:63
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:56