Remove unused atomic_invflag
[openal-soft.git] / al / eax_utils.h
blobd3d4a19606477a4d135ebb742c7b687e2ed9adcc
1 #ifndef EAX_UTILS_INCLUDED
2 #define EAX_UTILS_INCLUDED
4 #include <algorithm>
5 #include <cstdint>
6 #include <string>
7 #include <type_traits>
10 struct EaxAlLowPassParam
12 float gain;
13 float gain_hf;
14 }; // EaxAlLowPassParam
17 void eax_log_exception(
18 const char* message = nullptr) noexcept;
21 template<
22 typename TException,
23 typename TValue
25 void eax_validate_range(
26 const char* value_name,
27 const TValue& value,
28 const TValue& min_value,
29 const TValue& max_value)
31 if (value >= min_value && value <= max_value)
33 return;
36 const auto message =
37 std::string{value_name} +
38 " out of range (value: " +
39 std::to_string(value) + "; min: " +
40 std::to_string(min_value) + "; max: " +
41 std::to_string(max_value) + ").";
43 throw TException{message.c_str()};
47 namespace detail
51 template<
52 typename T
54 struct EaxIsBitFieldStruct
56 private:
57 using yes = std::true_type;
58 using no = std::false_type;
60 template<
61 typename U
63 static auto test(int) -> decltype(std::declval<typename U::EaxIsBitFieldStruct>(), yes{});
65 template<
66 typename
68 static no test(...);
71 public:
72 static constexpr auto value = std::is_same<decltype(test<T>(0)), yes>::value;
73 }; // EaxIsBitFieldStruct
76 template<
77 typename T,
78 typename TValue
80 inline bool eax_bit_fields_are_equal(
81 const T& lhs,
82 const T& rhs) noexcept
84 static_assert(sizeof(T) == sizeof(TValue), "Invalid type size.");
86 return reinterpret_cast<const TValue&>(lhs) == reinterpret_cast<const TValue&>(rhs);
90 } // namespace detail
93 template<
94 typename T,
95 std::enable_if_t<detail::EaxIsBitFieldStruct<T>::value, int> = 0
97 inline bool operator==(
98 const T& lhs,
99 const T& rhs) noexcept
101 using Value = std::conditional_t<
102 sizeof(T) == 1,
103 std::uint8_t,
104 std::conditional_t<
105 sizeof(T) == 2,
106 std::uint16_t,
107 std::conditional_t<
108 sizeof(T) == 4,
109 std::uint32_t,
110 void
115 static_assert(!std::is_same<Value, void>::value, "Unsupported type.");
117 return detail::eax_bit_fields_are_equal<T, Value>(lhs, rhs);
120 template<
121 typename T,
122 std::enable_if_t<detail::EaxIsBitFieldStruct<T>::value, int> = 0
124 inline bool operator!=(
125 const T& lhs,
126 const T& rhs) noexcept
128 return !(lhs == rhs);
132 #endif // !EAX_UTILS_INCLUDED