3 #include <boost/beast/http/verb.hpp> 5 #include <rapidjson/document.h> 17 constexpr
static std::array<rapidjson::Type,
sizeof...(Vs)>
values = {Vs...};
46 constexpr
static bool has_one_in_both() noexcept {
47 for (
auto s : singles) {
48 for (
auto r : ranges) {
55 static_assert(!has_one_in_both());
63 gsl::span<const rapidjson::Type> singles;
64 gsl::span<const rapidjson::Type> ranges;
74 template <
class JDV>
explicit constexpr
JDispatch(
const JDV& jdv) noexcept : singles(jdv.singles), ranges(jdv.ranges) {}
85 template <
class Hdl>
auto operator()(
const rapidjson::Value& jval, Hdl&& hdl)
const {
86 return [&,
this, hdl = std::forward<Hdl>(hdl)](
HandlerContext& hc) {
87 const auto jtype = jval.GetType();
88 if (!singles.empty() &&
static_cast<int>(singles[0]) == -1) {
89 return (
void)hdl(jval);
91 if (
cexpr::find(singles.begin(), singles.end(), jtype) != singles.end())
92 return (
void)hdl(jval);
94 if (
cexpr::find(ranges.begin(), ranges.end(), jtype) != ranges.end())
101 template <
class... JDVs, std::size_t... I>
103 constexpr
auto mk_jdisp = [](
const auto& jdv) {
return JDispatch{jdv}; };
104 return std::array{mk_jdisp(std::get<I>(tup))...};
115 template <
class... JDVs> constexpr
auto gen_jdispatchers(
const std::tuple<JDVs...>& tup) noexcept -> std::array<
JDispatch,
sizeof...(JDVs)> {
constexpr auto gen_jdispatchers(const std::tuple< JDVs... > &tup) noexcept-> std::array< JDispatch, sizeof...(JDVs)>
Definition: dispatch.hpp:115
void error(int code)
Definition: json_utils.hpp:57
Definition: dispatch.hpp:62
Definition: dispatch.hpp:16
auto operator()(const rapidjson::Value &jval, Hdl &&hdl) const
Definition: dispatch.hpp:85
constexpr JDispatch(const JDV &jdv) noexcept
Definition: dispatch.hpp:74
Definition: dispatch.hpp:20
Definition: hdl_ctx.hpp:11
void handle_depends(const rapidjson::Value &json_req, JsonRes &json_res, Hdl &&hdl)
Definition: depends.hpp:33
JsonRes & json_res
the result of running the handlers to be sent to the client
Definition: hdl_ctx.hpp:13
static constexpr std::array< rapidjson::Type, sizeof...(Vs)> values
Definition: dispatch.hpp:17
constexpr InputIt find(InputIt first, InputIt last, const T &value)
Definition: cexpr_algs.hpp:4
constexpr auto gen_jdispatchers_impl(const std::tuple< JDVs... > &tup, std::index_sequence< I... >) noexcept-> std::array< JDispatch, sizeof...(JDVs)>
Definition: dispatch.hpp:102