1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //  This software is distributed WITHOUT ANY WARRANTY; without even
6 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 //  PURPOSE.  See the above copyright notice for more information.
8 //
9 //  Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 //  Copyright 2016 UT-Battelle, LLC.
11 //  Copyright 2016 Los Alamos National Security.
12 //
13 //  Under the terms of Contract DE-NA0003525 with NTESS,
14 //  the U.S. Government retains certain rights in this software.
15 //
16 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 //  Laboratory (LANL), the U.S. Government retains certain rights in
18 //  this software.
19 //============================================================================
20 
21 #ifndef vtk_m_Bitset_h
22 #define vtk_m_Bitset_h
23 
24 #include <assert.h>
25 #include <limits>
26 #include <vtkm/Types.h>
27 #include <vtkm/internal/ExportMacros.h>
28 
29 namespace vtkm
30 {
31 
32 /// \brief A bitmap to serve different needs.
33 /// Ex. Editing particular bits in a byte(s), checkint if particular bit values
34 /// are present or not. Once Cuda supports std::bitset, we should use the
35 /// standard one if possible
36 template <typename MaskType>
37 struct Bitset
38 {
BitsetBitset39   VTKM_EXEC_CONT Bitset()
40     : Mask(0)
41   {
42   }
43 
setBitset44   VTKM_EXEC_CONT void set(vtkm::Id bitIndex)
45   {
46     this->Mask = this->Mask | (static_cast<MaskType>(1) << bitIndex);
47   }
48 
resetBitset49   VTKM_EXEC_CONT void reset(vtkm::Id bitIndex)
50   {
51     this->Mask = this->Mask & ~(static_cast<MaskType>(1) << bitIndex);
52   }
53 
toggleBitset54   VTKM_EXEC_CONT void toggle(vtkm::Id bitIndex)
55   {
56     this->Mask = this->Mask ^ (static_cast<MaskType>(0) << bitIndex);
57   }
58 
testBitset59   VTKM_EXEC_CONT bool test(vtkm::Id bitIndex)
60   {
61     return ((this->Mask & (static_cast<MaskType>(1) << bitIndex)) != 0);
62   }
63 
64 private:
65   MaskType Mask;
66 };
67 
68 } // namespace vtkm
69 
70 #endif //vtk_m_Bitset_h
71