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 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 :
50 {
51  x() = vx;
52  y() = vy;
53  z() = vz;
54 }
55 
56 
58 :
59  FixedList<bool, 3>(is)
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
65 inline bool Foam::boolVector::all() const
66 {
67  for (const bool val : *this)
68  {
69  if (!val) return false;
70  }
71  return true;
72 }
73 
74 
75 inline bool Foam::boolVector::any() const
76 {
77  for (const bool val : *this)
78  {
79  if (val) return true;
80  }
81  return false;
82 }
83 
84 
85 inline bool Foam::boolVector::none() const
86 {
87  return !any();
88 }
89 
90 
91 inline unsigned int Foam::boolVector::count(const bool on) const
92 {
93  unsigned int total = 0;
94 
95  for (const bool val : *this)
96  {
97  if (val) ++total;
98  }
99 
100  if (!on)
101  {
102  // Return the number of bits that are OFF.
103  return (3u - total);
104  }
105 
106  return total;
107 }
108 
109 
110 inline bool Foam::boolVector::x() const { return operator[](boolVector::X); }
111 inline bool Foam::boolVector::y() const { return operator[](boolVector::Y); }
112 inline bool Foam::boolVector::z() const { return operator[](boolVector::Z); }
113 
114 inline bool& Foam::boolVector::x() { return operator[](boolVector::X); }
115 inline bool& Foam::boolVector::y() { return operator[](boolVector::Y); }
116 inline bool& Foam::boolVector::z() { return operator[](boolVector::Z); }
117 
118 
120 {
121  for (bool& val : *this)
122  {
123  val = !val;
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
129 
130 inline void Foam::boolVector::operator=(const bool value)
131 {
133 }
134 
135 
136 // ************************************************************************* //
Foam::boolVector::all
bool all() const
True if all components are set.
Definition: boolVectorI.H:65
Foam::boolVector::operator=
boolVector & operator=(const boolVector &)=default
Copy assignment.
Foam::boolVector::none
bool none() const
True if no components are set.
Definition: boolVectorI.H:85
Foam::boolVector::Z
Definition: boolVector.H:68
Foam::FixedList::operator=
void operator=(const T list[N])
Assignment to array operator. Takes linear time.
Definition: FixedListI.H:432
Foam::boolVector::flip
void flip()
Invert all values.
Definition: boolVectorI.H:119
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::boolVector::boolVector
boolVector()
Default construct, zero-initialized (ie, false)
Definition: boolVectorI.H:30
Foam::BitOps::any
bool any(const UList< bool > &bools)
True if any entries are 'true'.
Definition: BitOps.H:91
Foam::boolVector::z
bool z() const
The z component.
Definition: boolVectorI.H:112
Foam::boolVector::X
Definition: boolVector.H:68
Foam::boolVector::Y
Definition: boolVector.H:68
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
bool
bool
Definition: EEqn.H:20
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::boolVector::x
bool x() const
The x component.
Definition: boolVectorI.H:110
Foam::boolVector::any
bool any() const
True if any components are set.
Definition: boolVectorI.H:75
Foam::boolVector::y
bool y() const
The y component.
Definition: boolVectorI.H:111
Foam::boolVector::count
unsigned int count(const bool on=true) const
Count number of items set.
Definition: boolVectorI.H:91
y
scalar y
Definition: LISASMDCalcMethod1.H:14