All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pieceMask32.h
Go to the documentation of this file.
1 /* pieceMask32.h
2  */
3 #ifndef PIECEMASK32_H
4 #define PIECEMASK32_H
5 
6 #include "osl/misc/mask.h"
7 #include "osl/misc/carray.h"
8 
9 namespace osl
10 {
11  namespace container
12  {
14  {
15  protected:
16  CArray<misc::Mask32,2> mask;
17  public:
18  static int numToIndex(int num) { return num>>5; }
19  static int numToOffset(int num) { return num&31; }
20 
22  {
23  resetAll();
24  }
25  PieceMask32(const misc::Mask32& m1,const misc::Mask32& m2)
26  {
27  mask[0]=m1; mask[1]=m2;
28  }
29  protected:
30  misc::Mask32& mutableMask(int index) { return mask[index]; }
31  public:
32  const misc::Mask32& getMask(int index) const
33  {
34  return mask[index];
35  }
37  {
38  mask[0] ^= o.mask[0];
39  mask[1] ^= o.mask[1];
40  return *this;
41  }
43  {
44  mask[0] &= o.mask[0];
45  mask[1] &= o.mask[1];
46  return *this;
47  }
49  {
50  mask[0] |= o.mask[0];
51  mask[1] |= o.mask[1];
52  return *this;
53  }
55  {
56  mask[0] -= o.mask[0];
57  mask[1] -= o.mask[1];
58  return *this;
59  }
61  {
62  mask[0] += o.mask[0];
63  mask[1] += o.mask[1];
64  return *this;
65  }
66  void resetAll()
67  {
69  }
70  void setAll()
71  {
72  mask[0]=misc::Mask32::makeDirect(0xffffffffu);
74  }
75  bool none() const
76  {
77  return (mask[0]|mask[1]).none();
78  }
79  bool hasMultipleBit() const
80  {
81  if (none())
82  return false;
83  if (! mask[0].any())
84  return mask[1].hasMultipleBit();
85  if (! mask[1].any())
86  return mask[0].hasMultipleBit();
87  return true;
88  }
93  int countBit2() const
94  {
95  if (none())
96  return 0;
97  if (! mask[0].any())
98  return mask[1].countBit2();
99  if (! mask[1].any())
100  return mask[0].countBit2();
101  return 2;
102  }
103  int countBit() const
104  {
105  return mask[0].countBit() + mask[1].countBit();
106  }
108  {
109  assert(!none());
110  if(! mask[0].none())
111  return mask[0].takeOneBit();
112  return mask[1].takeOneBit()+32;
113  }
114  };
115 } // namespace container
116  using container::PieceMask32;
117 } // namespace osl
118 
119 
120 #endif /* PIECEMASK32_H */
121 // ;;; Local Variables:
122 // ;;; mode:c++
123 // ;;; c-basic-offset:2
124 // ;;; End: