Go to the documentation of this file.
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>
182 s << (
x.test(i-1) ?
"1" :
"0");
189 #endif // UAVCAN_UTIL_BITSET_HPP_INCLUDED
UAVCAN_EXPORT EnableIf<!IsSameType< R, Array< T, ArrayMode, MaxSize > >::Result, bool >::Type operator==(const R &rhs, const Array< T, ArrayMode, MaxSize > &lhs)
bool test(std::size_t pos) const
const std::size_t bitpos_
OStream & operator<<(OStream &s, long long x)
std::size_t count() const
Reference(BitSet *arg_parent, std::size_t arg_bitpos)
static std::size_t getByteNum(std::size_t bit_num)
bool operator!=(const BitSet< NumBits > &rhs) const
BitSet< NumBits > & reset()
BitSet< NumBits > & set(std::size_t pos, bool val=true)
Reference & operator=(bool x)
static std::size_t getBitNum(const std::size_t bit_num)
Reference operator[](std::size_t pos)
Reference & operator=(const Reference &x)
BitSet< NumBits > & operator=(const BitSet< NumBits > &rhs)
bool operator==(const BitSet< NumBits > &rhs) const
BitSet< NumBits > & set()
static void validatePos(std::size_t &inout_pos)
bool operator[](std::size_t pos) const