HerdSoftware  0.1.1
Classes | Macros | Functions
BitMask.h File Reference
#include <bitset>
#include <string>
#include <type_traits>

Go to the source code of this file.

Classes

struct  EnableBitMaskOperators< Enum >
 

Macros

#define ENABLE_BITMASK_OPERATORS(x)   template <> struct EnableBitMaskOperators<x> { static const bool enable = true; };
 Type safe implementation of a bitmask enum. More...
 

Functions

template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator| (const Enum lhs, const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator & (const Enum lhs, const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator^ (const Enum lhs, const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator~ (const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator!= (const Enum lhs, const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator|= (Enum &lhs, const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator &= (Enum &lhs, const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator^= (Enum &lhs, const Enum rhs)
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, bool >::type MatchAnyBit (const Enum test, const Enum ones, const Enum zeroes=static_cast< Enum >(0))
 
template<typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, bool >::type MatchAllBits (const Enum test, const Enum ones, const Enum zeroes=static_cast< Enum >(0))
 
template<int N, typename Enum >
std::enable_if< EnableBitMaskOperators< Enum >::enable, std::string >::type to_string_binary (const Enum rhs)
 

Macro Definition Documentation

◆ ENABLE_BITMASK_OPERATORS

#define ENABLE_BITMASK_OPERATORS (   x)    template <> struct EnableBitMaskOperators<x> { static const bool enable = true; };

Type safe implementation of a bitmask enum.

Adapted form https://wiggling-bits.net/using-enum-classes-as-type-safe-bitmasks/

Function Documentation

◆ MatchAllBits()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, bool>::type MatchAllBits ( const Enum  test,
const Enum  ones,
const Enum  zeroes = static_cast<Enum>(0) 
)

◆ MatchAnyBit()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, bool>::type MatchAnyBit ( const Enum  test,
const Enum  ones,
const Enum  zeroes = static_cast<Enum>(0) 
)

◆ operator &()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator& ( const Enum  lhs,
const Enum  rhs 
)

◆ operator &=()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator&= ( Enum &  lhs,
const Enum  rhs 
)

◆ operator!=()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator!= ( const Enum  lhs,
const Enum  rhs 
)

◆ operator^()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator^ ( const Enum  lhs,
const Enum  rhs 
)

◆ operator^=()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator^= ( Enum &  lhs,
const Enum  rhs 
)

◆ operator|()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator| ( const Enum  lhs,
const Enum  rhs 
)

◆ operator|=()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator|= ( Enum &  lhs,
const Enum  rhs 
)

◆ operator~()

template<typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type operator~ ( const Enum  rhs)

◆ to_string_binary()

template<int N, typename Enum >
std::enable_if<EnableBitMaskOperators<Enum>::enable, std::string>::type to_string_binary ( const Enum  rhs)