5 #ifndef UAVCAN_UTIL_BITSET_HPP_INCLUDED 6 #define UAVCAN_UTIL_BITSET_HPP_INCLUDED 18 template <std::
size_t NumBits>
21 enum { NumBytes = (NumBits + 7) / 8 };
29 if (inout_pos >= NumBits)
32 inout_pos = NumBits - 1;
54 parent_->
set(bitpos_, x);
60 parent_->
set(bitpos_, x);
66 return !parent_->
test(bitpos_);
71 return parent_->
test(bitpos_);
83 std::memset(data_, 0, NumBytes);
89 std::memset(data_, 0xFF, NumBytes);
98 data_[getByteNum(pos)] = char(data_[getByteNum(pos)] | (1 << getBitNum(pos)));
102 data_[getByteNum(pos)] = char(data_[getByteNum(pos)] & ~(1 << getBitNum(pos)));
109 return (data_[getByteNum(pos)] & (1 << getBitNum(pos))) != 0;
129 retval +=
test(i) ? 1U : 0U;
144 return Reference(
this, pos);
155 data_[i] = rhs.
data_[i];
174 template <>
class BitSet<0>;
177 template <
typename Stream, std::
size_t NumBits>
178 Stream& operator<<(Stream& s, const BitSet<NumBits>&
x)
182 s << (
x.test(i-1) ?
"1" :
"0");
189 #endif // UAVCAN_UTIL_BITSET_HPP_INCLUDED bool operator!=(const BitSet< NumBits > &rhs) const
Reference & operator=(const Reference &x)
BitSet< NumBits > & reset()
static std::size_t getByteNum(std::size_t bit_num)
const std::size_t bitpos_
Reference(BitSet *arg_parent, std::size_t arg_bitpos)
BitSet< NumBits > & operator=(const BitSet< NumBits > &rhs)
Reference & operator=(bool x)
bool test(std::size_t pos) const
bool operator==(const BitSet< NumBits > &rhs) const
std::size_t count() const
UAVCAN_EXPORT EnableIf<!IsSameType< R, Array< T, ArrayMode, MaxSize > >::Result, bool >::Type operator==(const R &rhs, const Array< T, ArrayMode, MaxSize > &lhs)
BitSet< NumBits > & set()
static void validatePos(std::size_t &inout_pos)
Reference operator[](std::size_t pos)
bool operator[](std::size_t pos) const
static std::size_t getBitNum(const std::size_t bit_num)