#pragma once #include "baserule.hpp" #include "dynamicrule.hpp" #include "ruleparametertraits.hpp" #include #include #include #include namespace crow { template class TaggedRule : public BaseRule, public RuleParameterTraits> { public: using self_t = TaggedRule; explicit TaggedRule(const std::string& ruleIn) : BaseRule(ruleIn) {} void validate() override { if (!handler) { throw std::runtime_error("no handler for url " + rule); } } template void operator()(Func&& f) { static_assert( black_magic::CallHelper< Func, black_magic::S&, Args...>>::value, "Handler type is mismatched with URL parameters"); static_assert( std::is_same< void, decltype(f(std::declval(), std::declval&>(), std::declval()...))>::value, "Handler function with response argument should have void return type"); handler = std::forward(f); } void handle(const Request& req, const std::shared_ptr& asyncResp, const std::vector& params) override { detail::routing_handler_call_helper::Call< detail::routing_handler_call_helper::CallParams, 0, black_magic::S, black_magic::S<>>()( detail::routing_handler_call_helper::CallParams{ handler, params, req, asyncResp}); } private: std::function&, Args...)> handler; }; } // namespace crow