From f796c855274369516c67a98382fff8e55e97d1ef Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 5 Nov 2020 06:35:31 +0100 Subject: [PATCH] util/bitmask: Move bitmask functionality its own file --- CMakeLists.txt | 1 + source/common.hpp | 1 + source/util/util-bitmask.hpp | 61 ++++++++++++++++++++++++++++++++++++ source/util/utility.hpp | 39 ----------------------- 4 files changed, 63 insertions(+), 39 deletions(-) create mode 100644 source/util/util-bitmask.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 886875ed..e4a748f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -712,6 +712,7 @@ list(APPEND PROJECT_PRIVATE_SOURCE "source/plugin.cpp" "source/util/utility.hpp" "source/util/utility.cpp" + "source/util/util-bitmask.hpp" "source/util/util-event.hpp" "source/util/util-library.cpp" "source/util/util-library.hpp" diff --git a/source/common.hpp b/source/common.hpp index 6387b5be..ca74e13d 100644 --- a/source/common.hpp +++ b/source/common.hpp @@ -48,6 +48,7 @@ #include "config.hpp" #include "strings.hpp" #include "version.hpp" +#include "util/util-bitmask.hpp" #include "util/util-library.hpp" #include "util/util-math.hpp" #include "util/util-profiler.hpp" diff --git a/source/util/util-bitmask.hpp b/source/util/util-bitmask.hpp new file mode 100644 index 00000000..fd8d8cba --- /dev/null +++ b/source/util/util-bitmask.hpp @@ -0,0 +1,61 @@ +/* + * Modern effects for a modern Streamer + * Copyright (C) 2020 Michael Fabian Dirks + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ + +#pragma once +#include +#include + +template +struct enable_bitmask_operators { + static const bool enable = false; +}; + +template +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 +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 +typename std::enable_if::enable, bool>::type any(Enum lhs) +{ + using underlying = typename std::underlying_type::type; + return static_cast(lhs) != static_cast(0); +} + +template +typename std::enable_if::enable, bool>::type exact(Enum lhs, Enum rhs) +{ + using underlying = typename std::underlying_type::type; + return static_cast(lhs) == static_cast(rhs); +} + +#define P_ENABLE_BITMASK_OPERATORS(x) \ + template<> \ + struct enable_bitmask_operators { \ + static const bool enable = true; \ + }; diff --git a/source/util/utility.hpp b/source/util/utility.hpp index 8a604aec..85b3256e 100644 --- a/source/util/utility.hpp +++ b/source/util/utility.hpp @@ -48,45 +48,6 @@ extern "C" { const char* obs_module_recursive_text(const char* to_translate, std::size_t depth = std::numeric_limits::max()); -template -struct enable_bitmask_operators { - static const bool enable = false; -}; - -template -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 -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 -typename std::enable_if::enable, bool>::type any(Enum lhs) -{ - using underlying = typename std::underlying_type::type; - return static_cast(lhs) != static_cast(0); -} - -template -typename std::enable_if::enable, bool>::type exact(Enum lhs, Enum rhs) -{ - using underlying = typename std::underlying_type::type; - return static_cast(lhs) == static_cast(rhs); -} - -#define P_ENABLE_BITMASK_OPERATORS(x) \ - template<> \ - struct enable_bitmask_operators { \ - static const bool enable = true; \ - }; - #define D_STR(s) #s #define D_VSTR(s) D_STR(s)