2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2020-11-05 05:35:31 +00:00
|
|
|
|
|
|
|
#pragma once
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
2020-11-05 05:35:31 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <type_traits>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2020-11-05 05:35:31 +00:00
|
|
|
|
|
|
|
template<typename Enum>
|
|
|
|
struct enable_bitmask_operators {
|
|
|
|
static const bool enable = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Enum>
|
|
|
|
typename std::enable_if<enable_bitmask_operators<Enum>::enable, Enum>::type operator|(Enum lhs, Enum rhs)
|
|
|
|
{
|
|
|
|
using underlying = typename std::underlying_type<Enum>::type;
|
|
|
|
return static_cast<Enum>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Enum>
|
|
|
|
typename std::enable_if<enable_bitmask_operators<Enum>::enable, Enum>::type operator&(Enum lhs, Enum rhs)
|
|
|
|
{
|
|
|
|
using underlying = typename std::underlying_type<Enum>::type;
|
|
|
|
return static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Enum>
|
|
|
|
typename std::enable_if<enable_bitmask_operators<Enum>::enable, bool>::type any(Enum lhs)
|
|
|
|
{
|
|
|
|
using underlying = typename std::underlying_type<Enum>::type;
|
|
|
|
return static_cast<underlying>(lhs) != static_cast<underlying>(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Enum>
|
|
|
|
typename std::enable_if<enable_bitmask_operators<Enum>::enable, bool>::type exact(Enum lhs, Enum rhs)
|
|
|
|
{
|
|
|
|
using underlying = typename std::underlying_type<Enum>::type;
|
|
|
|
return static_cast<underlying>(lhs) == static_cast<underlying>(rhs);
|
|
|
|
}
|
|
|
|
|
2021-04-26 02:19:45 +00:00
|
|
|
template<typename Enum>
|
|
|
|
typename std::enable_if<enable_bitmask_operators<Enum>::enable, bool>::type has(Enum lhs, Enum rhs)
|
|
|
|
{
|
|
|
|
using underlying = typename std::underlying_type<Enum>::type;
|
|
|
|
return (lhs & rhs) == rhs;
|
|
|
|
}
|
|
|
|
|
2020-11-05 05:35:31 +00:00
|
|
|
#define P_ENABLE_BITMASK_OPERATORS(x) \
|
|
|
|
template<> \
|
|
|
|
struct enable_bitmask_operators<x> { \
|
|
|
|
static const bool enable = true; \
|
|
|
|
};
|