Classes | Namespaces | Typedefs | Functions | Variables
BitMask.h File Reference

Class holding flags. More...

#include <ostream>
#include <string>
#include <exception>
#include "lardataobj/Utilities/BitMask.tcc"

Go to the source code of this file.

Classes

struct  util::flags::details::SmallestUIntType< NBits >
 
struct  util::flags::Flag_t< Storage >
 Type identifying a flag. Operations are implemented as free functions. More...
 
struct  util::flags::Bits_t< Storage >
 Type identifying a set of bits. More...
 
struct  util::flags::errors::Exception
 Base class for exceptions thrown by flag-related utilities. More...
 
struct  util::flags::errors::FlagNotDefined
 Exception thrown to convey that an undefined flag index was tested. More...
 
struct  util::flags::errors::OutOfRange
 Exception thrown to convey that an invalid flag index was used. More...
 
struct  util::flags::BitMaskFromValuesTag
 Type for constructor tag from values. More...
 
class  util::flags::BitMask< Storage >
 A class containing a set of flags. More...
 

Namespaces

 util
 Namespace for general, non-LArSoft-specific utilities.
 
 util::flags
 Classes and functions to manage bit masks and flags.
 
 util::flags::details
 
 util::flags::errors
 Namespace enclosing BitMask exceptions.
 

Typedefs

using util::flags::Index_t = unsigned int
 Type to denote the index of the flag. More...
 
template<unsigned int NBits>
using util::flags::details::smallestUInt_t = typename SmallestUIntType< NBits >::type
 The smallest integral type accommodating NBits bits. More...
 

Functions

template<typename Storage >
constexpr unsigned int util::flags::details::computePages (unsigned int bits)
 Returns the number of Storage variables needed to hold that many bits. More...
 
template<typename Storage >
constexpr Storage util::flags::details::makeBits (Index_t index)
 Returns a set of bits with only the one at the specified index set. More...
 
template<typename Storage >
std::ostream & util::flags::operator<< (std::ostream &out, Flag_t< Storage > flag)
 Output of a flag into a stream (prints its index). More...
 
template<typename Storage >
std::string util::flags::to_string (Flag_t< Storage > const flag)
 Convert a flag into a stream (shows its index). More...
 
template<typename Stream , typename Storage >
Stream & util::flags::operator<< (Stream &&out, BitMask< Storage > const &mask)
 Output of a bit mask into a stream. More...
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::makeMask (Bits_t< Storage > bits)
 Constructs a mask from bits. More...
 
Comparison operators for flags (based on the index)
template<typename Storage >
constexpr bool util::flags::operator== (Index_t left, Flag_t< Storage > right)
 
template<typename Storage >
constexpr bool util::flags::operator== (Flag_t< Storage > left, Index_t right)
 
template<typename Storage >
constexpr bool util::flags::operator!= (Index_t left, Flag_t< Storage > right)
 
template<typename Storage >
constexpr bool util::flags::operator!= (Flag_t< Storage > left, Index_t right)
 
template<typename Storage >
constexpr bool util::flags::operator< (Index_t left, Flag_t< Storage > right)
 
template<typename Storage >
constexpr bool util::flags::operator< (Flag_t< Storage > left, Index_t right)
 
template<typename Storage >
constexpr bool util::flags::operator> (Index_t left, Flag_t< Storage > right)
 
template<typename Storage >
constexpr bool util::flags::operator> (Flag_t< Storage > left, Index_t right)
 
template<typename Storage >
constexpr bool util::flags::operator<= (Index_t left, Flag_t< Storage > right)
 
template<typename Storage >
constexpr bool util::flags::operator<= (Flag_t< Storage > left, Index_t right)
 
template<typename Storage >
constexpr bool util::flags::operator>= (Index_t left, Flag_t< Storage > right)
 
template<typename Storage >
constexpr bool util::flags::operator>= (Flag_t< Storage > left, Index_t right)
 
Flag and bit operations.

Any bitwise operation with a flag returns a Bits_t.

template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator| (Bits_t< Storage > left, Bits_t< Storage > right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator| (Bits_t< Storage > left, typename Bits_t< Storage >::Flag_t right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator| (typename Bits_t< Storage >::Flag_t left, Bits_t< Storage > right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator| (Flag_t< Storage > left, Flag_t< Storage > right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator+ (Bits_t< Storage > left, Bits_t< Storage > right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator+ (Bits_t< Storage > left, typename Bits_t< Storage >::Flag_t right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator+ (typename Bits_t< Storage >::Flag_t left, Bits_t< Storage > right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
template<typename Storage >
constexpr Bits_t< Storage > util::flags::operator+ (Flag_t< Storage > left, Flag_t< Storage > right)
 Returns a new Bits_t with all the bits from both arguments set. More...
 
Flag and mask management

The operations use the first operand as the starting point for the result. The binary operations in this group are:

  • bit-wise OR (equivalent to combineWithMask())
  • bit-wise AND (equivalent to intersectWithMask())
  • addition: the flags of the right operand that are defined are copied into the result
  • subtraction: the flags of the right operand that are set are unset in the result

The unary operations are:

  • bitwise negation (equivalent to negateMask())
  • unary plus sign: no operation (bit it converts the operand to Mask_t)
  • unary minus sign is not defined
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator| (BitMask< Storage > left, BitMask< Storage > right)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator| (BitMask< Storage > left, typename BitMask< Storage >::Bits_t right)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator| (typename BitMask< Storage >::Bits_t left, BitMask< Storage > right)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator& (BitMask< Storage > left, BitMask< Storage > right)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator& (BitMask< Storage > left, typename BitMask< Storage >::Bits_t right)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator& (typename BitMask< Storage >::Bits_t left, BitMask< Storage > right)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator& (Bits_t< Storage > left, Bits_t< Storage > right)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator+ (BitMask< Storage > baseMask, BitMask< Storage > mask)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator+ (BitMask< Storage > baseMask, typename BitMask< Storage >::Bits_t bits)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator+ (typename BitMask< Storage >::Bits_t baseBits, BitMask< Storage > mask)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator- (BitMask< Storage > baseMask, BitMask< Storage > mask)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator- (BitMask< Storage > baseMask, typename BitMask< Storage >::Bits_t bits)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator- (typename BitMask< Storage >::Bits_t baseBits, BitMask< Storage > mask)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator- (Bits_t< Storage > baseBits, Bits_t< Storage > bits)
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator+ (BitMask< Storage > mask)
 Returns a copy of the mask. More...
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator+ (Bits_t< Storage > bits)
 Returns a mask with the specified bits set. More...
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator- (Bits_t< Storage > bits)
 Returns a mask M = -B so that A + M is equivalent to A - B. More...
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator- (Flag_t< Storage > flag)
 Returns a mask M = -B so that A + M is equivalent to A - B. More...
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::operator~ (BitMask< Storage > mask)
 Returns a bit set which unsets the specified bits. More...
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::Set (Flag_t< Storage > flag)
 Returns a bit mask which sets the specified flag. More...
 
template<typename Storage >
constexpr BitMask< Storage > util::flags::Unset (Flag_t< Storage > flag)
 Returns a bit mask which unsets the specified flag. More...
 

Variables

constexpr BitMaskFromValuesTag util::flags::maskFromValues {}
 Value useful for BitMask constructors from value. More...
 

Detailed Description

Class holding flags.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
January 25, 2017
See also
lardataobj/Utilities/FlagSet.h

This pure header defines the template class util::flags::BitMask, which is used in util::flags::FlagSet, and a few auxiliary classes and types (util::flags::Index_t, util::flags::Flag_t).

Definition in file BitMask.h.