Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

bitfield.h 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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__