Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
util::flags::Bits_t< Storage > Struct Template Reference

Type identifying a set of bits. More...

#include <BitMask.h>

Public Types

using Storage_t = Storage
 
using This_t = Bits_t< Storage >
 This type. More...
 
using Flag_t = util::flags::Flag_t< Storage_t >
 Type of flag matching our storage. More...
 

Public Member Functions

constexpr Bits_t ()=default
 Default constructor: no bit set. More...
 
constexpr Bits_t (Flag_t flag)
 Constructs from a single flag. More...
 
constexpr Bits_t (Storage_t bits)
 Constructs from a set of bits. More...
 
constexpr operator bool () const
 Returns true if there is at least one bit set. More...
 
constexpr bool operator! () const
 Returns true if there is no bit set. More...
 
Bit query operations
constexpr bool empty () const
 Returns whether there is no bit set at all. More...
 
constexpr bool all (This_t bits) const
 Returns wether all bits are set. More...
 
constexpr bool any (This_t bits) const
 Returns wether at least one of the bits is set. More...
 
constexpr bool none (This_t bits) const
 Returns wether all bits are unset. More...
 
constexpr bool only (This_t bits) const
 Returns wether no bits are set except (at most) the specified ones. More...
 
Bit change operations
void set (This_t bits)
 Sets the specified bits. More...
 
void unset (This_t bits)
 Unsets the specified bits. More...
 
void keepOnly (This_t bits)
 Unsets the bits which are not in bits argument. More...
 
void clear ()
 Unsets all bits. More...
 
Bit manipulation operations returning a new object
constexpr This_t select (This_t bits) const
 Returns only the bits that are also present in the argument. More...
 
constexpr This_t exclude (This_t bits) const
 Returns only the bits that are not present in the argument. More...
 
constexpr This_t combine (This_t bits) const
 Returns our bits, plus the ones present in the argument. More...
 
constexpr This_t invert () const
 Returns all and only the bits that are not set. More...
 
Comparison operators for bits
constexpr bool operator== (This_t other) const
 
constexpr bool operator!= (This_t other) const
 
constexpr bool operator< (This_t other) const
 
constexpr bool operator> (This_t other) const
 
constexpr bool operator<= (This_t other) const
 
constexpr bool operator>= (This_t other) const
 

Static Public Member Functions

static void setBits (Storage_t &base, Storage_t bits)
 Returns data with all bits from base and from bits set. More...
 
static void onlyBits (Storage_t &base, Storage_t bits)
 
static void unsetBits (Storage_t &base, Storage_t bits)
 Returns data with all bits from base, but the ones from bits unset. More...
 

Public Attributes

Storage_t data = { 0 }
 The bits representing all set bits. More...
 

Detailed Description

template<typename Storage>
struct util::flags::Bits_t< Storage >

Type identifying a set of bits.

Definition at line 194 of file BitMask.h.

Member Typedef Documentation

template<typename Storage>
using util::flags::Bits_t< Storage >::Flag_t = util::flags::Flag_t<Storage_t>

Type of flag matching our storage.

Definition at line 199 of file BitMask.h.

template<typename Storage>
using util::flags::Bits_t< Storage >::Storage_t = Storage

Definition at line 195 of file BitMask.h.

template<typename Storage>
using util::flags::Bits_t< Storage >::This_t = Bits_t<Storage>

This type.

Definition at line 196 of file BitMask.h.

Constructor & Destructor Documentation

template<typename Storage>
constexpr util::flags::Bits_t< Storage >::Bits_t ( )
default

Default constructor: no bit set.

template<typename Storage>
constexpr util::flags::Bits_t< Storage >::Bits_t ( Flag_t  flag)
inline

Constructs from a single flag.

Definition at line 207 of file BitMask.h.

208  : data(flag.bits)
209  {}
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr util::flags::Bits_t< Storage >::Bits_t ( Storage_t  bits)
inlineexplicit

Constructs from a set of bits.

Definition at line 212 of file BitMask.h.

213  : data(bits)
214  {}
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201

Member Function Documentation

template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::all ( This_t  bits) const

Returns wether all bits are set.

template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::any ( This_t  bits) const

Returns wether at least one of the bits is set.

template<typename Storage>
void util::flags::Bits_t< Storage >::clear ( )
inline

Unsets all bits.

Definition at line 251 of file BitMask.h.

252  { data = 0; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr This_t util::flags::Bits_t< Storage >::combine ( This_t  bits) const

Returns our bits, plus the ones present in the argument.

template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::empty ( ) const
inline

Returns whether there is no bit set at all.

Definition at line 220 of file BitMask.h.

221  { return data == Storage_t(0); }
Storage Storage_t
Definition: BitMask.h:195
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr This_t util::flags::Bits_t< Storage >::exclude ( This_t  bits) const

Returns only the bits that are not present in the argument.

template<typename Storage>
constexpr This_t util::flags::Bits_t< Storage >::invert ( ) const

Returns all and only the bits that are not set.

template<typename Storage>
void util::flags::Bits_t< Storage >::keepOnly ( This_t  bits)

Unsets the bits which are not in bits argument.

template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::none ( This_t  bits) const

Returns wether all bits are unset.

template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::only ( This_t  bits) const

Returns wether no bits are set except (at most) the specified ones.

template<typename Storage>
static void util::flags::Bits_t< Storage >::onlyBits ( Storage_t base,
Storage_t  bits 
)
inlinestatic

Returns data with all bits from base which are also in bits argument.

Definition at line 306 of file BitMask.h.

307  { base &= bits; }
template<typename Storage>
constexpr util::flags::Bits_t< Storage >::operator bool ( ) const
inlineexplicit

Returns true if there is at least one bit set.

Definition at line 294 of file BitMask.h.

294 { return bool(data); }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
int bool
Definition: qglobal.h:345
template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::operator! ( ) const
inline

Returns true if there is no bit set.

Definition at line 297 of file BitMask.h.

297 { return !data; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::operator!= ( This_t  other) const
inline

Definition at line 280 of file BitMask.h.

281  { return data != other.data; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::operator< ( This_t  other) const
inline

Definition at line 282 of file BitMask.h.

283  { return data < other.data; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::operator<= ( This_t  other) const
inline

Definition at line 286 of file BitMask.h.

287  { return data <= other.data; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::operator== ( This_t  other) const
inline

Definition at line 278 of file BitMask.h.

279  { return data == other.data; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::operator> ( This_t  other) const
inline

Definition at line 284 of file BitMask.h.

285  { return data > other.data; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr bool util::flags::Bits_t< Storage >::operator>= ( This_t  other) const
inline

Definition at line 288 of file BitMask.h.

289  { return data >= other.data; }
Storage_t data
The bits representing all set bits.
Definition: BitMask.h:201
template<typename Storage>
constexpr This_t util::flags::Bits_t< Storage >::select ( This_t  bits) const

Returns only the bits that are also present in the argument.

template<typename Storage>
void util::flags::Bits_t< Storage >::set ( This_t  bits)

Sets the specified bits.

template<typename Storage>
static void util::flags::Bits_t< Storage >::setBits ( Storage_t base,
Storage_t  bits 
)
inlinestatic

Returns data with all bits from base and from bits set.

Definition at line 301 of file BitMask.h.

302  { base |= bits; }
template<typename Storage>
void util::flags::Bits_t< Storage >::unset ( This_t  bits)

Unsets the specified bits.

template<typename Storage>
static void util::flags::Bits_t< Storage >::unsetBits ( Storage_t base,
Storage_t  bits 
)
inlinestatic

Returns data with all bits from base, but the ones from bits unset.

Definition at line 310 of file BitMask.h.

311  { onlyBits(base, ~bits); }
static void onlyBits(Storage_t &base, Storage_t bits)
Definition: BitMask.h:306

Member Data Documentation

template<typename Storage>
Storage_t util::flags::Bits_t< Storage >::data = { 0 }

The bits representing all set bits.

Definition at line 201 of file BitMask.h.


The documentation for this struct was generated from the following file: