rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
rexlib::flagset< B > Class Template Reference

Stores a set of bits in the form of flags Similar to std::bitset but instead of a index based interface it provides a enum based interface. More...

#include <rexlib/core/binary/flagset.hpp>

Public Types

using bit_type = B
 The provided enum declaration of the flag bits.
 
using underlying_type = typename std::underlying_type< bit_type >::type
 The underlying type of the provided enum.
 
using unsigned_type = typename std::make_unsigned< underlying_type >::type
 Unsigned underlying type of the provided enum.
 

Public Member Functions

REXLIB_CONSTEXPR flagset () noexcept
 Empty constructor. It initializes the set as none of the flags were set.
 
REXLIB_CONSTEXPR flagset (bit_type bit) noexcept
 Initializes the set with a single bit set.
 
REXLIB_CONSTEXPR flagset (underlying_type data) noexcept
 Constructs the flagset from raw binary data.
 
template<typename It >
REXLIB_CONSTEXPR flagset (It first, It last) noexcept
 Initializes the set with the elements inside the a iterator range.
 
REXLIB_CONSTEXPR flagset (std::initializer_list< bit_type > bits) noexcept
 Initializes the set with a initializer list.
 
 flagset (const flagset &other)=default
 Copy constructor.
 
 flagset (flagset &&other) noexcept=default
 Move constructor. Same behaviour as copy constructor.
 
 ~flagset ()=default
 Destroy the flagset object.
 
flagset & operator= (const flagset &other)=default
 Copy assign operator.
 
flagset & operator= (flagset &&other) noexcept=default
 Move assign operator. Same behaviour as copy constructor.
 
REXLIB_CONSTEXPR operator bool () const noexcept
 Checks if the set is nonzero.
 
REXLIB_CONSTEXPR operator underlying_type () const noexcept
 Converts to the underlying type of the bit definition bits set.
 
REXLIB_CONSTEXPR flagset & operator|= (const flagset &rhs) noexcept
 In-place union with another flagset.
 
REXLIB_CONSTEXPR flagset & operator&= (const flagset &rhs) noexcept
 In-place intersection with another flagset.
 
REXLIB_CONSTEXPR flagset & operator^= (const flagset &rhs) noexcept
 In-place XOR with another flagset.
 
REXLIB_CONSTEXPR underlying_type get_bits () const noexcept
 Obtain the underlying integer representation of the flags.
 
REXLIB_CONSTEXPR bool contains (const bit_type &bit) const noexcept
 Tests if the requested flag is set.
 
REXLIB_CONSTEXPR bool all_of (const flagset &other) const noexcept
 Checks if all of a set of flags are present in this.
 
REXLIB_CONSTEXPR bool any_of (const flagset &other) const noexcept
 Checks if any of a set of flags are present in this.
 
REXLIB_CONSTEXPR bool none_of (const flagset &other) const noexcept
 Checks if none of a set of flags are present in this.
 
REXLIB_CONSTEXPR bool only_of (const flagset &other) const noexcept
 Checks if only a set of flags are present in this.
 
REXLIB_CONSTEXPR int count () const noexcept
 Counts the number of flags that are present.
 
REXLIB_CONSTEXPR bool parity () const noexcept
 Computes the parity of the stored flags.
 
REXLIB_CONSTEXPR bool has_single_bit () const noexcept
 Checks if only one flag is present.
 
REXLIB_CONSTEXPR flagset & set (const flagset &other, bool value) noexcept
 Set a particular set of flags to the desired value.
 
REXLIB_CONSTEXPR flagset & set (const flagset &other) noexcept
 Sets a particular set of flags.
 
REXLIB_CONSTEXPR flagset & clear () noexcept
 Clears all flags.
 
REXLIB_CONSTEXPR flagset & clear (const flagset &other) noexcept
 Clears a particular set of flags.
 
REXLIB_CONSTEXPR flagset & toggle (const flagset &other) noexcept
 Toggles a particular set of flags.
 

Friends

REXLIB_CONSTEXPR bool operator== (const flagset &lhs, const flagset &rhs) noexcept
 Compares for equality with another flagset.
 
REXLIB_CONSTEXPR bool operator!= (const flagset &lhs, const flagset &rhs) noexcept
 Compares for inequality with another flagset.
 
REXLIB_CONSTEXPR flagset operator| (const flagset &lhs, const flagset &rhs) noexcept
 
REXLIB_CONSTEXPR flagset operator& (const flagset &lhs, const flagset &rhs) noexcept
 
REXLIB_CONSTEXPR flagset operator^ (const flagset &lhs, const flagset &rhs) noexcept
 

Detailed Description

template<typename B>
class rexlib::flagset< B >

Stores a set of bits in the form of flags Similar to std::bitset but instead of a index based interface it provides a enum based interface.

Template Parameters
Benum type which contains the declaration of the flag bits

Constructor & Destructor Documentation

◆ flagset() [1/6]

template<typename B >
REXLIB_CONSTEXPR rexlib::flagset< B >::flagset ( bit_type  bit)
noexcept

Initializes the set with a single bit set.

Parameters
bitThe bit to be set

◆ flagset() [2/6]

template<typename B >
REXLIB_CONSTEXPR rexlib::flagset< B >::flagset ( underlying_type  data)
explicitnoexcept

Constructs the flagset from raw binary data.

Parameters
dataThe binary data

◆ flagset() [3/6]

template<typename B >
template<typename It >
REXLIB_CONSTEXPR rexlib::flagset< B >::flagset ( It  first,
It  last 
)
noexcept

Initializes the set with the elements inside the a iterator range.

Template Parameters
Itforward iterator
Parameters
firstIterator to the first element
lastIterator to the past the end element

◆ flagset() [4/6]

template<typename B >
REXLIB_CONSTEXPR rexlib::flagset< B >::flagset ( std::initializer_list< bit_type >  bits)
noexcept

Initializes the set with a initializer list.

Parameters
bitsInitializer list with the flags to be set

◆ flagset() [5/6]

template<typename B >
rexlib::flagset< B >::flagset ( const flagset< B > &  other)
default

Copy constructor.

Parameters
otherThe set to be copied from

◆ flagset() [6/6]

template<typename B >
rexlib::flagset< B >::flagset ( flagset< B > &&  other)
defaultnoexcept

Move constructor. Same behaviour as copy constructor.

Parameters
otherThe set to be copied from

Member Function Documentation

◆ all_of()

template<typename B >
REXLIB_CONSTEXPR bool rexlib::flagset< B >::all_of ( const flagset< B > &  other) const
noexcept

Checks if all of a set of flags are present in this.

Parameters
otherThe set of flags that needs to be present here
Returns
true If all the flags are present
false If all the flags are not present

◆ any_of()

template<typename B >
REXLIB_CONSTEXPR bool rexlib::flagset< B >::any_of ( const flagset< B > &  other) const
noexcept

Checks if any of a set of flags are present in this.

Parameters
otherThe set of flags that needs to be present here
Returns
true If any the flags are present
false If any the flags are not present

◆ clear() [1/2]

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::clear ( )
noexcept

Clears all flags.

Returns
flagset& *this

◆ clear() [2/2]

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::clear ( const flagset< B > &  other)
noexcept

Clears a particular set of flags.

Parameters
otherThe set of flags to be cleared
Returns
flagset& *this

◆ contains()

template<typename B >
REXLIB_CONSTEXPR bool rexlib::flagset< B >::contains ( const bit_type &  bit) const
noexcept

Tests if the requested flag is set.

Parameters
bitThe flag to be tested.
Returns
true If the bit is set.
false If the bit is not set.

◆ count()

template<typename B >
REXLIB_CONSTEXPR int rexlib::flagset< B >::count ( ) const
noexcept

Counts the number of flags that are present.

Returns
int The number of flags present here

◆ get_bits()

template<typename B >
REXLIB_CONSTEXPR underlying_type rexlib::flagset< B >::get_bits ( ) const
noexcept

Obtain the underlying integer representation of the flags.

Returns
underlying_type Unsigned integer with the data.

◆ has_single_bit()

template<typename B >
REXLIB_CONSTEXPR bool rexlib::flagset< B >::has_single_bit ( ) const
noexcept

Checks if only one flag is present.

Returns
true if only one flag is present
false if zero or more than one flags are present

◆ none_of()

template<typename B >
REXLIB_CONSTEXPR bool rexlib::flagset< B >::none_of ( const flagset< B > &  other) const
noexcept

Checks if none of a set of flags are present in this.

Parameters
otherThe set of flags that needs to be absent here
Returns
true If none the flags are present
false If any the flags are is present

◆ only_of()

template<typename B >
REXLIB_CONSTEXPR bool rexlib::flagset< B >::only_of ( const flagset< B > &  other) const
noexcept

Checks if only a set of flags are present in this.

Parameters
otherThe set of allowed flags
Returns
true If only the allowed flags are present
false If any of the disallowed flags is present

◆ operator bool()

template<typename B >
REXLIB_CONSTEXPR rexlib::flagset< B >::operator bool ( ) const
noexcept

Checks if the set is nonzero.

Returns
true If there is one or more bits set
false If there are no bits set

◆ operator underlying_type()

template<typename B >
REXLIB_CONSTEXPR rexlib::flagset< B >::operator underlying_type ( ) const
explicitnoexcept

Converts to the underlying type of the bit definition bits set.

Returns
underlying_type

◆ operator&=()

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::operator&= ( const flagset< B > &  rhs)
noexcept

In-place intersection with another flagset.

Parameters
rhsThe other flagset
Returns
flagset& *this

◆ operator=() [1/2]

template<typename B >
flagset & rexlib::flagset< B >::operator= ( const flagset< B > &  other)
default

Copy assign operator.

Parameters
otherThe set to be copied from
Returns
flagset& *this

◆ operator=() [2/2]

template<typename B >
flagset & rexlib::flagset< B >::operator= ( flagset< B > &&  other)
defaultnoexcept

Move assign operator. Same behaviour as copy constructor.

Parameters
otherThe set to be copied from
Returns
flagset& *this

◆ operator^=()

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::operator^= ( const flagset< B > &  rhs)
noexcept

In-place XOR with another flagset.

Parameters
rhsThe other flagset
Returns
flagset& *this

◆ operator|=()

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::operator|= ( const flagset< B > &  rhs)
noexcept

In-place union with another flagset.

Parameters
rhsThe other flagset
Returns
flagset& *this

◆ parity()

template<typename B >
REXLIB_CONSTEXPR bool rexlib::flagset< B >::parity ( ) const
noexcept

Computes the parity of the stored flags.

Returns
true when the number of flags is odd
false when the number of flags is even

◆ set() [1/2]

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::set ( const flagset< B > &  other)
noexcept

Sets a particular set of flags.

Parameters
otherThe set of flags to be set
Returns
flagset& *this

◆ set() [2/2]

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::set ( const flagset< B > &  other,
bool  value 
)
noexcept

Set a particular set of flags to the desired value.

Parameters
otherThe set of flags to be changed
valueThe value of the flags
Returns
flagset& *this

◆ toggle()

template<typename B >
REXLIB_CONSTEXPR flagset & rexlib::flagset< B >::toggle ( const flagset< B > &  other)
noexcept

Toggles a particular set of flags.

Parameters
otherThe set of flags to be toggled
Returns
flagset& *this

Friends And Related Symbol Documentation

◆ operator!=

template<typename B >
REXLIB_CONSTEXPR bool operator!= ( const flagset< B > &  lhs,
const flagset< B > &  rhs 
)
friend

Compares for inequality with another flagset.

Parameters
lhsOne flagset
rhsThe other flagset
Returns
true If both flagset-s are not equal
false If both flagset-s are equal

◆ operator==

template<typename B >
REXLIB_CONSTEXPR bool operator== ( const flagset< B > &  lhs,
const flagset< B > &  rhs 
)
friend

Compares for equality with another flagset.

Parameters
lhsOne flagset
rhsThe other flagset
Returns
true If both flagset-s are equal
false If both flagset-s are not equal

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