boolVectorI.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) 2020-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 :
32  FixedList<bool, 3>(false)
33 {}
34 
35 
36 inline Foam::boolVector::boolVector(const bool val)
37 :
38  FixedList<bool, 3>(val)
39 {}
40 
41 
43 (
44  const bool vx,
45  const bool vy,
46  const bool vz
47 )
48 {
49  x() = vx;
50  y() = vy;
51  z() = vz;
52 }
53 
54 
56 :
57  FixedList<bool, 3>(is)
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
63 inline bool Foam::boolVector::all() const noexcept
64 {
65  return (x() && y() && z());
66 }
67 
68 
69 inline bool Foam::boolVector::any() const noexcept
70 {
71  return (x() || y() || z());
72 }
73 
74 
75 inline bool Foam::boolVector::none() const noexcept
76 {
77  return !any();
78 }
79 
80 
81 inline unsigned int Foam::boolVector::count(const bool on) const
82 {
83  unsigned int total = 0;
84 
85  for (const bool val : *this)
86  {
87  if (val) ++total;
88  }
89 
90  if (!on)
91  {
92  // Return the number of bits that are OFF.
93  return (3u - total);
94  }
95 
96  return total;
97 }
98 
99 
100 inline void Foam::boolVector::flip()
101 {
102  x() = !x();
103  y() = !y();
104  z() = !z();
105 }
106 
107 
108 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
109 
110 inline void Foam::boolVector::operator=(const bool value)
111 {
113 }
114 
115 
116 // ************************************************************************* //
bool none() const noexcept
True if no components are set.
Definition: boolVectorI.H:68
boolVector & operator=(const boolVector &)=default
Copy assignment.
bool any(const UList< bool > &bools)
True if any entries are &#39;true&#39;.
Definition: BitOps.H:93
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:107
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
scalar y
boolVector()
Default construct, zero-initialized (ie, false)
Definition: boolVectorI.H:23
void operator=(const UList< T > &list)
Assignment to UList operator. Takes linear time.
Definition: FixedListI.H:423
const direction noexcept
Definition: Scalar.H:258
bool all() const noexcept
True if all components are set.
Definition: boolVectorI.H:56
void flip()
Invert all values.
Definition: boolVectorI.H:93
bool any() const noexcept
True if any components are set.
Definition: boolVectorI.H:62
unsigned int count(const bool on=true) const
Count number of items set.
Definition: boolVectorI.H:74