bool.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Primitive
25  bool
26 
27 Description
28  System bool
29 
30 SourceFiles
31  boolIO.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef bool_H
36 #define bool_H
37 
38 #include "word.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 class Istream;
46 class Ostream;
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 //- Return a word representation of a bool
51 word name(const bool);
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 Istream& operator>>(Istream&, bool&);
56 Ostream& operator<<(Ostream&, const bool);
57 
58 bool readBool(Istream&);
59 
60 inline void writeEntry(Ostream& os, const bool value)
61 {
62  os << value;
63 }
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 } // End namespace Foam
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 #include "pTraits.H"
72 #include "direction.H"
73 
74 namespace Foam
75 {
76 
77 // template specialisation for pTraits<bool>
78 template<>
79 class pTraits<bool>
80 {
81  bool p_;
82 
83 public:
84 
85  //- Component type
86  typedef bool cmptType;
87 
88 
89  // Member constants
90 
91  //- Dimensionality of space
92  static const direction dim = 3;
93 
94  //- Rank of bool is 0
95  static const direction rank = 0;
96 
97  //- Number of components in bool is 1
98  static const direction nComponents = 1;
99 
100 
101  // Static Data Members
102 
103  static const char* const typeName;
104  static const char* const componentNames[];
105  static const bool zero;
106  static const bool one;
107 
108 
109  // Constructors
110 
111  //- Construct from primitive
112  explicit pTraits(const bool&);
113 
114  //- Construct from Istream
115  pTraits(Istream&);
116 
117 
118  // Member Functions
119 
120  //- Access to the bool value
121  operator bool() const
122  {
123  return p_;
124  }
125 
126  //- Access to the bool value
127  operator bool&()
128  {
129  return p_;
130  }
131 };
132 
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 } // End namespace Foam
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 #endif
141 
142 // ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
static const bool one
Definition: bool.H:106
static const bool zero
Definition: bool.H:105
bool cmptType
Component type.
Definition: bool.H:86
static const char *const typeName
Definition: bool.H:103
Traits class for primitives.
Definition: pTraits.H:53
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:60
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc.
Namespace for OpenFOAM.
bool readBool(Istream &)
Definition: boolIO.C:66
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
uint8_t direction
Definition: direction.H:45