45#include <glaze/glaze.hpp>
50#include "../attributes.hpp"
54namespace morph::forms {
64template <std::
size_t N>
91 constexpr Choice() noexcept = default;
95 constexpr
Choice(T selected) noexcept(std::is_nothrow_move_constructible_v<T>) :
value{std::move(selected)} {}
99 constexpr Choice(std::optional<T> payload)
noexcept(std::is_nothrow_move_constructible_v<T>)
100 :
value{std::move(payload)} {}
104 [[nodiscard]]
static constexpr std::string_view
optionsAction() noexcept {
return OptionsAction.view(); }
108 [[nodiscard]]
static constexpr std::string_view
valueField() noexcept {
return ValueField.view(); }
112 [[nodiscard]]
static constexpr std::string_view
labelField() noexcept {
return LabelField.
view(); }
118 [[nodiscard]]
static constexpr std::array<std::string_view,
sizeof...(DependsOn)>
optionsDependsOn()
noexcept {
119 return {DependsOn.view()...};
124 [[nodiscard]]
constexpr bool hasValue() const noexcept {
return value.has_value(); }
131 [[nodiscard]]
constexpr const T&
operator*() const noexcept MORPH_LIFETIMEBOUND {
return *
value; }
143struct IsChoice : std::false_type {};
145template <
typename T, FixedString OptionsAction, FixedString ValueField, FixedString LabelField,
146 FixedString... DependsOn>
147struct IsChoice<Choice<T, OptionsAction, ValueField, LabelField, DependsOn...>> : std::true_type {};
153inline constexpr bool isChoice = detail::IsChoice<std::remove_cvref_t<T>>::value;
168struct glz::meta<morph::
forms::Choice<T, OptionsAction, ValueField, LabelField, DependsOn...>> {
169 static constexpr auto value = &
morph::forms::Choice<T, OptionsAction, ValueField, LabelField, DependsOn...>::value;
170 static constexpr std::string_view name =
171 morph::forms::detail::choiceSchemaName<OptionsAction, ValueField, LabelField, DependsOn...>;
::morph::detail::FixedString< N > FixedString
A structural, NTTP-capable compile-time string (for naming the options action and its value/label res...
constexpr bool isChoice
true when T (cvref-stripped) is a morph::forms::Choice.
Shared compile-time, NTTP-capable fixed string.
Compile-time $defs keys for the forms layer's field wrappers.
A structural, NTTP-capable compile-time string.
constexpr std::string_view view() const noexcept
A view of the string (without the terminating null).