14 #ifndef LARDATAOBJ_UTILITIES_BITMASK_H
15 #define LARDATAOBJ_UTILITIES_BITMASK_H
66 template <
unsigned int NBits>
70 template <
unsigned int NBits>
74 template <
typename Storage>
78 template <
typename Storage>
80 {
return Storage(1) << index; }
88 template <
typename Storage>
136 template <
typename Storage>
138 {
return left == right.
index(); }
139 template <
typename Storage>
143 template <
typename Storage>
145 {
return left != right.
index(); }
146 template <
typename Storage>
150 template <
typename Storage>
151 constexpr
bool operator< (Index_t left, Flag_t<Storage>
right)
153 template <
typename Storage>
157 template <
typename Storage>
159 {
return left > right.
index(); }
160 template <
typename Storage>
164 template <
typename Storage>
165 constexpr
bool operator<= (Index_t left, Flag_t<Storage>
right)
167 template <
typename Storage>
171 template <
typename Storage>
173 {
return left >= right.
index(); }
174 template <
typename Storage>
181 template <
typename Storage>
182 std::ostream& operator<< (std::ostream& out, Flag_t<Storage>
flag)
183 { out <<
'[' <<
flag.index() <<
']';
return out; }
186 template <
typename Storage>
193 template <
typename Storage>
204 constexpr
Bits_t() =
default;
325 template <
typename Storage>
326 constexpr Bits_t<Storage>
operator|
327 (Bits_t<Storage>
left, Bits_t<Storage>
right);
330 template <
typename Storage>
331 constexpr Bits_t<Storage>
operator|
332 (Bits_t<Storage>
left,
typename Bits_t<Storage>::Flag_t
right);
335 template <
typename Storage>
336 constexpr Bits_t<Storage>
operator|
337 (
typename Bits_t<Storage>::Flag_t
left, Bits_t<Storage>
right);
340 template <
typename Storage>
341 constexpr Bits_t<Storage>
operator|
342 (Flag_t<Storage>
left, Flag_t<Storage>
right);
345 template <
typename Storage>
346 constexpr Bits_t<Storage>
operator+
347 (Bits_t<Storage>
left, Bits_t<Storage>
right);
350 template <
typename Storage>
351 constexpr Bits_t<Storage>
operator+
352 (Bits_t<Storage>
left,
typename Bits_t<Storage>::Flag_t
right);
355 template <
typename Storage>
356 constexpr Bits_t<Storage>
operator+
357 (
typename Bits_t<Storage>::Flag_t
left, Bits_t<Storage>
right);
360 template <
typename Storage>
361 constexpr Bits_t<Storage>
operator+
362 (Flag_t<Storage>
left, Flag_t<Storage>
right);
419 template <
typename Storage>
466 explicit constexpr
BitMask() =
default;
535 template <
typename... Others>
537 : BitMask(
create(first, others...))
549 template <
typename... Others>
551 : BitMask(
create(first, others...))
568 template <
typename Second,
typename... Others>
570 : BitMask(
create(first, second, others...))
750 template <
typename Flag,
typename... OtherFlags>
764 template <
typename BeginIter,
typename EndIter>
778 template <
typename Flag,
typename... OtherFlags>
792 template <
typename BeginIter,
typename EndIter>
816 template <
typename Flag,
typename... OtherFlags>
817 void remove(Flag
first, OtherFlags... others)
850 template <
typename Stream>
851 void dump(
Stream&& out,
unsigned int nBits)
const;
854 template <
typename Stream>
876 template <
typename... Args>
1159 template <
typename... Flags>
1166 template <
typename... Flags>
1179 template <
typename... Flags>
1187 {
return data & bits; }
1191 {
return (data & mask) ==
mask; }
1195 {
return (data & ~mask) == data; }
1202 template <
typename Stream,
typename Storage>
1204 {
mask.dump(std::forward<Stream>(out));
return out; }
1233 template <
typename Storage>
1234 constexpr BitMask<Storage>
operator|
1235 (BitMask<Storage>
left, BitMask<Storage>
right);
1239 template <
typename Storage>
1240 constexpr BitMask<Storage>
operator|
1241 (BitMask<Storage>
left,
typename BitMask<Storage>::Bits_t
right);
1245 template <
typename Storage>
1246 constexpr BitMask<Storage>
operator|
1247 (
typename BitMask<Storage>::Bits_t
left, BitMask<Storage>
right);
1254 template <
typename Storage>
1255 constexpr BitMask<Storage>
operator&
1256 (BitMask<Storage>
left, BitMask<Storage>
right);
1260 template <
typename Storage>
1261 constexpr BitMask<Storage>
operator&
1262 (BitMask<Storage>
left,
typename BitMask<Storage>::Bits_t
right);
1266 template <
typename Storage>
1267 constexpr BitMask<Storage>
operator&
1268 (
typename BitMask<Storage>::Bits_t
left, BitMask<Storage>
right);
1272 template <
typename Storage>
1273 constexpr BitMask<Storage>
operator&
1274 (Bits_t<Storage>
left, Bits_t<Storage>
right);
1279 template <
typename Storage>
1280 constexpr BitMask<Storage>
operator+
1281 (BitMask<Storage> baseMask, BitMask<Storage>
mask);
1285 template <
typename Storage>
1286 constexpr BitMask<Storage>
operator+
1287 (BitMask<Storage> baseMask,
typename BitMask<Storage>::Bits_t bits);
1291 template <
typename Storage>
1292 constexpr BitMask<Storage>
operator+
1293 (
typename BitMask<Storage>::Bits_t baseBits, BitMask<Storage>
mask);
1300 template <
typename Storage>
1301 constexpr BitMask<Storage>
operator-
1302 (BitMask<Storage> baseMask, BitMask<Storage>
mask);
1306 template <
typename Storage>
1307 constexpr BitMask<Storage>
operator-
1308 (BitMask<Storage> baseMask,
typename BitMask<Storage>::Bits_t bits);
1312 template <
typename Storage>
1313 constexpr BitMask<Storage>
operator-
1314 (
typename BitMask<Storage>::Bits_t baseBits, BitMask<Storage>
mask);
1318 template <
typename Storage>
1319 constexpr BitMask<Storage>
operator-
1320 (Bits_t<Storage> baseBits, Bits_t<Storage> bits);
1324 template <
typename Storage>
1325 constexpr BitMask<Storage>
operator+ (BitMask<Storage>
mask);
1328 template <
typename Storage>
1329 constexpr BitMask<Storage>
operator+ (Bits_t<Storage> bits);
1333 template <
typename Storage>
1334 constexpr BitMask<Storage>
operator- (Bits_t<Storage> bits);
1337 template <
typename Storage>
1338 constexpr BitMask<Storage>
operator- (Flag_t<Storage>
flag);
1342 template <
typename Storage>
1343 constexpr BitMask<Storage>
operator~
1344 (BitMask<Storage>
mask);
1348 template <typename Storage>
1349 constexpr BitMask<Storage> operator~ (Bits_t<Storage> bits);
1354 template <
typename Storage>
1355 constexpr BitMask<Storage>
Set(Flag_t<Storage>
flag);
1358 template <
typename Storage>
1359 constexpr BitMask<Storage>
Unset(Flag_t<Storage>
flag);
1366 template <
typename Storage>
1367 constexpr BitMask<Storage>
makeMask(Bits_t<Storage> bits);
1379 #include "lardataobj/Utilities/BitMask.tcc"
1384 #endif // LARDATAOBJ_UTILITIES_BITMASK_H
typename Bits_t::Flag_t Flag_t
Type identifying a single flag.
Storage_t bits
The bits representing this flag (only one is set)
constexpr unsigned int computePages(unsigned int bits)
Returns the number of Storage variables needed to hold that many bits.
constexpr Bits_t(Flag_t flag)
Constructs from a single flag.
void dump(Stream &&out, unsigned int nBits) const
Prints into the specified stream the least nBits significant bits.
constexpr bool isSet(Flag_t flag) const
Returns if the specified flag is set.
constexpr bool operator==(This_t other) const
constexpr bool match(Mask_t const &mask) const
Returns whether all bits defined in the mask are equal to ours.
typename SmallestUIntType< NBits >::type smallestUInt_t
The smallest integral type accommodating NBits bits.
then echo unknown compiler flag
constexpr bool operator>(Index_t left, Flag_t< Storage > right)
constexpr bool none(Bits_t bits) const
Returns whether all the specified bits are unset.
constexpr bool anySet(Mask_t const &mask) const
Returns whether any of the bits set in the mask are set.
Base class for exceptions thrown by flag-related utilities.
static constexpr size_t capacity()
Returns the number of flags the set has room for.
void defineSingle(Flag_t flag)
Marks a flag as defined. Value is still uninitialised!
FlagNotDefined(std::string msg="Flag undefined-flag error")
Type identifying a flag. Operations are implemented as free functions.
virtual const char * what() const noexceptoverride
static void onlyBits(Storage_t &base, Storage_t bits)
constexpr bool operator>=(This_t other) const
static constexpr auto fromValues
Constructor tag from values.
constexpr Bits_t definedOnly() const
Returns a bit set with all undefined bits unset.
static constexpr Mask_t create(Args...args)
Creates a new BitMask.
void unsetImpl()
Implementation detail of unset()
constexpr bool operator!=(This_t other) const
constexpr bool operator>=(Index_t left, Flag_t< Storage > right)
unsigned int Index_t
Type to denote the index of the flag.
util::flags::Index_t FlagIndex_t
Type of index of flag.
void undefineSingle(Flag_t flag)
Marks a flag as undefined.
void dump(Stream &&out) const
Prints into the specified stream all bits.
void rangeUnset(BeginIter begin, EndIter end)
Unsets all flags specified by the index iterator range.
Type for constructor tag from values.
static constexpr Mask_t negateMask(Mask_t mask)
Returns the negation of mask.
static constexpr bool testUnsetBitmask(Storage_t data, Storage_t mask)
Returns whether all the specified bits in the mask are set.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
static constexpr bool testBits(Storage_t data, Storage_t bits)
Returns whether any of the specified bits is set.
constexpr bool operator>(This_t other) const
constexpr BitMask< Storage > operator-(BitMask< Storage > baseMask, BitMask< Storage > mask)
A class containing a set of flags.
constexpr Storage makeBits(Index_t index)
Returns a set of bits with only the one at the specified index set.
constexpr This_t invert() const
Returns all and only the bits that are not set.
static constexpr Mask_t mergeIntoMask(Mask_t baseMask, Mask_t mask)
Returns a new mask with the content of the other mask merged.
static constexpr Mask_t combineWithMask(Mask_t A, Mask_t B)
Returns a new mask combining bits set from two masks.
constexpr bool empty() const
Returns whether there is no bit set at all.
void unset(This_t bits)
Unsets the specified bits.
constexpr Flag_t(Index_t flagIndex)
Constructs from the flag index.
constexpr mask_t< EnumType > mask(EnumType bit, OtherBits...otherBits)
Returns a mask with all specified bits set.
constexpr bool isUnset(Flag_t flag) const
Returns if the specified flag is unset.
constexpr bool noneSet(Mask_t const &mask) const
Returns whether none of the bits set in the mask is set.
constexpr bool operator!=(Mask_t const &other) const
constexpr bool operator<(This_t other) const
constexpr BitMask< Storage > Set(Flag_t< Storage > flag)
Returns a bit mask which sets the specified flag.
static void setBits(Storage_t &base, Storage_t bits)
Returns data with all bits from base and from bits set.
constexpr bool operator>=(This_t other) const
details::smallestUInt_t< NFlags > Storage_t
Type of underlying bit data representation.
void clear()
Unsets all bits.
constexpr bool only(This_t bits) const
Returns wether no bits are set except (at most) the specified ones.
constexpr bool any(This_t bits) const
Returns wether at least one of the bits is set.
constexpr Bits_t< Storage > operator+(Bits_t< Storage > left, Bits_t< Storage > right)
Returns a new Bits_t with all the bits from both arguments set.
constexpr bool none(This_t bits) const
Returns wether all bits are unset.
static constexpr bool testBitmask(Storage_t data, Storage_t mask)
Returns whether all the specified bits in the mask are set.
constexpr bool operator!=(Index_t left, Flag_t< Storage > right)
constexpr This_t combine(This_t bits) const
Returns our bits, plus the ones present in the argument.
Type identifying a set of bits.
constexpr BitMask< Storage > makeMask(Bits_t< Storage > bits)
Constructs a mask from bits.
BitMask< Storage > Mask_t
This type.
constexpr bool operator==(Index_t left, Flag_t< Storage > right)
constexpr bool any(Bits_t bits) const
Returns whether at least one of the specified bits is set.
constexpr bool operator>(This_t other) const
constexpr BitMask()=default
Default constructor: no flag defined at all.
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not defined
constexpr BitMask(Bits_t first, Others...others)
Constructor: merges all arguments in the argument list.
void unsetSingle(Flag_t flag)
Implementation detail of unset()
constexpr bool all(This_t bits) const
Returns wether all bits are set.
void unset(Flag first, OtherFlags...others)
Unsets all specified flags.
constexpr BitMask(Flag_t first, Others...others)
Constructor: merges all arguments in the argument list.
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
constexpr bool operator==(Mask_t const &other) const
Bits_t< Storage > This_t
This type.
static void unsetBits(Storage_t &base, Storage_t bits)
Returns data with all bits from base, but the ones from bits unset.
std::string to_string(WindowPattern const &pattern)
Exception(std::string msg="Flag error")
util::flags::Flag_t< Storage_t > Flag_t
Type of flag matching our storage.
void keepOnly(This_t bits)
Unsets the bits which are not in bits argument.
Bits_t values
Storage of value bits.
constexpr Bits_t(Storage_t bits)
Constructs from a set of bits.
void setImpl()
Implementation detail of set()
Exception thrown to convey that an invalid flag index was used.
constexpr bool operator<=(This_t other) const
static constexpr Mask_t intersectWithMask(Mask_t A, Mask_t B)
Returns a new mask with the bits set from both masks.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
constexpr bool isDefined(Flag_t flag) const
Returns whether the flag is defined.
constexpr BitMaskFromValuesTag maskFromValues
Value useful for BitMask constructors from value.
Bits_t presence
Storage of definition bits.
void clear()
Undefines all bits.
OutOfRange(std::string msg="Flag out-of-range error")
constexpr This_t select(This_t bits) const
Returns only the bits that are also present in the argument.
void set(This_t bits)
Sets the specified bits.
Storage_t data
The bits representing all set bits.
constexpr Flag_t copy() const
Returns a copy of this object.
constexpr bool operator!=(This_t other) const
void set(Flag first, OtherFlags...others)
Sets all specified flags.
constexpr Index_t index() const
Returns the index of the (first) bit set.
constexpr bool operator==(This_t other) const
Exception thrown to convey that an undefined flag index was tested.
constexpr BitMask< Storage > Unset(Flag_t< Storage > flag)
Returns a bit mask which unsets the specified flag.
void rangeSet(BeginIter begin, EndIter end)
Sets all flags specified by the index iterator range.
constexpr bool all(Bits_t bits) const
Returns whether all the specified bits are set.
constexpr bool isUndefined(Flag_t flag) const
Returns whether the flag is undefined.
constexpr This_t exclude(This_t bits) const
Returns only the bits that are not present in the argument.
void undefineImpl()
Implementation detail of remove()
static constexpr Mask_t unsetMask(Mask_t baseMask, Mask_t mask)
Returns a new mask with the bits set from both masks.
void setSingle(Flag_t flag)
Implementation detail of set()
constexpr bool operator<=(This_t other) const
constexpr bool operator<(This_t other) const
constexpr bool operator!() const
Returns true if there is no bit set.
constexpr Bits_t()=default
Default constructor: no bit set.
constexpr BitMask(Mask_t first, Second second, Others...others)
Constructor: merges all arguments in the argument list.