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-------------------------------------------------------------------------------
10License
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
36inline 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 FixedList<bool, 3>()
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
65inline 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
75inline 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
85inline bool Foam::boolVector::none() const
86{
87 return !any();
88}
89
90
91inline 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
110inline bool Foam::boolVector::x() const { return operator[](boolVector::X); }
111inline bool Foam::boolVector::y() const { return operator[](boolVector::Y); }
112inline bool Foam::boolVector::z() const { return operator[](boolVector::Z); }
113
114inline bool& Foam::boolVector::x() { return operator[](boolVector::X); }
115inline bool& Foam::boolVector::y() { return operator[](boolVector::Y); }
116inline 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
130inline void Foam::boolVector::operator=(const bool value)
131{
133}
134
135
136// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
void operator=(const T list[N])
Assignment to array operator. Takes linear time.
Definition: FixedListI.H:432
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
void flip()
Invert all values.
Definition: boolVectorI.H:119
bool none() const
True if no components are set.
Definition: boolVectorI.H:85
bool x() const
The x component.
Definition: boolVectorI.H:110
boolVector & operator=(const boolVector &)=default
Copy assignment.
bool all() const
True if all components are set.
Definition: boolVectorI.H:65
bool y() const
The y component.
Definition: boolVectorI.H:111
boolVector()
Default construct, zero-initialized (ie, false)
Definition: boolVectorI.H:30
bool any() const
True if any components are set.
Definition: boolVectorI.H:75
bool z() const
The z component.
Definition: boolVectorI.H:112
label count() const
bool
Definition: EEqn.H:20