OpenNI 1.3.2
XnBitSet.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * OpenNI 1.1 Alpha *
4 * Copyright (C) 2011 PrimeSense Ltd. *
5 * *
6 * This file is part of OpenNI. *
7 * *
8 * OpenNI is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published *
10 * by the Free Software Foundation, either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * OpenNI is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20 * *
21 ****************************************************************************/
22 #ifndef __XNBITSET_H__
23 #define __XNBITSET_H__
24 
25 #include <XnArray.h>
26 
27 class XnBitSet
28 {
29 public:
30  XnBitSet() : m_nSize(0) {}
31 
34  XnStatus Reserve(XnUInt32 nBits)
35  {
36  return m_array.Reserve((nBits >> 5) + 1);
37  }
38 
40  XnStatus SetSize(XnUInt32 nBits)
41  {
42  return m_array.SetSize((nBits >> 5) + 1, 0);
43  }
44 
46  XnStatus Set(XnUInt32 nIndex, XnBool bValue)
47  {
48  XnUInt32 nArrayIndex = (nIndex >> 5);
49  XnUInt32 nMask = (1 << ((~nIndex) & 0x1F));
50  XnUInt32 nOldVal = nArrayIndex < m_array.GetSize() ? m_array[nArrayIndex] : 0;
51  XnUInt32 nNewVal = bValue ? (nOldVal | nMask) : (nOldVal & (~nMask));
52  XnStatus nRetVal = m_array.Set(nArrayIndex, nNewVal, 0);
53  XN_IS_STATUS_OK(nRetVal);
54  m_nSize = XN_MAX(m_nSize, nIndex + 1);
55  return XN_STATUS_OK;
56  }
57 
59  XnBool IsSet(XnUInt32 nIndex) const
60  {
61  XnUInt32 nArrayIndex = (nIndex >> 5);
62  if (nArrayIndex >= m_array.GetSize())
63  {
64  return FALSE;
65  }
66  return (m_array[nArrayIndex] & (1 << ((~nIndex) & 0x1F))) ? TRUE : FALSE;
67  }
68 
70  XnStatus SetData(const XnUInt32* pData, XnUInt32 nSizeInDwords)
71  {
72  XnStatus nRetVal = m_array.SetData(pData, nSizeInDwords);
73  XN_IS_STATUS_OK(nRetVal);
74  m_nSize = (nSizeInDwords << 5);
75  return XN_STATUS_OK;
76  }
77 
79  const XnUInt32* GetData() const
80  {
81  return m_array.GetData();
82  }
83 
85  XnUInt32* GetData()
86  {
87  return m_array.GetData();
88  }
89 
91  XnUInt32 GetSize() const
92  {
93  return m_nSize;
94  }
95 
97  void Clear()
98  {
99  m_array.Clear();
100  m_nSize = 0;
101  }
102 
104  XnBool IsEmpty() const
105  {
106  return m_array.IsEmpty();
107  }
108 
109 private:
110  XnArray<XnUInt32> m_array;
111  XnUInt32 m_nSize;
112 };
113 
114 #endif // __XNBITSET_H__