bool.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) 2019-2021 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 Primitive
28  bool
29 
30 Description
31  System bool
32 
33 SourceFiles
34  bool.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_primitives_bool_H
39 #define Foam_primitives_bool_H
40 
41 #include "pTraits.H"
42 #include "direction.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // IOstream Operators
50 
51 //- Read bool from stream using Foam::Switch(Istream&)
52 Istream& operator>>(Istream& is, bool& b);
53 
54 //- Write bool to a stream as an label (integer) value
55 Ostream& operator<<(Ostream& os, const bool b);
56 
57 //- Read bool from stream using Foam::Switch(Istream&)
58 bool readBool(Istream& is);
59 
60 
61 /*---------------------------------------------------------------------------*\
62  Specialization pTraits<bool>
63 \*---------------------------------------------------------------------------*/
64 
65 //- Template specialisation for pTraits<bool>
66 template<>
67 class pTraits<bool>
68 {
69  bool p_;
70 
71 public:
72 
73  // Typedefs
74 
75  //- Component type
76  typedef bool cmptType;
77 
78  //- Magnitude type
79  typedef bool magType;
80 
81 
82  // Member Constants
83 
84  //- Dimensionality of space
85  static constexpr direction dim = 3;
86 
87  //- Rank of bool is 0
88  static constexpr direction rank = 0;
89 
90  //- Number of components in bool is 1
91  static constexpr direction nComponents = 1;
92 
93 
94  // Static Data Members
95 
96  static const char* const typeName;
97  static const char* const componentNames[];
98  static const bool zero;
99  static const bool one;
101 
102  // Constructors
103 
104  //- Copy construct from primitive
105  explicit pTraits(bool val) noexcept
106  :
107  p_(val)
108  {}
109 
110  //- Read construct from Istream
111  explicit pTraits(Istream& is);
114  // Member Functions
115 
116  //- Return the value
117  operator bool() const noexcept { return p_; }
118 
119  //- Access the value
120  operator bool&() noexcept { return p_; }
121 };
122 
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 } // End namespace Foam
127 
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129 
130 #endif
131 
132 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
bool magType
Magnitude type.
Definition: bool.H:87
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:86
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
Direction is an 8-bit unsigned integer type used to represent Cartesian directions, components etc.
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition: exprTraits.C:70
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
bool cmptType
Component type.
Definition: bool.H:82
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:62
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