15 namespace duds {
namespace general {
100 template <
class Tag,
class BitsType =
int>
121 constexpr
BitFlags(
const BitsType &b) : bits(b) { }
142 return BitFlags(((BitsType)1) << b);
154 return bits | bf.
bits;
160 return bits |= bf.
bits;
166 return bits & bf.
bits;
172 return bits &= bf.
bits;
178 return bits ^ bf.
bits;
184 return bits ^= bf.
bits;
190 return bits == bf.
bits;
196 return bits != bf.
bits;
225 constexpr
operator bool ()
const {
232 return bits = bf.
bits;
240 return bits &= mask.
bits;
253 return bits &= ~bf.
bits;
260 return bits |= bf.
bits;
269 return bits |= bf.
bits;
271 return bits &= ~bf.
bits;
279 return bits = (bits & (~mask.
bits)) | (bf.
bits & mask.
bits);
286 return bits ^= bf.
bits;
302 return (bits & valuemask.
bits) == valuemask.
bits;
314 template <
class T,
class B>
315 struct hash<
duds::general::BitFlags<T, B> > {
317 return hash<B>()(bf.
flags());
323 namespace duds {
namespace general {
330 template <
class T,
class B>
332 return std::hash< duds::general::BitFlags<T, B> >()(bf);
337 #endif // #ifndef BITFLAGS_HPP BitFlags setTo(const BitFlags &bf, bool val)
Make all bits in bf set or clear based on the value of val.
BitFlags mask(const BitFlags &mask)
A bit mask operation; bits set in mask will remain unchanged in this object, while all other bits wil...
BitFlags clear(const BitFlags &bf)
Clear all bits in this object that are set in bf.
std::size_t operator()(const duds::general::BitFlags< T, B > &bf) const
BitFlags()=default
Construct an uninitialized bit flags container.
BitFlags operator&=(const BitFlags &bf)
Regular bitwise and assignment.
constexpr bool test(const BitFlags &value, const BitFlags &mask) const
Returns true if the flags identified by mask have the same value as those flags do in value...
BitFlags toggle(const BitFlags &bf)
Toggle the bits that are set in bf; all other bits remain unchanged.
constexpr bool operator!() const
Regular logical not.
BitFlags operator^=(const BitFlags &bf)
Regular bitwise exclusive or assignment.
std::size_t hash_value(const duds::general::BitFlags< T, B > &bf)
Generates a hash value for use with Boost containers, like boost::multi_index::multi_index_container ...
static constexpr BitFlags Zero()
Makes a bit flags container with all flags cleared.
BitFlags clear()
Clear all bits.
BitFlags operator=(const BitFlags &bf)
Regular assignment.
constexpr bool operator!=(const BitFlags &bf) const
Regular not equivalent operator.
constexpr BitFlags operator|(const BitFlags &bf) const
Regular bitwise or.
static constexpr BitFlags Bit(BitsType b)
Makes a bit flags container with a single bit set that is specified by digit number rather than value...
constexpr BitFlags(const BitFlags &f)
Construct a bit flags container with a copy of the contents of another container of the same type...
constexpr BitFlags(const BitsType &b)
Construct a bit flags container with a specified value.
BitFlags operator|=(const BitFlags &bf)
Regular bitwise or assignment.
constexpr BitFlags operator&(const BitFlags &bf) const
Regular bitwise and.
A type-safe bit flag storage class.
constexpr BitFlags operator^(const BitFlags &bf) const
Regular bitwise exclusive or.
constexpr bool operator==(const BitFlags &bf) const
Regular equality operator.
BitsType bitsType
The datatype used to store the flags.
constexpr BitsType flags() const
Returns the value stored in the object.
constexpr BitFlags operator~() const
Regular bitwise not.
constexpr bool test(const BitFlags &valuemask) const
Returns true if the flags identified by valuemask are all set.
BitFlags setMasked(const BitFlags &bf, const BitFlags &mask)
Changes only the bits in a masked range.