3 #include <boost/utility/string_view.hpp> 20 template <
class TPOUH,
class KeysT,
class FcnsT,
class ListFcn>
class Resolver {
21 std::string_view type;
27 using O =
typename TPOUH::First;
28 using UH =
typename TPOUH::Second;
31 [[nodiscard]] constexpr std::pair<int, std::string_view> getSearchKey(
const TargetParser& target)
const noexcept {
32 const auto& path_parts = target.getPathParts();
33 if (path_parts.size() < 3)
35 if (path_parts.size() < 4)
36 return {std::numeric_limits<int>::min(), std::string_view{}};
38 const auto path_part = path_parts[2];
39 const auto it =
cexpr::find(skeys.begin(), skeys.end(), path_part);
40 if (it == skeys.end())
41 return {std::numeric_limits<int>::min(), std::string_view{}};
43 const auto idx = std::distance(skeys.begin(), it);
44 return {idx, path_parts[3]};
48 constexpr
Resolver(TPOUH, std::string_view type, KeysT skeys, FcnsT sfcns, ListFcn list_fcn) noexcept
49 : type(type), skeys(skeys), sfcns(sfcns), list_fcn(list_fcn) {}
53 using Ret = std::vector<O>;
54 auto error = [&](
auto... args) {
return hc.json_res.error(args...); };
56 const auto [idx, search_value] = getSearchKey(target);
57 if (search_value.data() ==
nullptr)
58 return error(101), Ret{};
62 if (
auto dom_res = sfcns[idx](hc, search_value); dom_res)
63 ret.emplace_back(std::move(dom_res));
67 const auto flags_opt =
UH{hc}.search_all_flags(target);
69 return error(102), Ret{};
70 const auto flags = *flags_opt;
71 ret = list_fcn(hc, flags);
constexpr Resolver(TPOUH, std::string_view type, KeysT skeys, FcnsT sfcns, ListFcn list_fcn) noexcept
Definition: solver.hpp:48
auto operator()(HandlerContext &hc) const -> std::vector< O >
Definition: solver.hpp:51
typename TPOUH::First O
Definition: solver.hpp:27
Definition: hdl_ctx.hpp:11
constexpr InputIt find(InputIt first, InputIt last, const T &value)
Definition: cexpr_algs.hpp:4
Definition: urlparser.hpp:36
typename TPOUH::Second UH
Definition: solver.hpp:28
Definition: solver.hpp:20