OpenShot Audio Library | OpenShotAudio 0.4.0
juce_EnumHelpers.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23//==============================================================================
52#define JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS(EnumType) \
53 static_assert (std::is_enum_v<EnumType>, \
54 "JUCE_DECLARE_SCOPED_ENUM_BITWISE_OPERATORS " \
55 "should only be used with enum types"); \
56 constexpr auto operator& (EnumType a, EnumType b) \
57 { \
58 using base_type = std::underlying_type<EnumType>::type; \
59 return static_cast<EnumType> (base_type (a) & base_type (b)); \
60 } \
61 constexpr auto operator| (EnumType a, EnumType b) \
62 { \
63 using base_type = std::underlying_type<EnumType>::type; \
64 return static_cast<EnumType> (base_type (a) | base_type (b)); \
65 } \
66 constexpr auto operator~ (EnumType a) \
67 { \
68 using base_type = std::underlying_type<EnumType>::type; \
69 return static_cast<EnumType> (~base_type (a)); \
70 } \
71 constexpr auto& operator|= (EnumType& a, EnumType b) \
72 { \
73 a = (a | b); \
74 return a; \
75 } \
76 constexpr auto& operator&= (EnumType& a, EnumType b) \
77 { \
78 a = (a & b); \
79 return a; \
80 }
81
82
83namespace juce
84{
85
86template <typename EnumType, std::enable_if_t<std::is_enum_v<EnumType>, int> = 0>
87constexpr bool hasBitValueSet (EnumType enumValue, EnumType valueToLookFor) noexcept
88{
89 return (enumValue & valueToLookFor) != EnumType{};
90}
91
92template <typename EnumType, std::enable_if_t<std::is_enum_v<EnumType>, int> = 0>
93constexpr EnumType withBitValueSet (EnumType enumValue, EnumType valueToAdd) noexcept
94{
95 return enumValue | valueToAdd;
96}
97
98template <typename EnumType, std::enable_if_t<std::is_enum_v<EnumType>, int> = 0>
99constexpr EnumType withBitValueCleared (EnumType enumValue, EnumType valueToRemove) noexcept
100{
101 return enumValue & ~valueToRemove;
102}
103}