2022-04-25 12:02:45 +08:00
|
|
|
#ifndef EAX_UTILS_INCLUDED
|
|
|
|
#define EAX_UTILS_INCLUDED
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2023-02-04 15:03:54 +08:00
|
|
|
using EaxDirtyFlags = unsigned int;
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
struct EaxAlLowPassParam {
|
2022-04-25 12:02:45 +08:00
|
|
|
float gain;
|
|
|
|
float gain_hf;
|
2022-07-14 23:17:11 +08:00
|
|
|
};
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2023-02-04 15:03:54 +08:00
|
|
|
void eax_log_exception(const char *message) noexcept;
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
template<typename TException, typename TValue>
|
2022-04-25 12:02:45 +08:00
|
|
|
void eax_validate_range(
|
|
|
|
const char* value_name,
|
|
|
|
const TValue& value,
|
|
|
|
const TValue& min_value,
|
|
|
|
const TValue& max_value)
|
|
|
|
{
|
|
|
|
if (value >= min_value && value <= max_value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto message =
|
|
|
|
std::string{value_name} +
|
|
|
|
" out of range (value: " +
|
|
|
|
std::to_string(value) + "; min: " +
|
|
|
|
std::to_string(min_value) + "; max: " +
|
|
|
|
std::to_string(max_value) + ").";
|
|
|
|
|
|
|
|
throw TException{message.c_str()};
|
|
|
|
}
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
namespace detail {
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
template<typename T>
|
|
|
|
struct EaxIsBitFieldStruct {
|
2022-04-25 12:02:45 +08:00
|
|
|
private:
|
|
|
|
using yes = std::true_type;
|
|
|
|
using no = std::false_type;
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
template<typename U>
|
2022-04-25 12:02:45 +08:00
|
|
|
static auto test(int) -> decltype(std::declval<typename U::EaxIsBitFieldStruct>(), yes{});
|
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
template<typename>
|
2022-04-25 12:02:45 +08:00
|
|
|
static no test(...);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr auto value = std::is_same<decltype(test<T>(0)), yes>::value;
|
2022-07-14 23:17:11 +08:00
|
|
|
};
|
2022-04-25 12:02:45 +08:00
|
|
|
|
2022-07-14 23:17:11 +08:00
|
|
|
template<typename T, typename TValue>
|
|
|
|
inline bool eax_bit_fields_are_equal(const T& lhs, const T& rhs) noexcept
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
|
|
|
static_assert(sizeof(T) == sizeof(TValue), "Invalid type size.");
|
|
|
|
return reinterpret_cast<const TValue&>(lhs) == reinterpret_cast<const TValue&>(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
std::enable_if_t<detail::EaxIsBitFieldStruct<T>::value, int> = 0
|
|
|
|
>
|
2022-07-14 23:17:11 +08:00
|
|
|
inline bool operator==(const T& lhs, const T& rhs) noexcept
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
|
|
|
using Value = std::conditional_t<
|
|
|
|
sizeof(T) == 1,
|
|
|
|
std::uint8_t,
|
|
|
|
std::conditional_t<
|
|
|
|
sizeof(T) == 2,
|
|
|
|
std::uint16_t,
|
|
|
|
std::conditional_t<
|
|
|
|
sizeof(T) == 4,
|
|
|
|
std::uint32_t,
|
2022-07-14 23:17:11 +08:00
|
|
|
void>>>;
|
2022-04-25 12:02:45 +08:00
|
|
|
|
|
|
|
static_assert(!std::is_same<Value, void>::value, "Unsupported type.");
|
|
|
|
return detail::eax_bit_fields_are_equal<T, Value>(lhs, rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename T,
|
|
|
|
std::enable_if_t<detail::EaxIsBitFieldStruct<T>::value, int> = 0
|
|
|
|
>
|
2022-07-14 23:17:11 +08:00
|
|
|
inline bool operator!=(const T& lhs, const T& rhs) noexcept
|
2022-04-25 12:02:45 +08:00
|
|
|
{
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !EAX_UTILS_INCLUDED
|