OpenMPCD
Bitset.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * Defines the `OpenMPCD::CUDA::Bitset` class.
4  */
5 
6 #ifndef OPENMPCD_CUDA_BITSET_HPP
7 #define OPENMPCD_CUDA_BITSET_HPP
8 
10 
11 #include <climits>
12 
13 namespace OpenMPCD
14 {
15 namespace CUDA
16 {
17 
18 /**
19  * Represents a constant-size collection of boolean values.
20  */
21 class Bitset
22 {
23 public:
24  /**
25  * The constructor.
26  *
27  * The initial value of the bits is unspecified.
28  *
29  * @param[in] bitCount_
30  * The number of bits to store.
31  */
33  Bitset(const std::size_t bitCount_);
34 
35 private:
36  /**
37  * The copy constructor.
38  */
39  Bitset(const Bitset&);
40 
41 public:
42  /**
43  * The destructor.
44  */
46  ~Bitset();
47 
48 public:
49  /**
50  * Returns the number of accessible bits.
51  */
53  std::size_t getBitCount() const;
54 
55  /**
56  * Sets the given bit to the given value.
57  *
58  * This function is thread-safe.
59  *
60  * If `OPENMPCD_DEBUG` is defined, asserts that `bit` has a valid value.
61  *
62  * @param[in] bit
63  * The bit to set, indexed in the range `[0, getBitCount())`.
64  * @param[in] value
65  * The value to set the bit to.
66  */
68  void set(const std::size_t bit, const bool value);
69 
70  /**
71  * Returns the given bit.
72  *
73  * This function is thread-safe.
74  *
75  * If `OPENMPCD_DEBUG` is defined, asserts that `bit` has a valid value.
76  *
77  * @param[in] bit
78  * The bit to set, indexed in the range `[0, getBitCount())`.
79  */
81  bool get(const std::size_t bit) const;
82 
83  /**
84  * Sets all bits to the given value.
85  *
86  * @param[in] value
87  * The value to set the bits to.
88  */
90  void setAll(const bool value);
91 
92 private:
93  /**
94  * The assignment operator.
95  */
96  const Bitset& operator=(const Bitset&);
97 
98 private:
99  unsigned int* const storage; ///< The memory where the bits are stored.
100  const std::size_t bitCount; ///< The number of bits stored.
101 
102 private:
103  static const std::size_t bitsPerElement = sizeof(unsigned int) * CHAR_BIT;
104  ///< The number of bits per stored element.
105 }; //class Bitset
106 } //namespace CUDA
107 } //namespace OpenMPCD
108 
109 
111 
112 #endif //OPENMPCD_CUDA_BITSET_HPP
OpenMPCD::CUDA::Bitset::~Bitset
OPENMPCD_CUDA_DEVICE ~Bitset()
The destructor.
Definition: ImplementationDetails/Bitset.hpp:28
OpenMPCD::CUDA::Bitset::Bitset
OPENMPCD_CUDA_DEVICE Bitset(const std::size_t bitCount_)
The constructor.
Definition: ImplementationDetails/Bitset.hpp:20
OpenMPCD::CUDA::Bitset::set
OPENMPCD_CUDA_DEVICE void set(const std::size_t bit, const bool value)
Sets the given bit to the given value.
Definition: ImplementationDetails/Bitset.hpp:40
OPENMPCD_CUDA_DEVICE
#define OPENMPCD_CUDA_DEVICE
Denotes a function to be callable from a CUDA Device.
Definition: Macros.hpp:25
OpenMPCD::CUDA::Bitset
Represents a constant-size collection of boolean values.
Definition: Bitset.hpp:21
OpenMPCD::CUDA::Bitset::get
OPENMPCD_CUDA_DEVICE bool get(const std::size_t bit) const
Returns the given bit.
Definition: ImplementationDetails/Bitset.hpp:58
OpenMPCD::CUDA::Bitset::setAll
OPENMPCD_CUDA_DEVICE void setAll(const bool value)
Sets all bits to the given value.
Definition: ImplementationDetails/Bitset.hpp:69
Macros.hpp
Bitset.hpp
OpenMPCD::CUDA::Bitset::getBitCount
OPENMPCD_CUDA_DEVICE std::size_t getBitCount() const
Returns the number of accessible bits.
Definition: ImplementationDetails/Bitset.hpp:34