68 lines
1.6 KiB
C
68 lines
1.6 KiB
C
|
#pragma once
|
||
|
|
||
|
#include <iostream>
|
||
|
|
||
|
namespace SHADE
|
||
|
{
|
||
|
template<typename BitType>
|
||
|
class SHEnumWrapper
|
||
|
{
|
||
|
public:
|
||
|
using UnderlyingType = typename std::underlying_type_t<BitType>;
|
||
|
|
||
|
private:
|
||
|
UnderlyingType mask;
|
||
|
|
||
|
public:
|
||
|
|
||
|
constexpr SHEnumWrapper(void) noexcept
|
||
|
: mask{ 0 }
|
||
|
{
|
||
|
|
||
|
};
|
||
|
|
||
|
constexpr SHEnumWrapper(BitType bit) noexcept
|
||
|
: mask{ static_cast<UnderlyingType>(bit) }
|
||
|
{
|
||
|
|
||
|
};
|
||
|
|
||
|
constexpr SHEnumWrapper(SHEnumWrapper<BitType> const& rhs) noexcept = default;
|
||
|
constexpr SHEnumWrapper& operator= (SHEnumWrapper<BitType> const& rhs) noexcept = default;
|
||
|
|
||
|
constexpr explicit SHEnumWrapper(UnderlyingType flags) noexcept
|
||
|
: mask{ flags }
|
||
|
{
|
||
|
|
||
|
};
|
||
|
|
||
|
constexpr SHEnumWrapper<BitType> operator| (SHEnumWrapper<BitType> const& rhs) const noexcept
|
||
|
{
|
||
|
return static_cast<SHEnumWrapper<BitType>> (mask | rhs.mask);
|
||
|
};
|
||
|
|
||
|
constexpr SHEnumWrapper<BitType> operator& (SHEnumWrapper<BitType> const& rhs) const noexcept
|
||
|
{
|
||
|
return static_cast<SHEnumWrapper<BitType>> (mask & rhs.mask);
|
||
|
};
|
||
|
|
||
|
constexpr operator UnderlyingType() const noexcept
|
||
|
{
|
||
|
return mask;
|
||
|
};
|
||
|
};
|
||
|
|
||
|
template<typename BitType, typename = std::enable_if_t<std::is_enum_v<BitType>>>
|
||
|
inline BitType operator|(const BitType& left, const BitType& right)
|
||
|
{
|
||
|
return static_cast<BitType>(static_cast<int>(left) | static_cast<int>(right));
|
||
|
}
|
||
|
|
||
|
template<typename BitType, typename = std::enable_if_t<std::is_enum_v<BitType>>>
|
||
|
inline BitType operator&(const BitType& left, const BitType& right)
|
||
|
{
|
||
|
return static_cast<BitType>(static_cast<int>(left) & static_cast<int>(right));
|
||
|
}
|
||
|
|
||
|
}
|