21 inline std::vector<std::string>
split(
const std::string& s,
char delimiter)
24 std::vector<std::string> tokens;
25 std::istringstream tokenStream(s);
26 while (std::getline(tokenStream, token, delimiter)) {
28 size_t first = token.find_first_not_of(
" \t\n\r");
29 if (std::string::npos != first) {
30 size_t last = token.find_last_not_of(
" \t\n\r");
31 tokens.push_back(token.substr(first, (last - first + 1)));
54 template <
typename... Args>
55 std::string
format_args(
const std::string& names,
const Args&... args)
59 std::vector<std::string> arg_names =
split(names,
',');
63 auto printer = [&](
const auto& arg_value) {
64 if (i < arg_names.size()) {
65 if (i > 0) ss <<
", ";
66 ss << arg_names[i] <<
" = " << arg_value;
78#if defined(__GNUC__) || defined(__clang__)
79#define FUNCTION_NAME __PRETTY_FUNCTION__
80#elif defined(_MSC_VER)
81#define FUNCTION_NAME __FUNCSIG__
83#define FUNCTION_NAME __func__
87#define THROW_ON_INVALID_ARG(condition, ...) \
90 std::stringstream ss; \
91 ss << "\n Condition '" << #condition << "' failed." \
92 << "\n With: " << OscProb::format_args(#__VA_ARGS__, __VA_ARGS__) \
93 << "\n In function: " << FUNCTION_NAME \
94 << "\n At file: " << __FILE__ << "\n At line: " << __LINE__; \
95 throw std::invalid_argument(ss.str()); \
Some useful general definitions.
std::string format_args(const std::string &names, const Args &... args)
The main variadic template function to log the arguments.
std::vector< std::string > split(const std::string &s, char delimiter)
Helper function to split a string by a delimiter.