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  // Member constants
89 
90  //- Dimensionality of space
91  static const direction dim = 3;
92 
93  //- Rank of bool is 0
94  static const direction rank = 0;
95 
96  //- Number of components in bool is 1
97  static const direction nComponents = 1;
98 
99 
100  // Static Data Members
101 
102  static const char* const typeName;
103  static const char* const componentNames[];
104  static const bool zero;
105  static const bool one;
106 
107 
108  // Constructors
109 
110  //- Construct from primitive
111  explicit pTraits(const bool&);
112 
113  //- Construct from Istream
114  pTraits(Istream&);
115 
116 
117  // Member Functions
118 
119  //- Access to the bool value
120  operator bool() const
121  {
122  return p_;
123  }
124 
125  //- Access to the bool value
126  operator bool&()
127  {
128  return p_;
129  }
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace Foam
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 #endif
140 
141 // ************************************************************************* //
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:105
static const bool zero
Definition: bool.H:104
bool cmptType
Component type.
Definition: bool.H:86
static const char *const typeName
Definition: bool.H:102
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 &, directionInfo &)
Ostream & operator<<(Ostream &, const ensightPart &)
uint8_t direction
Definition: direction.H:45