• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

XnBitSet.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 *                                                                           *
00003 *  OpenNI 1.1 Alpha                                                         *
00004 *  Copyright (C) 2011 PrimeSense Ltd.                                       *
00005 *                                                                           *
00006 *  This file is part of OpenNI.                                             *
00007 *                                                                           *
00008 *  OpenNI is free software: you can redistribute it and/or modify           *
00009 *  it under the terms of the GNU Lesser General Public License as published *
00010 *  by the Free Software Foundation, either version 3 of the License, or     *
00011 *  (at your option) any later version.                                      *
00012 *                                                                           *
00013 *  OpenNI is distributed in the hope that it will be useful,                *
00014 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00015 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
00016 *  GNU Lesser General Public License for more details.                      *
00017 *                                                                           *
00018 *  You should have received a copy of the GNU Lesser General Public License *
00019 *  along with OpenNI. If not, see <http://www.gnu.org/licenses/>.           *
00020 *                                                                           *
00021 ****************************************************************************/
00022 #ifndef __XNBITSET_H__
00023 #define __XNBITSET_H__
00024 
00025 #include <XnArray.h>
00026 
00027 class XnBitSet
00028 {
00029 public:
00030     XnBitSet() : m_nSize(0) {}
00031 
00034     XnStatus Reserve(XnUInt32 nBits)
00035     {
00036         return m_array.Reserve((nBits >> 5) + 1);
00037     }
00038 
00040     XnStatus SetSize(XnUInt32 nBits)
00041     {
00042         return m_array.SetSize((nBits >> 5) + 1, 0);
00043     }
00044 
00046     XnStatus Set(XnUInt32 nIndex, XnBool bValue)
00047     {
00048         XnUInt32 nArrayIndex = (nIndex >> 5);
00049         XnUInt32 nMask = (1 << ((~nIndex) & 0x1F));
00050         XnUInt32 nOldVal = nArrayIndex < m_array.GetSize() ? m_array[nArrayIndex] : 0;
00051         XnUInt32 nNewVal = bValue ? (nOldVal | nMask) : (nOldVal & (~nMask));
00052         XnStatus nRetVal = m_array.Set(nArrayIndex, nNewVal, 0);
00053         XN_IS_STATUS_OK(nRetVal);
00054         m_nSize = XN_MAX(m_nSize, nIndex + 1);
00055         return XN_STATUS_OK;
00056     }
00057     
00059     XnBool IsSet(XnUInt32 nIndex) const
00060     {
00061         XnUInt32 nArrayIndex = (nIndex >> 5);
00062         if (nArrayIndex >= m_array.GetSize())
00063         {
00064             return FALSE;
00065         }
00066         return (m_array[nArrayIndex] & (1 << ((~nIndex) & 0x1F))) ? TRUE : FALSE;
00067     }
00068 
00070     XnStatus SetData(const XnUInt32* pData, XnUInt32 nSizeInDwords)
00071     {
00072         XnStatus nRetVal = m_array.SetData(pData, nSizeInDwords);
00073         XN_IS_STATUS_OK(nRetVal);
00074         m_nSize = (nSizeInDwords << 5);
00075         return XN_STATUS_OK;
00076     }
00077 
00079     const XnUInt32* GetData() const
00080     {
00081         return m_array.GetData();
00082     }
00083 
00085     XnUInt32* GetData()
00086     {
00087         return m_array.GetData();
00088     }
00089 
00091     XnUInt32 GetSize() const
00092     {
00093         return m_nSize;
00094     }
00095 
00097     void Clear()
00098     {
00099         m_array.Clear();
00100         m_nSize = 0;
00101     }
00102 
00104     XnBool IsEmpty() const
00105     {
00106         return m_array.IsEmpty();
00107     }
00108     
00109 private:
00110     XnArray<XnUInt32> m_array;
00111     XnUInt32 m_nSize;
00112 };
00113 
00114 #endif // __XNBITSET_H__

Generated on Fri Nov 9 2012 23:01:16 for OpenNI 1.3.2 by  doxygen 1.7.1