BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Bitset.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_BITSET_HPP
13#define BELFEM_CL_BITSET_HPP
14
15
16#include <bitset>
17
18#include "typedefs.hpp"
19
20namespace belfem
21{
22//------------------------------------------------------------------------------
23
30 template < index_t N >
31 class Bitset
32 {
33//------------------------------------------------------------------------------
34
35 // the wrapped standard bitset
36 std::bitset< N > mBitset;
37
38//------------------------------------------------------------------------------
39 public:
40//------------------------------------------------------------------------------
41
42
46 Bitset() = default;
47
48//------------------------------------------------------------------------------
49
53 Bitset( const Bitset< N > & aBitset ) :
54 mBitset( aBitset.mBitset )
55 {
56 }
57
58//------------------------------------------------------------------------------
59
63 Bitset( Bitset< N > && aBitset ) :
64 mBitset( std::move( aBitset.mBitset ) )
65 {
66 }
67
68//------------------------------------------------------------------------------
69
73 ~Bitset() = default;
74
75//------------------------------------------------------------------------------
76
80 inline index_t
81 size() const
82 {
83 return N;
84 }
85
86//------------------------------------------------------------------------------
87
91 inline void
92 set( const index_t aIndex )
93 {
94 mBitset.set( aIndex );
95 }
96
97//------------------------------------------------------------------------------
98
102 inline void
103 reset( const index_t aIndex )
104 {
105 mBitset.reset( aIndex );
106 }
107
108
109//------------------------------------------------------------------------------
110
114 inline void
116 {
117 mBitset.reset();
118 }
119
120
121//------------------------------------------------------------------------------
122
126 inline void
127 flip( const index_t aIndex )
128 {
129 mBitset.flip( aIndex );
130 }
131
132//------------------------------------------------------------------------------
133
137 inline bool
138 test( const index_t aIndex ) const
139 {
140 return mBitset.test( aIndex );
141 }
142
143//------------------------------------------------------------------------------
144
148 inline index_t
149 count() const
150 {
151 return mBitset.count();
152 }
153
154//------------------------------------------------------------------------------
155
159 inline std::bitset< N > &
161 {
162 return mBitset ;
163 }
164
165//------------------------------------------------------------------------------
166
170 inline const std::bitset< N > &
171 data() const
172 {
173 return mBitset ;
174 }
175
176//------------------------------------------------------------------------------
177
182 operator=( const Bitset< N > & aBitset )
183 {
184 if( this != & aBitset )
185 {
186 mBitset = aBitset.mBitset ;
187 }
188 return *this ;
189 }
190
191//------------------------------------------------------------------------------
192
197 operator=( Bitset< N > && aBitset )
198 {
199 if( this != & aBitset )
200 {
201 mBitset = std::move( aBitset.mBitset ) ;
202 }
203 return *this ;
204 }
205
206//------------------------------------------------------------------------------
207
211 inline bool
212 operator==( const Bitset< N > & aBitset ) const
213 {
214 return mBitset == aBitset.mBitset ;
215 }
216
217//------------------------------------------------------------------------------
218
222 inline bool
223 operator!=( const Bitset< N > & aBitset ) const
224 {
225 return mBitset != aBitset.mBitset ;
226 }
227
228//------------------------------------------------------------------------------
229 };
230}
231
232#endif //BELFEM_CL_BITSET_HPP
Compile-time fixed-size bitset.
Definition cl_Bitset.hpp:32
std::bitset< N > & data()
expose data container
Definition cl_Bitset.hpp:160
void reset(const index_t aIndex)
set a bit to false
Definition cl_Bitset.hpp:103
bool operator==(const Bitset< N > &aBitset) const
equality operator
Definition cl_Bitset.hpp:212
Bitset(const Bitset< N > &aBitset)
copy constructor
Definition cl_Bitset.hpp:53
index_t size() const
the size of the bitset
Definition cl_Bitset.hpp:81
Bitset(Bitset< N > &&aBitset)
move constructor
Definition cl_Bitset.hpp:63
void flip(const index_t aIndex)
invert a bit
Definition cl_Bitset.hpp:127
bool operator!=(const Bitset< N > &aBitset) const
inequality operator
Definition cl_Bitset.hpp:223
void set(const index_t aIndex)
set a bit to true
Definition cl_Bitset.hpp:92
bool test(const index_t aIndex) const
test if a bit is set
Definition cl_Bitset.hpp:138
Bitset< N > & operator=(const Bitset< N > &aBitset)
copy assignment operator
Definition cl_Bitset.hpp:182
const std::bitset< N > & data() const
expose data container (const)
Definition cl_Bitset.hpp:171
void reset()
set all bits to false
Definition cl_Bitset.hpp:115
Bitset< N > & operator=(Bitset< N > &&aBitset)
move assignment operator
Definition cl_Bitset.hpp:197
index_t count() const
count the number of true bits
Definition cl_Bitset.hpp:149
Bitset()=default
trivial constructor
~Bitset()=default
tivial destructor
USER GUIDES:
Definition cl_Capacitor.cpp:16
uint32_t index_t
Definition typedefs.hpp:52