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.
 
 
 

56 regels
1.0 KiB

  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 __LOL_BITFIELD_H__
  15. #define __LOL_BITFIELD_H__
  16. #include <stdint.h>
  17. namespace lol
  18. {
  19. template class BitField<unsigned int COUNT>
  20. {
  21. public:
  22. BitField()
  23. {
  24. memset(bits, 0, sizeof(bits));
  25. }
  26. inline unsigned int IsSet(unsigned int index)
  27. {
  28. return bits[index / 32] & (1 << (index & 31));
  29. }
  30. inline void Set(unsigned int index)
  31. {
  32. bits[index / 32] |= (1 << (index & 31));
  33. }
  34. inline void Unset(unsigned int index)
  35. {
  36. bits[index / 32] &= ~(1 << (index & 31));
  37. }
  38. private:
  39. uint32_t bits[(COUNT + 31) / 32];
  40. };
  41. } /* namespace lol */
  42. #endif // __LOL_BITFIELD_H__