boolVector.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-2023 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 Class
27  Foam::boolVector
28 
29 Description
30  Specialized bundling of boolean values as a vector of 3 components,
31  element access using x(), y() and z() member functions.
32  It also has some methods similar to bitSet.
33 
34 Note
35  The boolVector is not derived from Vector or VectorSpace since
36  it does not share very many vector-like characteristics.
37 
38 SourceFiles
39  boolVectorI.H
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Foam_boolVector_H
44 #define Foam_boolVector_H
45 
46 #include "FixedList.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class boolVector Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class boolVector
58 :
59  public FixedList<bool, 3>
60 {
61 public:
62 
63  // Typedefs
64 
65  //- The component type is bool
66  typedef bool cmptType;
67 
68 
69  // Member Constants
70 
71  //- Rank of a vector is 1
72  static constexpr direction rank = 1;
73 
74  //- Number of components in this vector space
75  static constexpr direction nComponents = 3;
76 
77  //- Component labeling enumeration
78  enum components { X, Y, Z };
79 
80 
81  // Generated Methods
82 
83  //- Copy construct
84  boolVector(const boolVector&) = default;
85 
86  //- Copy assignment
87  boolVector& operator=(const boolVector&) = default;
88 
89  //- Move construct
90  boolVector(boolVector&&) = default;
91 
92  //- Move assignment
93  boolVector& operator=(boolVector&&) = default;
94 
95  //- The front() accessor (from FixedList) has no purpose
96  void front() = delete;
97 
98  //- The back() accessor (from FixedList) has no purpose
99  void back() = delete;
100 
101 
102  // Constructors
103 
104  //- Default construct, zero-initialized (ie, false)
105  inline boolVector();
106 
107  //- Uniform construct with specified value
108  inline explicit boolVector(const bool val);
109 
110  //- Construct from three components
111  inline boolVector(const bool vx, const bool vy, const bool vz);
112 
113  //- Construct from Istream
114  inline explicit boolVector(Istream& is);
115 
116 
117  // Member Functions
118 
119  // Query
120 
121  //- True if all components are set
122  //
123  // \note Method name compatibility with bitSet
124  inline bool all() const noexcept;
125 
126  //- True if any components are set
127  //
128  // \note Method name compatibility with bitSet
129  inline bool any() const noexcept;
130 
131  //- True if no components are set
132  //
133  // \note Method name compatibility with bitSet
134  inline bool none() const noexcept;
135 
136  //- Count number of items set.
137  // \param on can be set to false to count the number of unset bits
138  // instead.
139  //
140  // \note Method name compatibility with bitSet
141  inline unsigned int count(const bool on=true) const;
142 
143 
144  // Component Access
145 
146  //- The x component
147  bool x() const noexcept { return get<0>(); }
148 
149  //- The y component
150  bool y() const noexcept { return get<1>(); }
151 
152  //- The z component
153  bool z() const noexcept { return get<2>(); }
154 
155  //- The x component
156  bool& x() noexcept { return get<0>(); }
157 
158  //- The y component
159  bool& y() noexcept { return get<1>(); }
160 
161  //- The z component
162  bool& z() noexcept { return get<2>(); }
163 
164 
165  // Edit
166 
167  //- Invert all values
168  //
169  // \note Method name compatibility with bitSet
170  inline void flip();
171 
172 
173  // Operators
174 
175  //- Assignment of all entries to the given value
176  inline void operator=(const bool value);
177 };
178 
179 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
180 
181 //- A boolVector is contiguous (FixedList of bool)
182 template<> struct is_contiguous<boolVector> : std::true_type {};
183 
185 /*---------------------------------------------------------------------------*\
186  Specialization pTraits<boolVector>
187 \*---------------------------------------------------------------------------*/
188 
189 //- A boolVector has bool data components.
190 template<>
191 struct pTraits_cmptType<boolVector> { typedef bool type; };
192 
193 //- A boolVector has three data components
194 template<>
196 :
197  std::integral_constant<Foam::direction, 3>
198 {};
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 } // End namespace Foam
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #include "boolVectorI.H"
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 #endif
212 
213 // ************************************************************************* //
bool none() const noexcept
True if no components are set.
Definition: boolVectorI.H:68
boolVector & operator=(const boolVector &)=default
Copy assignment.
uint8_t direction
Definition: direction.H:46
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:107
bool y() const noexcept
The y component.
Definition: boolVector.H:189
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
The vector-space number of components: default is 1.
Definition: pTraits.H:168
void back()=delete
The back() accessor (from FixedList) has no purpose.
bool cmptType
The component type is bool.
Definition: boolVector.H:63
boolVector()
Default construct, zero-initialized (ie, false)
Definition: boolVectorI.H:23
void front()=delete
The front() accessor (from FixedList) has no purpose.
The underlying component data type: default is pass-through.
Definition: pTraits.H:148
bool x() const noexcept
The x component.
Definition: boolVector.H:184
const direction noexcept
Definition: Scalar.H:258
Specialized bundling of boolean values as a vector of 3 components, element access using x()...
Definition: boolVector.H:52
bool all() const noexcept
True if all components are set.
Definition: boolVectorI.H:56
static constexpr direction nComponents
Number of components in this vector space.
Definition: boolVector.H:76
components
Component labeling enumeration.
Definition: boolVector.H:81
void flip()
Invert all values.
Definition: boolVectorI.H:93
bool z() const noexcept
The z component.
Definition: boolVector.H:194
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
static constexpr direction rank
Rank of a vector is 1.
Definition: boolVector.H:71
Namespace for OpenFOAM.