Flow123d  3.9.0-094ba6f5a
Classes | Public Member Functions | Static Public Attributes | Private Types | Private Attributes | Friends | List of all members
FlagArray< Tag, Size > Class Template Reference

std::bitset with generalized mask mechanism. More...

#include <flag_array.hh>

Collaboration diagram for FlagArray< Tag, Size >:
Collaboration graph
[legend]

Classes

class  Mask
 

Public Member Functions

 FlagArray ()
 Default constructor turns all flags off. More...
 
 FlagArray (Mask mask)
 Conversion from the mask. More...
 
constexpr bool match (Mask mask) const
 
FlagArrayadd (Mask mask)
 

Static Public Attributes

static const unsigned int size = Size
 Allocated size of flags storage. More...
 
static constexpr Mask all_true_mask =Mask(~BitField(0), ~BitField(0))
 
static constexpr Mask all_false_mask =Mask(~BitField(0), BitField(0))
 
static constexpr Mask none_mask =Mask(0, 0)
 

Private Types

typedef unsigned int BitField
 Declaration of internal bitfield type. More...
 

Private Attributes

BitField flags_
 flags storage More...
 

Friends

constexpr friend bool operator== (FlagArray left, FlagArray right)
 
bool operator!= (FlagArray left, FlagArray right)
 
std::ostream & operator<< (std::ostream &s, const FlagArray &f)
 

Detailed Description

template<class Tag, int Size = 32>
class FlagArray< Tag, Size >

std::bitset with generalized mask mechanism.

The drawback of classical bitfield technique implemented e.g. in std::bitset<> is problematic work (set and test) with more bits then one at time. This class is simple wrapper for std::bitset<> that provides public class FlagArray<..>::Mask that represents some bit subset together with a reference value which can be used to set the bit subset or to test the bit subset.

The class is meant to be used in several other classes, that can define their specific masks. Every class using the FlagArray should provide specific Tag template parameter in order to guarantee Mask - FlagArray compatibility.

Implementation note: since std::bitset do not have constexpr operators (may be in c++1y) we currently use just unsigned int in our implementation.

Usage:

class FlagsUser {
public:
static constexpr
};

Definition at line 48 of file flag_array.hh.

Member Typedef Documentation

◆ BitField

template<class Tag , int Size = 32>
typedef unsigned int FlagArray< Tag, Size >::BitField
private

Declaration of internal bitfield type.

Definition at line 52 of file flag_array.hh.

Constructor & Destructor Documentation

◆ FlagArray() [1/2]

template<class Tag , int Size = 32>
FlagArray< Tag, Size >::FlagArray ( )
inline

Default constructor turns all flags off.

Definition at line 139 of file flag_array.hh.

◆ FlagArray() [2/2]

template<class Tag , int Size = 32>
FlagArray< Tag, Size >::FlagArray ( Mask  mask)
inline

Conversion from the mask.

Definition at line 144 of file flag_array.hh.

Member Function Documentation

◆ add()

template<class Tag , int Size = 32>
FlagArray& FlagArray< Tag, Size >::add ( Mask  mask)
inline

Apply the mask to the flags. Bits by the mask.mask_ are overwritten by the mask.set_ values.

Definition at line 170 of file flag_array.hh.

Here is the caller graph for this function:

◆ match()

template<class Tag , int Size = 32>
constexpr bool FlagArray< Tag, Size >::match ( Mask  mask) const
inlineconstexpr

The FlagArray match a mask if and only if bits given by the mask.mask_ are same in both the flags_ and mask.set_.

Definition at line 163 of file flag_array.hh.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

template<class Tag , int Size = 32>
bool operator!= ( FlagArray< Tag, Size >  left,
FlagArray< Tag, Size >  right 
)
friend

Definition at line 154 of file flag_array.hh.

◆ operator<<

template<class Tag , int Size = 32>
std::ostream& operator<< ( std::ostream &  s,
const FlagArray< Tag, Size > &  f 
)
friend

Definition at line 173 of file flag_array.hh.

◆ operator==

template<class Tag , int Size = 32>
constexpr friend bool operator== ( FlagArray< Tag, Size >  left,
FlagArray< Tag, Size >  right 
)
friend

Definition at line 150 of file flag_array.hh.

Member Data Documentation

◆ all_false_mask

template<class Tag , int Size = 32>
constexpr Mask FlagArray< Tag, Size >::all_false_mask =Mask(~BitField(0), BitField(0))
staticconstexpr

Definition at line 132 of file flag_array.hh.

◆ all_true_mask

template<class Tag , int Size = 32>
constexpr Mask FlagArray< Tag, Size >::all_true_mask =Mask(~BitField(0), ~BitField(0))
staticconstexpr

Definition at line 131 of file flag_array.hh.

◆ flags_

template<class Tag , int Size = 32>
BitField FlagArray< Tag, Size >::flags_
private

flags storage

Definition at line 179 of file flag_array.hh.

◆ none_mask

template<class Tag , int Size = 32>
constexpr Mask FlagArray< Tag, Size >::none_mask =Mask(0, 0)
staticconstexpr

Definition at line 133 of file flag_array.hh.

◆ size

template<class Tag , int Size = 32>
const unsigned int FlagArray< Tag, Size >::size = Size
static

Allocated size of flags storage.

Definition at line 129 of file flag_array.hh.


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