VTK-m  2.2
Bitset.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_Bitset_h
12 #define vtk_m_Bitset_h
13 
14 #include <cassert>
15 #include <limits>
16 #include <vtkm/Types.h>
18 
19 namespace vtkm
20 {
21 
27 template <typename MaskType>
28 struct Bitset
29 {
30  VTKM_EXEC_CONT void set(vtkm::Id bitIndex)
31  {
32  this->Mask = static_cast<MaskType>(this->Mask | (static_cast<MaskType>(1) << bitIndex));
33  }
34 
35  VTKM_EXEC_CONT void set(vtkm::Id bitIndex, bool val)
36  {
37  if (val)
38  this->set(bitIndex);
39  else
40  this->reset(bitIndex);
41  }
42 
43  VTKM_EXEC_CONT void reset(vtkm::Id bitIndex)
44  {
45  this->Mask = static_cast<MaskType>(this->Mask & ~(static_cast<MaskType>(1) << bitIndex));
46  }
47 
49  {
50  this->Mask = this->Mask ^ (static_cast<MaskType>(0) << bitIndex);
51  }
52 
53  VTKM_EXEC_CONT bool test(vtkm::Id bitIndex) const
54  {
55  return ((this->Mask & (static_cast<MaskType>(1) << bitIndex)) != 0);
56  }
57 
58  VTKM_EXEC_CONT bool operator==(const vtkm::Bitset<MaskType>& otherBitset) const
59  {
60  return this->Mask == otherBitset.Mask;
61  }
62 
63 private:
64  MaskType Mask = 0;
65 };
66 
67 } // namespace vtkm
68 
69 #endif //vtk_m_Bitset_h
vtkm::Bitset
A bitmap to serve different needs.
Definition: Bitset.h:28
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Bitset::operator==
bool operator==(const vtkm::Bitset< MaskType > &otherBitset) const
Definition: Bitset.h:58
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
ExportMacros.h
vtkm::Bitset::test
bool test(vtkm::Id bitIndex) const
Definition: Bitset.h:53
vtkm::Bitset::reset
void reset(vtkm::Id bitIndex)
Definition: Bitset.h:43
vtkm::Bitset::toggle
void toggle(vtkm::Id bitIndex)
Definition: Bitset.h:48
vtkm::Bitset::Mask
MaskType Mask
Definition: Bitset.h:64
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::Bitset::set
void set(vtkm::Id bitIndex, bool val)
Definition: Bitset.h:35
vtkm::Bitset::set
void set(vtkm::Id bitIndex)
Definition: Bitset.h:30