Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991-1998
  5. //
  6. // File: BitArray.hxx
  7. //
  8. // Contents: Classes for manipulating bit arrays
  9. //
  10. // Classes: CBitArray
  11. //
  12. // History: 25-Jun-98 KLam Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Class: CBitArray
  19. //
  20. // Purpose: Class for manipulating bit arrays
  21. //
  22. // History: Jun-16-98 KLam Created
  23. //
  24. //----------------------------------------------------------------------------
  25. #define BitsInDWORD 32
  26. #define DivDWORD(dw) (dw >> 5) // dw / 32 = dw / BitsInDWORD
  27. #define ModDWORD(dw) ( dw & (32-1)) // dw % 32
  28. class CBitArray
  29. {
  30. public:
  31. CBitArray ( size_t cBits = BitsInDWORD )
  32. : _xdwBits ( ( cBits/(BitsInDWORD + 1)) + 1 ),
  33. _cBits ( cBits )
  34. {
  35. ClearAll();
  36. }
  37. void Set ( DWORD iBit )
  38. {
  39. Win4Assert ( iBit < _cBits );
  40. _xdwBits[DivDWORD(iBit)] |= 1 << ModDWORD(iBit);
  41. }
  42. void Clear ( DWORD iBit )
  43. {
  44. Win4Assert ( iBit < _cBits );
  45. _xdwBits[DivDWORD(iBit)] &= ~( 1 << ModDWORD(iBit) );
  46. }
  47. BOOL Test ( DWORD iBit ) const
  48. {
  49. Win4Assert ( iBit < _cBits );
  50. return ( _xdwBits[DivDWORD(iBit)] & ( 1 << ModDWORD(iBit) ) ) != 0;
  51. }
  52. void ClearAll ()
  53. {
  54. RtlZeroMemory ( _xdwBits.Get(), _xdwBits.SizeOf() );
  55. }
  56. private:
  57. XGrowable<DWORD,1> _xdwBits;
  58. DWORD _cBits;
  59. };