virthttp  0.0
libvirt http interface
base.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include "hdl_ctx.hpp"
4 #include "json_utils.hpp"
5 #include "virt_wrap.hpp"
6 
19 template <boost::beast::http::verb... Vs> struct VerbList {
20 
25  constexpr static std::array<boost::beast::http::verb, sizeof...(Vs)> values = {Vs...}; // note: cannot use CTAD because of the empty list case
26 };
27 
34 struct HandlerMethods : public HandlerContext {
35 
44  virtual DependsOutcome create(const rapidjson::Value& obj) = 0;
53  virtual DependsOutcome query(const rapidjson::Value& obj) = 0;
62  virtual DependsOutcome alter(const rapidjson::Value& obj) = 0;
71  virtual DependsOutcome vacuum(const rapidjson::Value& obj) = 0;
72 
77  using Verbs =
84 
85  static_assert(Verbs::values.size() == methods.size());
86 
91  explicit constexpr HandlerMethods(HandlerContext& hc) noexcept : HandlerContext(hc) {}
92 
100  constexpr static long verb_to_idx(boost::beast::http::verb v) noexcept {
101  const auto it = cexpr::find(Verbs::values.begin(), Verbs::values.end(), v);
102  return it != Verbs::values.end() ? std::distance(Verbs::values.begin(), it) : -1;
103  }
104 };
DependsOutcome
Definition: depends.hpp:11
virtual DependsOutcome query(const rapidjson::Value &obj)=0
virtual DependsOutcome alter(const rapidjson::Value &obj)=0
Definition: hdl_ctx.hpp:11
static constexpr std::array< boost::beast::http::verb, sizeof...(Vs)> values
Definition: base.hpp:25
static constexpr long verb_to_idx(boost::beast::http::verb v) noexcept
Definition: base.hpp:100
Definition: base.hpp:19
virtual DependsOutcome create(const rapidjson::Value &obj)=0
Definition: base.hpp:34
constexpr InputIt find(InputIt first, InputIt last, const T &value)
Definition: cexpr_algs.hpp:4
virtual DependsOutcome vacuum(const rapidjson::Value &obj)=0
constexpr HandlerMethods(HandlerContext &hc) noexcept
Definition: base.hpp:91