21 template<
typename... Args>
34 using ElementT =
typename std::decay<T>::type;
38 std::vector<char> data =
data_;
42 element.write(builder);
58 template<
typename... Args>
63 template<
typename Arg,
typename... Args>
66 using ElementT =
typename std::decay<Arg>::type;
71 element.write(builder);
82 builder.start_array(element.write_size());
83 element.write(builder);
84 builder.finish_array();
103 template<
typename Callback>
108 template<
typename... Args>
130 static auto test(T *) ->
typename T::is_form_element_t;
133 static std::false_type
test(...);
141 template<
typename Derived, Elements element>
146 static constexpr
auto type = element;
148 static constexpr
size_t write_size() {
return 3 + Derived::write_size_(); }
155 builder.
write(
static_cast<typename std::underlying_type<Elements>::type
>(
type));
157 static_cast<Derived &
>(*this).write_(builder);
177 static_assert(std::is_same_v<std::decay_t<T>, T>);
183 static inline constexpr
bool is_callback = std::is_invocable_v<T>;
221 builder.
write(has_def_);
229 template<
typename T, Elements element>
245 template<
typename T, Elements element>
251 interactive_(interactive)
257 interactive_(interactive)
268 builder.
write(interactive_);
277 #define MAKE_DATA_INPUT_HELPER(DATAT, ELEMENT, FNAME) \
278 inline details::FormDataInput<DATAT, ELEMENT> FNAME(const std::string & name, bool required) \
280 return {name, required}; \
283 template<typename T = DATAT> \
284 inline auto FNAME(const std::string & name, bool required, T value) \
286 if constexpr(std::is_invocable_v<T>) { return details::FormDataInput<T, ELEMENT>{name, required, value}; } \
289 if constexpr(std::is_same_v<std::decay_t<T>, DATAT>) \
291 return details::FormDataInput<DATAT, ELEMENT>{name, required, value}; \
293 else { return details::FormDataInput<DATAT, ELEMENT>{name, required, DATAT{value}}; } \
297 #define MAKE_INTERACTIVE_DATA_INPUT_HELPER(DATAT, ELEMENT, FNAME) \
298 inline details::FormInteractiveDataInput<DATAT, ELEMENT> FNAME(const std::string & name, bool required, \
299 bool interactive = true) \
301 return {name, required, interactive}; \
304 template<typename T = DATAT, typename = std::enable_if_t<!std::is_same_v<T, bool>>> \
305 inline auto FNAME(const std::string & name, bool required, T value, bool interactive = true) \
307 if constexpr(std::is_invocable_v<T>) \
309 return details::FormInteractiveDataInput<T, ELEMENT>{name, required, value, interactive}; \
313 if constexpr(std::is_same_v<std::decay_t<T>, DATAT>) \
315 return details::FormInteractiveDataInput<DATAT, ELEMENT>{name, required, value, interactive}; \
317 else { return details::FormInteractiveDataInput<DATAT, ELEMENT>{name, required, DATAT{value}, interactive}; } \
329 #undef MAKE_DATA_INPUT_HELPER
330 #undef MAKE_INTERACTIVE_DATA_INPUT_HELPER
340 const std::vector<std::string> & labels,
342 bool fixed_size =
true)
344 has_def_(
true), labels_(labels)
350 const std::vector<std::string> & labels = {},
351 bool fixed_size =
false)
364 builder.
write(fixed_size_);
365 builder.
write(has_def_);
366 builder.
write(labels_);
373 std::vector<std::string> labels_;
382 return {name, required, Labels::labels, fixed_size};
386 auto FormArrayInput(
const std::string & name,
bool required, T && value,
bool fixed_size =
true)
388 if constexpr(std::is_invocable_v<T>)
390 using DataT = std::decay_t<decltype(std::declval<T>()())>;
396 using DataT = std::decay_t<T>;
406 const std::vector<std::string> & values,
407 bool send_index =
false,
418 builder.
write(values_);
419 builder.
write(send_index_);
427 std::vector<std::string> values_;
428 bool send_index_ =
false;
436 const std::vector<std::string> & ref,
437 bool send_index =
false)
447 builder.
write(send_index_);
454 std::vector<std::string> ref_;
465 template<
typename... Args>
489 template<
typename T = details::Vo
idValue>
493 template<
typename = std::enable_if_t<!details::is_form_element_v<T>>>
499 template<
typename Element,
typename = std::enable_if_t<details::is_form_element_v<Element>>>
502 FormElements(std::forward<Element>(element)), data_{data}
513 FormElements::write_impl(builder);
514 data_.write(builder);
531 template<
typename T = details::Vo
idValue>
541 typename = std::enable_if_t<!details::is_variant_v<std::decay_t<U>> && !details::is_getter<U>()>>
542 FormOneOfInput(
const std::string & name,
bool required, U && arg, Args &&... args)
548 template<
typename... Args>
549 FormOneOfInput(
const std::string & name,
bool required,
const T & def, Args &&... args)
561 FormElements::write_impl(builder);
569 template<
typename Callback,
typename... Args>
570 auto Form(
const std::string & name, Callback cb, Args &&... args)