Added reading and writing for anonymous fields

This commit is contained in:
Patrick Urbanke
2023-11-06 21:10:03 +01:00
parent 57dad0df3f
commit 91cba55edb
7 changed files with 1263 additions and 1165 deletions
+24 -9
View File
@@ -5,7 +5,6 @@
#include <type_traits>
#include <utility>
#include "rfl/internal/all_fields.hpp"
#include "rfl/internal/is_field.hpp"
#include "rfl/internal/is_flatten_field.hpp"
#include "rfl/internal/ptr_tuple_t.hpp"
@@ -14,12 +13,29 @@ namespace rfl {
namespace internal {
template <class TupleType, int _i = 0>
constexpr bool has_some_fields() {
constexpr bool all_fields_or_flatten() {
if constexpr (_i == std::tuple_size_v<TupleType>) {
return true;
} else {
using T = std::decay_t<std::tuple_element_t<_i, TupleType>>;
if constexpr (is_flatten_field_v<T>) {
return all_fields_or_flatten<
ptr_tuple_t<typename std::remove_pointer_t<T>::Type>>() &&
all_fields_or_flatten<TupleType, _i + 1>();
} else {
return is_field_v<T> && all_fields_or_flatten<TupleType, _i + 1>();
}
}
}
template <class TupleType, int _i = 0>
constexpr bool has_some_fields_or_flatten() {
if constexpr (_i == std::tuple_size_v<TupleType>) {
return false;
} else {
using T = std::decay_t<std::tuple_element_t<_i, TupleType>>;
return is_field_v<T> || has_some_fields<TupleType, _i + 1>();
return is_field_v<T> || is_flatten_field_v<T> ||
has_some_fields_or_flatten<TupleType, _i + 1>();
}
}
@@ -29,13 +45,12 @@ constexpr bool has_fields() {
return true;
} else {
using TupleType = ptr_tuple_t<T>;
if constexpr (has_some_fields<TupleType>()) {
if constexpr (has_some_fields_or_flatten<TupleType>()) {
static_assert(
all_fields<TupleType>(),
"If some of your fields are annotated using rfl::Field<...>, then "
"you "
"must "
"annotate all of your fields. Also, you cannot combine annotated and "
all_fields_or_flatten<TupleType>(),
"If some of your fields are annotated using rfl::Field<...> or "
"rfl::Flatten, then you must annotate all of your fields. "
"Also, you cannot combine annotated and "
"unannotated fields using rfl::Flatten<...>.");
return true;
} else {