![]() |
boost::taar::handler::constrained — Argument provider wrapper that validates the converted value against constraints.
// In header: <boost/taar/handler/constrained.hpp> template<typename ArgProviderType> struct constrained { // types typedef ArgProviderType arg_provider_type; typedef unspecified arg_provider_request_type; typedef unspecified arg_provider_result_type; // public member functions constrained(arg_provider_type, constraints); std::string name() const; std::string description() const; decltype(auto) operator()(arg_provider_request_type const &, matcher::context const &) const; constraints const & rules() const noexcept; template<typename T> void check(T const &) const; // private member functions void fail(std::string) const; // public data members arg_provider_type arg_provider_; constraints constraints_; std::optional< std::regex > regex_; };
Wraps any REST, JSON-RPC or MCP provider, including one already wrapped in with_default: rest(&list, constrained(with_default(query_arg("page"), 1), {.minimum = 1}))
A violation is thrown as boost::taar::exception carrying error::constraint_violated with a message naming the argument and the rule: 400 on REST, -32602 (invalid params) on JSON-RPC and MCP, the message in data. An absent optional value is not checked.
constrained public member functionsconstrained(arg_provider_type arg_provider, constraints rules);
std::string name() const;
std::string description() const;
decltype(auto) operator()(arg_provider_request_type const & request, matcher::context const & context) const;
constraints const & rules() const noexcept;
template<typename T> void check(T const & value) const;Validate value.
Throws: |
boost::taar::exception with error::constraint_violated, message <name> <rule> (e.g. "page must be >= 1") and data {"argument": name}. |