...
This commit is contained in:
@@ -88,17 +88,20 @@ int main()
|
||||
snplib_keyvalue_expr_t kv1;
|
||||
|
||||
kv1.setKeyValue("KEY", 7.7);
|
||||
kv1.appendValue(std::string{"dekjlwe"});
|
||||
kv1.appendValue(std::string{"dekjlwe1"});
|
||||
kv1.appendValue(100);
|
||||
|
||||
std::println("key = '{}'", kv1.key());
|
||||
std::println("value = '{}'", kv1.value());
|
||||
std::println("valueSeq = '{}'\n", kv1.valueSeq());
|
||||
|
||||
si = std::string{"dekjlwe"};
|
||||
si = std::string{"dekjlwe2"};
|
||||
kv1.setValue(7.7, snplib_serialization_params_t{}, si, snplib_serialization_params_t{}, 100,
|
||||
snplib_serialization_params_t{});
|
||||
|
||||
si = std::string{"dekjlwe3"};
|
||||
kv1.setValue(snplib_serialization_params_t{}, 7.7, si, 100);
|
||||
|
||||
std::println("key = '{}'", kv1.key());
|
||||
std::println("value = '{}'", kv1.value());
|
||||
std::println("valueSeq = '{}'\n", kv1.valueSeq());
|
||||
|
||||
@@ -253,43 +253,6 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
// value1, ser-pars1, value2, ser-pars2, ..., valueN, ser-parsN
|
||||
template <typename... ValSerParPairTs>
|
||||
requires(mutableContent && sizeof...(ValSerParPairTs) >= 4 && (sizeof...(ValSerParPairTs) % 2 == 0))
|
||||
error_t setValue(ValSerParPairTs&&... pairs)
|
||||
{
|
||||
constexpr auto f = []<size_t... Is>(std::index_sequence<Is...>) {
|
||||
using args_t = std::tuple<ValSerParPairTs...>;
|
||||
|
||||
return ((snplib_serializable_c<std::tuple_element_t<Is * 2, args_t>> &&
|
||||
snplib_serialization_params_c<std::tuple_element_t<Is * 2 + 1, args_t>>) &&
|
||||
...);
|
||||
}(std::make_index_sequence<sizeof...(ValSerParPairTs) / 2>{});
|
||||
|
||||
_valueSeq.clear(); // to trigger the first call to setValue
|
||||
return [this](this auto&& self, auto&& v1, auto&& sp1, auto&&... prs) -> error_t {
|
||||
auto err = appendValue(std::forward<decltype(v1)>(v1), std::forward<decltype(sp1)>(sp1));
|
||||
if (err) {
|
||||
return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument));
|
||||
}
|
||||
|
||||
if constexpr (sizeof...(prs)) {
|
||||
return std::forward<decltype(self)>(self)(std::forward<decltype(prs)>(prs)...);
|
||||
}
|
||||
|
||||
return {};
|
||||
}(std::forward<ValSerParPairTs>(pairs)...);
|
||||
}
|
||||
|
||||
template <typename... ArgTs>
|
||||
requires(mutableContent && sizeof...(ArgTs) > 2)
|
||||
error_t setVal(ArgTs&&... args)
|
||||
{
|
||||
static_assert(snplib_serialization_params_c<snplib_last_in_pack_t<ArgTs...>>, "");
|
||||
|
||||
using args_t = snplib_tuple_except_last_t<ArgTs...>;
|
||||
}
|
||||
|
||||
|
||||
template <snplib_serializable_c ValueT, snplib_serialization_params_c SParT = snplib_serialization_params_t>
|
||||
requires mutableContent
|
||||
@@ -327,6 +290,204 @@ public:
|
||||
}
|
||||
|
||||
|
||||
// value1, ser-pars1, value2, ser-pars2, ..., valueN, ser-parsN
|
||||
template <typename... ValSerParPairTs>
|
||||
requires(mutableContent && sizeof...(ValSerParPairTs) >= 4 && (sizeof...(ValSerParPairTs) % 2 == 0) &&
|
||||
!snplib_serialization_params_c<std::tuple_element_t<0, std::tuple<ValSerParPairTs...>>>)
|
||||
error_t setValue(ValSerParPairTs&&... pairs)
|
||||
{
|
||||
constexpr auto f = []<size_t... Is>(std::index_sequence<Is...>) {
|
||||
using args_t = std::tuple<ValSerParPairTs...>;
|
||||
|
||||
return ((snplib_serializable_c<std::tuple_element_t<Is * 2, args_t>> &&
|
||||
snplib_serialization_params_c<std::tuple_element_t<Is * 2 + 1, args_t>>) &&
|
||||
...);
|
||||
}(std::make_index_sequence<sizeof...(ValSerParPairTs) / 2>{});
|
||||
|
||||
_valueSeq.clear(); // to trigger the first call to setValue
|
||||
|
||||
return [this](this auto&& self, auto&& v1, auto&& sp1, auto&&... prs) -> error_t {
|
||||
auto err = appendValue(std::forward<decltype(v1)>(v1), std::forward<decltype(sp1)>(sp1));
|
||||
if (err) {
|
||||
return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument));
|
||||
}
|
||||
|
||||
if constexpr (sizeof...(prs)) {
|
||||
return std::forward<decltype(self)>(self)(std::forward<decltype(prs)>(prs)...);
|
||||
}
|
||||
|
||||
return {};
|
||||
}(std::forward<ValSerParPairTs>(pairs)...);
|
||||
}
|
||||
|
||||
|
||||
// value1, ser-pars1, value2, ser-pars2, ..., valueN, ser-parsN
|
||||
// or
|
||||
// common-ser-pars, value1, value2, ..., valueN
|
||||
template <typename ArgT, typename... ArgTs>
|
||||
requires(mutableContent && sizeof...(ArgTs) > 1)
|
||||
error_t setValue(ArgT&& arg, ArgTs&&... args)
|
||||
{
|
||||
static constexpr size_t NARGS = sizeof...(ArgTs) + 1;
|
||||
|
||||
// "val-spar" pairs
|
||||
constexpr auto is_val_spar_pairs =
|
||||
!snplib_serialization_params_c<ArgT> && []<size_t... Is>(std::index_sequence<Is...>) {
|
||||
if constexpr (NARGS % 2) { // NARGS must be an even
|
||||
return false;
|
||||
}
|
||||
|
||||
using args_t = std::tuple<ArgT, ArgTs...>;
|
||||
|
||||
return ((snplib_serializable_c<std::tuple_element_t<Is * 2, args_t>> &&
|
||||
snplib_serialization_params_c<std::tuple_element_t<Is * 2 + 1, args_t>>) &&
|
||||
...);
|
||||
}(std::make_index_sequence<NARGS / 2>{});
|
||||
|
||||
|
||||
constexpr auto is_val_seq =
|
||||
snplib_serialization_params_c<ArgT> && []<size_t... Is>(std::index_sequence<Is...>) {
|
||||
return (snplib_serializable_c<std::tuple_element_t<Is, std::tuple<ArgTs...>>> && ...);
|
||||
}(std::make_index_sequence<sizeof...(ArgTs)>{});
|
||||
|
||||
static_assert(is_val_spar_pairs || is_val_seq, "Unsupported input parameter types!");
|
||||
|
||||
_valueSeq.clear(); // to trigger the first call to setValue
|
||||
|
||||
if constexpr (is_val_spar_pairs) {
|
||||
return [this](this auto&& self, auto&& v1, auto&& sp1, auto&&... prs) -> error_t {
|
||||
auto err = appendValue(std::forward<decltype(v1)>(v1), std::forward<decltype(sp1)>(sp1));
|
||||
if (err) {
|
||||
return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument));
|
||||
}
|
||||
|
||||
if constexpr (sizeof...(prs)) {
|
||||
return std::forward<decltype(self)>(self)(std::forward<decltype(prs)>(prs)...);
|
||||
}
|
||||
|
||||
return {};
|
||||
}(std::forward<ArgT>(arg), std::forward<ArgTs>(args)...);
|
||||
} else { // ser-params and values sequence
|
||||
return [sp = std::forward<ArgT>(arg), this]<size_t I = 0>(this auto&& self, auto&& tp) -> error_t {
|
||||
using tp_t = std::remove_cvref_t<decltype(tp)>;
|
||||
|
||||
if constexpr (I < std::tuple_size_v<tp_t>) {
|
||||
auto err = appendValue(
|
||||
std::forward<std::tuple_element_t<I, tp_t>>(std::get<I>(std::forward<decltype(tp)>(tp))), sp);
|
||||
if (err) {
|
||||
return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument));
|
||||
}
|
||||
|
||||
return std::forward<decltype(self)>(self).template operator()<I + 1>(
|
||||
std::forward<decltype(tp)>(tp));
|
||||
}
|
||||
|
||||
return {};
|
||||
}(std::forward_as_tuple(std::forward<ArgTs>(args)...));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// // common-ser-pars, value1, value2, ..., valueN
|
||||
// template <snplib_serialization_params_c SParT, snplib_serializable_c... ValueTs>
|
||||
// requires(mutableContent && sizeof...(ValueTs) > 1)
|
||||
// error_t setValue(SParT sparams, ValueTs&&... values)
|
||||
// {
|
||||
// _valueSeq.clear(); // to trigger the first call to setValue
|
||||
|
||||
// return [sp = std::move(sparams), this]<size_t I = 0>(this auto&& self, auto&& tp) -> error_t {
|
||||
// using tp_t = std::remove_cvref_t<decltype(tp)>;
|
||||
|
||||
// if constexpr (I < std::tuple_size_v<tp_t>) {
|
||||
// auto err = appendValue(
|
||||
// std::forward<std::tuple_element_t<I, tp_t>>(std::get<I>(std::forward<decltype(tp)>(tp))),
|
||||
// std::move(sp));
|
||||
// if (err) {
|
||||
// return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument));
|
||||
// }
|
||||
|
||||
// return std::forward<decltype(self)>(self).template operator()<I + 1>(std::forward<decltype(tp)>(tp));
|
||||
// }
|
||||
|
||||
// return {};
|
||||
// }(std::forward_as_tuple(std::forward<ValueTs>(values)...));
|
||||
// }
|
||||
|
||||
// value1, ser-pars1, value2, ser-pars2, ..., valueN, ser-parsN
|
||||
// or
|
||||
// value1, value2, ..., valueN, common-ser-pars
|
||||
// template <typename... ArgTs>
|
||||
// requires(mutableContent && sizeof...(ArgTs) > 2)
|
||||
// error_t setValue(ArgTs&&... args)
|
||||
// {
|
||||
// constexpr auto is_val_spar_pairs = []<size_t... Is>(std::index_sequence<Is...>) {
|
||||
// using args_t = std::tuple<ArgTs...>;
|
||||
|
||||
// return ((snplib_serializable_c<std::tuple_element_t<Is * 2, args_t>> &&
|
||||
// snplib_serialization_params_c<std::tuple_element_t<Is * 2 + 1, args_t>>) &&
|
||||
// ...);
|
||||
// }(std::make_index_sequence<sizeof...(ArgTs) / 2>{});
|
||||
|
||||
// using v_args_t = snplib_tuple_except_last_t<ArgTs...>;
|
||||
|
||||
// constexpr auto is_val_seq = []<size_t... Is>(std::index_sequence<Is...>) {
|
||||
// return (snplib_serializable_c<std::tuple_element_t<Is, v_args_t>> && ...);
|
||||
// }(std::make_index_sequence<std::tuple_size_v<v_args_t>>{});
|
||||
|
||||
// static_assert(is_val_spar_pairs || is_val_seq, "Unsupported input parameter types!");
|
||||
|
||||
// _valueSeq.clear(); // to trigger the first call to setValue
|
||||
|
||||
// if constexpr (is_val_spar_pairs) {
|
||||
// return [this](this auto&& self, auto&& v1, auto&& sp1, auto&&... prs) -> error_t {
|
||||
// auto err = appendValue(std::forward<decltype(v1)>(v1), std::forward<decltype(sp1)>(sp1));
|
||||
// if (err) {
|
||||
// return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument));
|
||||
// }
|
||||
|
||||
// if constexpr (sizeof...(prs)) {
|
||||
// return std::forward<decltype(self)>(self)(std::forward<decltype(prs)>(prs)...);
|
||||
// }
|
||||
|
||||
// return {};
|
||||
// }(std::forward<ArgTs>(args)...);
|
||||
// } else { // value sequence with trailing common serialization parameters
|
||||
// static_assert(snplib_serialization_params_c<snplib_last_in_pack_t<ArgTs...>>,
|
||||
// "The last input parameter must satisfy to 'snplib_serialization_params_c' requirement!");
|
||||
|
||||
// auto make_vals_tuple = [... args = std::forward<ArgTs>(args)]() mutable {
|
||||
// return [tp = std::forward_as_tuple(std::forward<ArgTs>(args)...)]<size_t... Is>(
|
||||
// std::index_sequence<Is...>) mutable {
|
||||
// return std::forward_as_tuple(
|
||||
// std::forward<std::tuple_element_t<Is, decltype(tp)>>(std::get<Is>(tp))...);
|
||||
// }(std::make_index_sequence<sizeof...(ArgTs) - 1>{});
|
||||
// };
|
||||
|
||||
|
||||
// return [spar = std::forward<std::tuple_element_t<sizeof...(ArgTs) - 1, decltype(std::forward_as_tuple(
|
||||
// std::forward<ArgTs>(args)...))>>(
|
||||
// std::get<sizeof...(ArgTs) - 1>(std::forward_as_tuple(std::forward<ArgTs>(args)...))),
|
||||
// this]<size_t I = 0>(this auto&& self, auto&& tp) -> error_t {
|
||||
// using tp_t = std::remove_cvref_t<decltype(tp)>;
|
||||
|
||||
// if constexpr (I < std::tuple_size_v<tp_t>) {
|
||||
// auto err = appendValue(
|
||||
// std::forward<std::tuple_element_t<I, tp_t>>(std::get<I>(std::forward<decltype(tp)>(tp))),
|
||||
// std::forward<decltype(spar)>(spar));
|
||||
// if (err) {
|
||||
// return snplib_deduced_error(err, std::make_error_code(std::errc::invalid_argument));
|
||||
// }
|
||||
|
||||
// return std::forward<decltype(self)>(self).template operator()<I + 1>(
|
||||
// std::forward<decltype(tp)>(tp));
|
||||
// }
|
||||
|
||||
// return {};
|
||||
// }(make_vals_tuple());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
template <snplib_serializable_c KeyT,
|
||||
snplib_serializable_c ValueT,
|
||||
snplib_serialization_params_c SParT = snplib_serialization_params_t>
|
||||
|
||||
Reference in New Issue
Block a user