Simpatico  v1.10
Bit.h
1 #ifndef UTIL_BIT_H
2 #define UTIL_BIT_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 namespace Util
12 {
13 
21  class Bit
22  {
23  public:
24 
28  Bit();
29 
35  Bit(unsigned int shift);
36 
42  void setMask(unsigned int shift);
43 
49  void set(unsigned int& flags) const;
50 
56  void clear(unsigned int& flags) const;
57 
63  bool isSet(unsigned int flags) const;
64 
68  unsigned int mask() const;
69 
70  private:
71 
73  unsigned int mask_;
74 
75  };
76 
77  /*
78  * Set this bit in the flags parameter.
79  */
80  inline void Bit::set(unsigned int& flags) const
81  { flags |= mask_; }
82 
83  /*
84  * Clear this bit in the flags parameter.
85  */
86  inline void Bit::clear(unsigned int& flags) const
87  { flags &= (~mask_); }
88 
89  /*
90  * Is this bit set in the flags integer?
91  */
92  inline bool Bit::isSet(unsigned int flags) const
93  { return bool(flags & mask_); }
94 
95  /*
96  * Return unsigned int with only this bit set.
97  */
98  inline unsigned int Bit::mask() const
99  { return mask_; }
100 
101 }
102 #endif
void set(unsigned int &flags) const
Set this bit in the flags parameter.
Definition: Bit.h:80
void clear(unsigned int &flags) const
Clear this bit in the flags parameter.
Definition: Bit.h:86
bool isSet(unsigned int flags) const
Is this bit set in the flags integer?
Definition: Bit.h:92
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setMask(unsigned int shift)
Set or reset the bit mask.
Definition: Bit.cpp:31
Bit()
Default constructor.
Definition: Bit.cpp:18
unsigned int mask() const
Return integer with only this bit set.
Definition: Bit.h:98
Represents a specific bit location within an unsigned int.
Definition: Bit.h:21