Leaked source code of windows server 2003
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.

62 lines
1.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999 - 1999.
  5. //
  6. // File: bitfield.hxx
  7. //
  8. // Contents: read/write access to a bitfield
  9. //
  10. // History: May-5-99 dlee Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #pragma once
  14. //+---------------------------------------------------------------------------
  15. //
  16. // Class: CBitfield
  17. //
  18. // Purpose: Manages a bitfield allocated elsewhere
  19. //
  20. // History: May-5-99 dlee Created
  21. //
  22. //----------------------------------------------------------------------------
  23. const unsigned cBitsPerByte = 8;
  24. class CBitfield
  25. {
  26. public:
  27. CBitfield( BYTE * pbBitfield ) : _pbBitfield( pbBitfield)
  28. {
  29. }
  30. BOOL IsBitSet( unsigned iBit )
  31. {
  32. unsigned iByte = iBit / cBitsPerByte;
  33. unsigned cRemainder = ( iBit % cBitsPerByte );
  34. return ( 0 != ( _pbBitfield[ iByte ] & ( 1 << cRemainder ) ) );
  35. }
  36. void SetBit( unsigned iBit )
  37. {
  38. unsigned iByte = iBit / cBitsPerByte;
  39. unsigned cRemainder = ( iBit % cBitsPerByte );
  40. _pbBitfield[ iByte ] |= ( 1 << cRemainder );
  41. }
  42. void ClearBit( unsigned iBit )
  43. {
  44. unsigned iByte = iBit / cBitsPerByte;
  45. unsigned cRemainder = ( iBit % cBitsPerByte );
  46. _pbBitfield[ iByte ] &= ( ~ ( 1 << cRemainder ) );
  47. }
  48. private:
  49. BYTE * _pbBitfield;
  50. };