/* * Copyright (C) Nemirtingas * This file is part of System. * * System is free software; you can redistribute it * and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * System is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with System; if not, see * . */ #pragma once #include namespace System { template struct EnableBitMaskOperators { static constexpr bool enable = false; }; template constexpr typename std::underlying_type::type GetEnumValue(T enum_value) { return static_cast::type>(enum_value); } } template constexpr typename std::enable_if::enable, Enum>::type operator |(Enum lhs, Enum rhs) { using underlying = typename std::underlying_type::type; return static_cast ( static_cast(lhs) | static_cast(rhs) ); } template constexpr typename std::enable_if::enable, Enum>::type operator &(Enum lhs, Enum rhs) { using underlying = typename std::underlying_type::type; return static_cast ( static_cast(lhs) & static_cast(rhs) ); } template constexpr typename std::enable_if::enable, Enum>::type operator ^(Enum lhs, Enum rhs) { using underlying = typename std::underlying_type::type; return static_cast ( static_cast(lhs) ^ static_cast(rhs) ); } template constexpr typename std::enable_if::enable, Enum>::type operator ~(Enum lhs) { using underlying = typename std::underlying_type::type; return static_cast (~static_cast(lhs)); } template constexpr typename std::enable_if::enable, Enum>::type& operator |=(Enum& lhs, Enum rhs) { lhs = lhs | rhs; return lhs; } template constexpr typename std::enable_if::enable, Enum>::type& operator &=(Enum& lhs, Enum rhs) { lhs = lhs & rhs; return lhs; } template constexpr typename std::enable_if::enable, Enum>::type& operator ^=(Enum& lhs, Enum rhs) { lhs = lhs ^ rhs; return lhs; } template constexpr typename std::enable_if::enable, bool>::type operator !(Enum lhs) { using underlying = typename std::underlying_type::type; return !static_cast(lhs); } #define UTILS_ENABLE_BITMASK_OPERATORS(T) \ template<> \ struct System::EnableBitMaskOperators \ { \ static constexpr bool enable = true; \ }