#pragma once template class GpBitfield { public: GpBitfield(); GpBitfield(const GpBitfield &other); bool operator==(const GpBitfield &other) const; bool operator!=(const GpBitfield &other) const; void Set(unsigned int index, bool v); bool Get(unsigned int index) const; private: static const unsigned int TSizeBytes = (TSize + 7) / 8; uint8_t m_bytes[TSizeBytes]; }; template inline GpBitfield::GpBitfield() { for (unsigned int i = 0; i < TSizeBytes; i++) m_bytes[i] = 0; } template inline GpBitfield::GpBitfield(const GpBitfield &other) : m_bytes(other.m_bytes) { } template inline bool GpBitfield::operator==(const GpBitfield &other) const { for (unsigned int i = 0; i < TSizeBytes; i++) if (m_bytes[i] != other.m_bytes[i]) return false; return true; } template inline bool GpBitfield::operator!=(const GpBitfield &other) const { return !((*this) == other); } template void GpBitfield::Set(unsigned int index, bool v) { if (v) m_bytes[index / 8] |= (1 << (index & 7)); else m_bytes[index / 8] &= ~(1 << (index & 7)); } template bool GpBitfield::Get(unsigned int index) const { return (m_bytes[index / 8] & (1 << (index & 7))) != 0; }