Add a simple wrapper to call the mixer function
[openal-soft.git] / al / eax / exception.cpp
blob435e74426bc7339bde33c839f4ef0784d1c4ef10
1 #include "config.h"
3 #include "exception.h"
5 #include <cassert>
6 #include <string>
9 EaxException::EaxException(const char *context, const char *message)
10 : std::runtime_error{make_message(context, message)}
13 EaxException::~EaxException() = default;
16 std::string EaxException::make_message(const char *context, const char *message)
18 const auto context_size = (context ? std::string::traits_type::length(context) : 0);
19 const auto has_contex = (context_size > 0);
21 const auto message_size = (message ? std::string::traits_type::length(message) : 0);
22 const auto has_message = (message_size > 0);
24 if (!has_contex && !has_message)
26 return std::string{};
29 static constexpr char left_prefix[] = "[";
30 const auto left_prefix_size = std::string::traits_type::length(left_prefix);
32 static constexpr char right_prefix[] = "] ";
33 const auto right_prefix_size = std::string::traits_type::length(right_prefix);
35 const auto what_size =
37 has_contex ?
38 left_prefix_size + context_size + right_prefix_size :
39 0) +
40 message_size +
43 auto what = std::string{};
44 what.reserve(what_size);
46 if (has_contex)
48 what.append(left_prefix, left_prefix_size);
49 what.append(context, context_size);
50 what.append(right_prefix, right_prefix_size);
53 if (has_message)
55 what.append(message, message_size);
58 return what;