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.
 
 
 

51 lines
1003 B

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. //
  11. // The BitField class
  12. // ------------------
  13. //
  14. #if !defined __DH_BITFIELD_H__
  15. #define __DH_BITFIELD_H__
  16. #include <stdint.h>
  17. template class BitField<unsigned int COUNT>
  18. {
  19. public:
  20. BitField()
  21. {
  22. memset(bits, 0, sizeof(bits));
  23. }
  24. inline unsigned int IsSet(unsigned int index)
  25. {
  26. return bits[index / 32] & (1 << (index & 31));
  27. }
  28. inline void Set(unsigned int index)
  29. {
  30. bits[index / 32] |= (1 << (index & 31));
  31. }
  32. inline void Unset(unsigned int index)
  33. {
  34. bits[index / 32] &= ~(1 << (index & 31));
  35. }
  36. private:
  37. uint32_t bits[(COUNT + 31) / 32];
  38. };
  39. #endif // __DH_BITFIELD_H__