Types - Helper for enum-based flags
This commit is contained in:
parent
3adfdadd11
commit
82fc8406b3
2 changed files with 186 additions and 0 deletions
include/ebcl/inline
|
@ -8,6 +8,151 @@
|
|||
namespace ebcl {
|
||||
|
||||
|
||||
/*= FLAGS HELPER =============================================================*/
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S >::T_Flags( ) noexcept
|
||||
: flags_( 0 )
|
||||
{ }
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S >::T_Flags(
|
||||
T_Flags< E , S > const& other ) noexcept
|
||||
: flags_( other.flags_ )
|
||||
{ }
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S >::T_Flags(
|
||||
const E flag ) noexcept
|
||||
: flags_( 1 << int( flag ) )
|
||||
{ }
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S >::T_Flags(
|
||||
std::initializer_list< E > flags ) noexcept
|
||||
: flags_( 0 )
|
||||
{
|
||||
for ( auto f : flags ) {
|
||||
flags_ |= ( 1 << int( f ) );
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S >::T_Flags(
|
||||
const S flags ) noexcept
|
||||
: flags_( flags )
|
||||
{ }
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S > T_Flags< E , S >::operator |=(
|
||||
const T_Flags< E , S > other ) noexcept
|
||||
{
|
||||
flags_ |= other.flags_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S > T_Flags< E , S >::operator &=(
|
||||
const T_Flags< E , S > other ) noexcept
|
||||
{
|
||||
flags_ &= other.flags_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S > T_Flags< E , S >::operator ^=(
|
||||
const T_Flags< E , S > other ) noexcept
|
||||
{
|
||||
flags_ ^= other.flags_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags<E , S > T_Flags< E , S >::operator ~( ) const noexcept
|
||||
{
|
||||
return T_Flags( ~flags_ );
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S > T_Flags< E , S >::operator &(
|
||||
const T_Flags< E , S > other ) const noexcept
|
||||
{
|
||||
return T_Flags( flags_ & other.flags_ );
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S > T_Flags< E , S >::operator |(
|
||||
const T_Flags< E , S > other ) const noexcept
|
||||
{
|
||||
return T_Flags( flags_ | other.flags_ );
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S > T_Flags< E , S >::operator ^(
|
||||
const T_Flags< E , S > other ) const noexcept
|
||||
{
|
||||
return T_Flags( flags_ ^ other.flags_ );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S >::operator bool( ) const noexcept
|
||||
{
|
||||
return flags_ != 0;
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr bool T_Flags< E , S >::operator!( ) const noexcept
|
||||
{
|
||||
return flags_ == 0;
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr T_Flags< E , S >::operator S( ) const noexcept
|
||||
{
|
||||
return flags_;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr bool T_Flags< E , S >::operator ==(
|
||||
const T_Flags< E , S > other ) const noexcept
|
||||
{
|
||||
return flags_ == other.flags_;
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr bool T_Flags< E , S >::operator !=(
|
||||
const T_Flags< E , S > other ) const noexcept
|
||||
{
|
||||
return flags_ != other.flags_;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr bool T_Flags< E , S >::isSet(
|
||||
const T_Flags< E , S > value ) const noexcept
|
||||
{
|
||||
return ( *this & value ) == value;
|
||||
}
|
||||
|
||||
template< typename E , typename S >
|
||||
inline constexpr bool T_Flags< E , S >::isClear(
|
||||
const T_Flags< E , S > value ) const noexcept
|
||||
{
|
||||
return !( *this & value );
|
||||
}
|
||||
|
||||
|
||||
/*= VARIANT TYPE =============================================================*/
|
||||
|
||||
template< typename T >
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue