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-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 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  // Member Constants
64 
65  //- Rank of a vector is 1
66  static constexpr direction rank = 1;
67 
68  //- Component labeling enumeration
69  enum components { X, Y, Z };
70 
71 
72  // Generated Methods
73 
74  //- Copy construct
75  boolVector(const boolVector&) = default;
76 
77  //- Copy assignment
78  boolVector& operator=(const boolVector&) = default;
79 
80  //- Move construct
81  boolVector(boolVector&&) = default;
82 
83  //- Move assignment
84  boolVector& operator=(boolVector&&) = default;
85 
86  //- The front() accessor (from FixedList) has no purpose
87  void front() = delete;
88 
89  //- The back() accessor (from FixedList) has no purpose
90  void back() = delete;
91 
92 
93  // Constructors
94 
95  //- Default construct, zero-initialized (ie, false)
96  inline boolVector();
97 
98  //- Uniform construct with specified value
99  inline explicit boolVector(const bool val);
100 
101  //- Construct from three components
102  inline boolVector(const bool vx, const bool vy, const bool vz);
103 
104  //- Construct from Istream
105  inline explicit boolVector(Istream& is);
106 
107 
108  // Member Functions
109 
110  // Query
111 
112  //- True if all components are set
113  //
114  // \note Method name compatibility with bitSet
115  inline bool all() const noexcept;
116 
117  //- True if any components are set
118  //
119  // \note Method name compatibility with bitSet
120  inline bool any() const noexcept;
121 
122  //- True if no components are set
123  //
124  // \note Method name compatibility with bitSet
125  inline bool none() const noexcept;
126 
127  //- Count number of items set.
128  // \param on can be set to false to count the number of unset bits
129  // instead.
130  //
131  // \note Method name compatibility with bitSet
132  inline unsigned int count(const bool on=true) const;
133 
134 
135  // Component Access
136 
137  //- The x component
138  bool x() const noexcept { return get<0>(); }
139 
140  //- The y component
141  bool y() const noexcept { return get<1>(); }
142 
143  //- The z component
144  bool z() const noexcept { return get<2>(); }
145 
146  //- The x component
147  bool& x() noexcept { return get<0>(); }
148 
149  //- The y component
150  bool& y() noexcept { return get<1>(); }
151 
152  //- The z component
153  bool& z() noexcept { return get<2>(); }
154 
155 
156  // Edit
157 
158  //- Invert all values
159  //
160  // \note Method name compatibility with bitSet
161  inline void flip();
162 
163 
164  // Operators
165 
166  //- Assignment of all entries to the given value
167  inline void operator=(const bool value);
168 };
169 
170 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
172 //- A boolVector is contiguous (FixedList of bool)
173 template<> struct is_contiguous<boolVector> : std::true_type {};
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 } // End namespace Foam
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 #include "boolVectorI.H"
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 #endif
187 
188 // ************************************************************************* //
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:101
bool y() const noexcept
The y component.
Definition: boolVector.H:176
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void back()=delete
The back() accessor (from FixedList) has no purpose.
boolVector()
Default construct, zero-initialized (ie, false)
Definition: boolVectorI.H:23
void front()=delete
The front() accessor (from FixedList) has no purpose.
bool x() const noexcept
The x component.
Definition: boolVector.H:171
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
components
Component labeling enumeration.
Definition: boolVector.H:68
A template class to specify that a data type can be considered as being contiguous in memory...
Definition: contiguous.H:71
void flip()
Invert all values.
Definition: boolVectorI.H:93
bool z() const noexcept
The z component.
Definition: boolVector.H:181
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:63
Namespace for OpenFOAM.