Bitset.h 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef ANKI_BITSET_H
  2. #define ANKI_BITSET_H
  3. #include "anki/util/StdTypes.h"
  4. namespace anki {
  5. /// @addtogroup util
  6. /// @{
  7. /// @addtogroup containers
  8. /// @{
  9. /// Easy bit manipulation
  10. template<typename T>
  11. class Bitset
  12. {
  13. public:
  14. typedef T Value;
  15. Bitset()
  16. : bitmask(0)
  17. {}
  18. Bitset(T bitmask_)
  19. : bitmask(bitmask_)
  20. {}
  21. /// @name Bits manipulation
  22. /// @{
  23. void enableBits(Value mask)
  24. {
  25. bitmask |= mask;
  26. }
  27. void enableBits(Value mask, Bool enable)
  28. {
  29. bitmask = (enable) ? bitmask | mask : bitmask & ~mask;
  30. }
  31. void disableBits(Value mask)
  32. {
  33. bitmask &= ~mask;
  34. }
  35. void switchBits(Value mask)
  36. {
  37. bitmask ^= mask;
  38. }
  39. Bool bitsEnabled(Value mask) const
  40. {
  41. return bitmask & mask;
  42. }
  43. Value getBitmask() const
  44. {
  45. return bitmask;
  46. }
  47. /// @}
  48. protected:
  49. Value bitmask;
  50. };
  51. /// @}
  52. /// @}
  53. } // end namespace anki
  54. #endif