X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fparam.h;h=78d23c2071ed13b5423720dccdbd8523bccbe0eb;hb=0b5b222f19eaa060db90dbe3d2dce1b8d43b816f;hp=ae38d35b164bedc9c01f2b8ec9cb858cd49e3db5;hpb=3f721be92a116e212c954695321475348edd47e7;p=casparcg diff --git a/common/param.h b/common/param.h index ae38d35b1..78d23c207 100644 --- a/common/param.h +++ b/common/param.h @@ -10,12 +10,13 @@ namespace caspar { -class param_comparer { - const std::wstring& lhs; - public: - explicit param_comparer(const std::wstring& p) : lhs(p) {} - bool operator()(const std::wstring& rhs) { return boost::iequals(lhs, rhs); } - }; +class param_comparer +{ + const std::wstring& lhs; +public: + explicit param_comparer(const std::wstring& p) : lhs(p) {} + bool operator()(const std::wstring& rhs) { return boost::iequals(lhs, rhs); } +}; template bool contains_param(const std::wstring& name, C&& params) @@ -23,6 +24,13 @@ bool contains_param(const std::wstring& name, C&& params) return std::find_if(params.begin(), params.end(), param_comparer(name)) != params.end(); } +template +void replace_placeholders(const std::wstring& placeholder, const std::wstring& replacement, C&& params) +{ + for (auto& param : params) + boost::ireplace_all(param, placeholder, replacement); +} + template typename std::enable_if::value, typename std::decay::type>::type get_param(const std::wstring& name, C&& params, T fail_value = T()) { @@ -35,11 +43,11 @@ typename std::enable_if::value, typename s if(++it == params.end()) throw std::out_of_range(""); - return boost::lexical_cast::type>(*it); + return boost::lexical_cast::type>(*it); } catch(...) { - CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Failed to parse param.") << arg_name_info(name) << nested_exception(std::current_exception())); + CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Failed to parse param " + name) << nested_exception(std::current_exception())); } } @@ -59,8 +67,8 @@ std::wstring get_param(const std::wstring& name, C&& params, const std::wstring& } catch(...) { - CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info("Failed to parse param.") << arg_name_info(name) << nested_exception(std::current_exception())); + CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Failed to parse param " + name) << nested_exception(std::current_exception())); } } -} \ No newline at end of file +}