diff --git a/include/rfl/Processors.hpp b/include/rfl/Processors.hpp index 14707b1f..eded95dc 100644 --- a/include/rfl/Processors.hpp +++ b/include/rfl/Processors.hpp @@ -4,13 +4,7 @@ #include #include -#include "internal/is_add_tags_to_variants_v.hpp" -#include "internal/is_allow_raw_ptrs_v.hpp" -#include "internal/is_default_if_missing_v.hpp" -#include "internal/is_no_extra_fields_v.hpp" -#include "internal/is_no_field_names_v.hpp" -#include "internal/is_no_optionals_v.hpp" -#include "internal/is_underlying_enums_v.hpp" +#include "Tuple.hpp" namespace rfl { @@ -19,60 +13,16 @@ struct Processors; template <> struct Processors<> { - static constexpr bool add_tags_to_variants_ = false; - static constexpr bool add_namespaced_tags_to_variants_ = false; - static constexpr bool allow_raw_ptrs_ = false; - static constexpr bool all_required_ = false; - static constexpr bool default_if_missing_ = false; - static constexpr bool no_extra_fields_ = false; - static constexpr bool no_field_names_ = false; - static constexpr bool underlying_enums_ = false; - template static auto process(NamedTupleType&& _named_tuple) { - return _named_tuple; + return std::forward(_named_tuple); } }; template struct Processors { - static constexpr bool add_tags_to_variants_ = - std::disjunction_v, - internal::is_add_tags_to_variants...>; - - static constexpr bool add_namespaced_tags_to_variants_ = - std::disjunction_v, - internal::is_add_namespaced_tags_to_variants...>; - - static constexpr bool allow_raw_ptrs_ = - std::disjunction_v, - internal::is_allow_raw_ptrs...>; - - static constexpr bool all_required_ = - std::disjunction_v, - internal::is_no_optionals...>; - - static constexpr bool default_if_missing_ = - std::disjunction_v, - internal::is_default_if_missing...>; - - static constexpr bool no_extra_fields_ = - std::disjunction_v, - internal::is_no_extra_fields...>; - - static constexpr bool no_field_names_ = - std::disjunction_v, - internal::is_no_field_names...>; - - static constexpr bool underlying_enums_ = - std::disjunction_v, - internal::is_underlying_enums...>; - template static auto process(NamedTupleType&& _named_tuple) { - static_assert(!add_tags_to_variants_ || !add_namespaced_tags_to_variants_, - "You cannot add both rfl::AddTagsToVariants and " - "rfl::AddNamespacedTagsToVariants."); return Processors::template process( Head::template process(std::move(_named_tuple))); } diff --git a/include/rfl/avro/Parser.hpp b/include/rfl/avro/Parser.hpp index 31e93cc0..599ddc81 100644 --- a/include/rfl/avro/Parser.hpp +++ b/include/rfl/avro/Parser.hpp @@ -5,6 +5,7 @@ #include "../NamedTuple.hpp" #include "../Tuple.hpp" #include "../always_false.hpp" +#include "../internal/no_field_names_v.hpp" #include "../parsing/AreReaderAndWriter.hpp" #include "../parsing/Parser.hpp" #include "Reader.hpp" @@ -25,8 +26,8 @@ struct Parser, avro::Reader, avro::Writer, /*_ignore_empty_containers=*/false, /*_all_required=*/true, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> {}; + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; template requires AreReaderAndWriter> diff --git a/include/rfl/boost_serialization/Parser.hpp b/include/rfl/boost_serialization/Parser.hpp index 71269b6f..7cf7e6af 100644 --- a/include/rfl/boost_serialization/Parser.hpp +++ b/include/rfl/boost_serialization/Parser.hpp @@ -5,6 +5,7 @@ #include "../NamedTuple.hpp" #include "../Tuple.hpp" #include "../always_false.hpp" +#include "../internal/no_field_names_v.hpp" #include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" @@ -28,8 +29,8 @@ struct Parser, boost_serialization::Writer, /*_ignore_empty_containers=*/false, /*_all_required=*/true, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> {}; + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; template requires AreReaderAndWriter, diff --git a/include/rfl/bson/read.hpp b/include/rfl/bson/read.hpp index a18204d3..a04da5ca 100644 --- a/include/rfl/bson/read.hpp +++ b/include/rfl/bson/read.hpp @@ -7,6 +7,7 @@ #include "../Processors.hpp" #include "../concepts.hpp" +#include "../internal/no_field_names_v.hpp" #include "../internal/ptr_cast.hpp" #include "../internal/wrap_in_rfl_array_t.hpp" #include "Parser.hpp" @@ -23,7 +24,7 @@ template Result> read(const InputVarType& _obj) { const auto r = Reader(); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); return Parser::read(r, _obj); diff --git a/include/rfl/bson/write.hpp b/include/rfl/bson/write.hpp index 1938eb6c..8cd6f0b6 100644 --- a/include/rfl/bson/write.hpp +++ b/include/rfl/bson/write.hpp @@ -10,6 +10,7 @@ #include "../Processors.hpp" #include "../Result.hpp" +#include "../internal/no_field_names_v.hpp" #include "../internal/ptr_cast.hpp" #include "../parsing/Parent.hpp" #include "Parser.hpp" @@ -32,7 +33,7 @@ Result> to_buffer(const auto& _obj) noexcept { bson_writer_begin(bson_writer.get(), &doc); const auto rfl_writer = Writer(doc); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); const auto nothing = [&]() -> Result { diff --git a/include/rfl/capnproto/Parser.hpp b/include/rfl/capnproto/Parser.hpp index 60e205c1..02261f3f 100644 --- a/include/rfl/capnproto/Parser.hpp +++ b/include/rfl/capnproto/Parser.hpp @@ -5,6 +5,7 @@ #include "../NamedTuple.hpp" #include "../Tuple.hpp" #include "../always_false.hpp" +#include "../internal/no_field_names_v.hpp" #include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" @@ -24,8 +25,8 @@ struct Parser, capnproto::Reader, capnproto::Writer, /*_ignore_empty_containers=*/false, /*_all_required=*/true, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> {}; + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; template requires AreReaderAndWriter, cereal::Reader, cereal::Writer, /*_ignore_empty_containers=*/false, /*_all_required=*/true, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> {}; + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; template requires AreReaderAndWriter> diff --git a/include/rfl/internal/add_tags_to_variants_v.hpp b/include/rfl/internal/add_tags_to_variants_v.hpp new file mode 100644 index 00000000..450dfe18 --- /dev/null +++ b/include/rfl/internal/add_tags_to_variants_v.hpp @@ -0,0 +1,60 @@ +#ifndef RFL_INTERNAL_ADDTAGSTOVARIANTS_HPP_ +#define RFL_INTERNAL_ADDTAGSTOVARIANTS_HPP_ + +#include + +#include "../AddTagsToVariants.hpp" +#include "../Processors.hpp" + +namespace rfl::internal { + +template +class add_tags_to_variants; + +template +class add_tags_to_variants : public std::false_type {}; + +template <> +class add_tags_to_variants : public std::true_type {}; + +template +struct add_tags_to_variants> { + static constexpr bool value = (add_tags_to_variants::value || ... || + add_tags_to_variants::value); +}; + +template +constexpr bool add_tags_to_variants_v = + add_tags_to_variants>>::value; + +template +class add_namespaced_tags_to_variants; + +template +class add_namespaced_tags_to_variants : public std::false_type {}; + +template <> +class add_namespaced_tags_to_variants + : public std::true_type {}; + +template +struct add_namespaced_tags_to_variants> { + static constexpr bool value = + (add_namespaced_tags_to_variants::value || ... || + add_namespaced_tags_to_variants::value); + + static_assert( + !add_tags_to_variants>::value || + !add_namespaced_tags_to_variants>::value, + "Cannot use both AddTagsToVariants and AddNamespacedTagsToVariants in " + "the same Processors list."); +}; + +template +constexpr bool add_namespaced_tags_to_variants_v = + add_namespaced_tags_to_variants< + std::remove_cvref_t>>::value; + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/internal/allow_raw_ptrs_v.hpp b/include/rfl/internal/allow_raw_ptrs_v.hpp new file mode 100644 index 00000000..a53529e6 --- /dev/null +++ b/include/rfl/internal/allow_raw_ptrs_v.hpp @@ -0,0 +1,32 @@ +#ifndef RFL_INTERNAL_ALLOWRAWPTRS_HPP_ +#define RFL_INTERNAL_ALLOWRAWPTRS_HPP_ + +#include + +#include "../AllowRawPtrs.hpp" +#include "../Processors.hpp" + +namespace rfl::internal { + +template +class allow_raw_ptrs; + +template +class allow_raw_ptrs : public std::false_type {}; + +template <> +class allow_raw_ptrs : public std::true_type {}; + +template +struct allow_raw_ptrs> { + static constexpr bool value = + (allow_raw_ptrs::value || ... || allow_raw_ptrs::value); +}; + +template +constexpr bool allow_raw_ptrs_v = + allow_raw_ptrs>>::value; + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/internal/default_if_missing_v.hpp b/include/rfl/internal/default_if_missing_v.hpp new file mode 100644 index 00000000..a94ec619 --- /dev/null +++ b/include/rfl/internal/default_if_missing_v.hpp @@ -0,0 +1,32 @@ +#ifndef RFL_INTERNAL_DEFAULTIFMISSING_HPP_ +#define RFL_INTERNAL_DEFAULTIFMISSING_HPP_ + +#include + +#include "../DefaultIfMissing.hpp" +#include "../Processors.hpp" + +namespace rfl::internal { + +template +class default_if_missing; + +template +class default_if_missing : public std::false_type {}; + +template <> +class default_if_missing : public std::true_type {}; + +template +struct default_if_missing> { + static constexpr bool value = (default_if_missing::value || ... || + default_if_missing::value); +}; + +template +constexpr bool default_if_missing_v = + default_if_missing>>::value; + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/internal/is_add_tags_to_variants_v.hpp b/include/rfl/internal/is_add_tags_to_variants_v.hpp deleted file mode 100644 index 4385b1d2..00000000 --- a/include/rfl/internal/is_add_tags_to_variants_v.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef RFL_INTERNAL_ISADDTAGSTOVARIANTS_HPP_ -#define RFL_INTERNAL_ISADDTAGSTOVARIANTS_HPP_ - -#include - -#include "../AddTagsToVariants.hpp" - -namespace rfl ::internal { - -template -class is_add_tags_to_variants; - -template -class is_add_tags_to_variants : public std::false_type {}; - -template <> -class is_add_tags_to_variants : public std::true_type {}; - -template -constexpr bool is_add_tags_to_variants_v = is_add_tags_to_variants< - std::remove_cvref_t>>::value; - -template -class is_add_namespaced_tags_to_variants; - -template -class is_add_namespaced_tags_to_variants : public std::false_type {}; - -template <> -class is_add_namespaced_tags_to_variants - : public std::true_type {}; - -template -constexpr bool is_add_namespaced_tags_to_variants_v = - is_add_namespaced_tags_to_variants< - std::remove_cvref_t>>::value; - -} // namespace rfl::internal - -#endif diff --git a/include/rfl/internal/is_allow_raw_ptrs_v.hpp b/include/rfl/internal/is_allow_raw_ptrs_v.hpp deleted file mode 100644 index 3b3e51ae..00000000 --- a/include/rfl/internal/is_allow_raw_ptrs_v.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef RFL_INTERNAL_ISALLOWRAWPTRS_HPP_ -#define RFL_INTERNAL_ISALLOWRAWPTRS_HPP_ - -#include - -#include "../AllowRawPtrs.hpp" - -namespace rfl { -namespace internal { - -template -class is_allow_raw_ptrs; - -template -class is_allow_raw_ptrs : public std::false_type {}; - -template <> -class is_allow_raw_ptrs : public std::true_type {}; - -template -constexpr bool is_allow_raw_ptrs_v = - is_allow_raw_ptrs>>::value; - -} // namespace internal -} // namespace rfl - -#endif diff --git a/include/rfl/internal/is_default_if_missing_v.hpp b/include/rfl/internal/is_default_if_missing_v.hpp deleted file mode 100644 index 836ca7e0..00000000 --- a/include/rfl/internal/is_default_if_missing_v.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef RFL_INTERNAL_ISDEFAULTIFMISSING_HPP_ -#define RFL_INTERNAL_ISDEFAULTIFMISSING_HPP_ - -#include - -#include "../DefaultIfMissing.hpp" - -namespace rfl::internal { - -template -class is_default_if_missing; - -template -class is_default_if_missing : public std::false_type {}; - -template <> -class is_default_if_missing : public std::true_type {}; - -template -constexpr bool is_default_if_missing_v = - is_default_if_missing>>::value; - -} // namespace rfl::internal - -#endif diff --git a/include/rfl/internal/is_no_extra_fields_v.hpp b/include/rfl/internal/is_no_extra_fields_v.hpp deleted file mode 100644 index 1c624534..00000000 --- a/include/rfl/internal/is_no_extra_fields_v.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef RFL_INTERNAL_ISNOEXTRAFIELDS_HPP_ -#define RFL_INTERNAL_ISNOEXTRAFIELDS_HPP_ - -#include - -#include "../NoExtraFields.hpp" - -namespace rfl { -namespace internal { - -template -class is_no_extra_fields; - -template -class is_no_extra_fields : public std::false_type {}; - -template <> -class is_no_extra_fields : public std::true_type {}; - -template -constexpr bool is_no_extra_fields_v = - is_no_extra_fields>>::value; - -} // namespace internal -} // namespace rfl - -#endif diff --git a/include/rfl/internal/is_no_field_names_v.hpp b/include/rfl/internal/is_no_field_names_v.hpp deleted file mode 100644 index 9c0cbee5..00000000 --- a/include/rfl/internal/is_no_field_names_v.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef RFL_INTERNAL_ISNOFIELDNAMES_HPP_ -#define RFL_INTERNAL_ISNOFIELDNAMES_HPP_ - -#include - -#include "../NoFieldNames.hpp" - -namespace rfl::internal { - -template -class is_no_field_names; - -template -class is_no_field_names : public std::false_type {}; - -template <> -class is_no_field_names : public std::true_type {}; - -template -constexpr bool is_no_field_names_v = - is_no_field_names>>::value; - -} // namespace rfl::internal - -#endif diff --git a/include/rfl/internal/is_no_optionals_v.hpp b/include/rfl/internal/is_no_optionals_v.hpp deleted file mode 100644 index e2e2bc1f..00000000 --- a/include/rfl/internal/is_no_optionals_v.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef RFL_INTERNAL_ISNOOPTIONALS_HPP_ -#define RFL_INTERNAL_ISNOOPTIONALS_HPP_ - -#include - -#include "../NoOptionals.hpp" - -namespace rfl { -namespace internal { - -template -class is_no_optionals; - -template -class is_no_optionals : public std::false_type {}; - -template <> -class is_no_optionals : public std::true_type {}; - -template -constexpr bool is_no_optionals_v = - is_no_optionals>>::value; - -} // namespace internal -} // namespace rfl - -#endif diff --git a/include/rfl/internal/is_underlying_enums_v.hpp b/include/rfl/internal/is_underlying_enums_v.hpp deleted file mode 100644 index f0570e9c..00000000 --- a/include/rfl/internal/is_underlying_enums_v.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef RFL_INTERNAL_ISUNDERLYINGENUMS_HPP_ -#define RFL_INTERNAL_ISUNDERLYINGENUMS_HPP_ - -#include - -#include "../UnderlyingEnums.hpp" - -namespace rfl { -namespace internal { - -template -class is_underlying_enums; - -template -class is_underlying_enums : public std::false_type {}; - -template <> -class is_underlying_enums : public std::true_type {}; - -template -constexpr bool is_underlying_enums_v = - is_underlying_enums>>::value; - -} // namespace internal -} // namespace rfl - -#endif diff --git a/include/rfl/internal/no_extra_fields_v.hpp b/include/rfl/internal/no_extra_fields_v.hpp new file mode 100644 index 00000000..538ed8b9 --- /dev/null +++ b/include/rfl/internal/no_extra_fields_v.hpp @@ -0,0 +1,32 @@ +#ifndef RFL_INTERNAL_NOEXTRAFIELDS_HPP_ +#define RFL_INTERNAL_NOEXTRAFIELDS_HPP_ + +#include + +#include "../NoExtraFields.hpp" +#include "../Processors.hpp" + +namespace rfl::internal { + +template +class no_extra_fields; + +template +class no_extra_fields : public std::false_type {}; + +template <> +class no_extra_fields : public std::true_type {}; + +template +struct no_extra_fields> { + static constexpr bool value = + (no_extra_fields::value || ... || no_extra_fields::value); +}; + +template +constexpr bool no_extra_fields_v = + no_extra_fields>>::value; + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/internal/no_field_names_v.hpp b/include/rfl/internal/no_field_names_v.hpp new file mode 100644 index 00000000..184159db --- /dev/null +++ b/include/rfl/internal/no_field_names_v.hpp @@ -0,0 +1,32 @@ +#ifndef RFL_INTERNAL_NOFIELDNAMES_HPP_ +#define RFL_INTERNAL_NOFIELDNAMES_HPP_ + +#include + +#include "../NoFieldNames.hpp" +#include "../Processors.hpp" + +namespace rfl::internal { + +template +class no_field_names; + +template +class no_field_names : public std::false_type {}; + +template <> +class no_field_names : public std::true_type {}; + +template +struct no_field_names> { + static constexpr bool value = + (no_field_names::value || ... || no_field_names::value); +}; + +template +constexpr bool no_field_names_v = + no_field_names>>::value; + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/internal/no_optionals_v.hpp b/include/rfl/internal/no_optionals_v.hpp new file mode 100644 index 00000000..76120701 --- /dev/null +++ b/include/rfl/internal/no_optionals_v.hpp @@ -0,0 +1,32 @@ +#ifndef RFL_INTERNAL_NOOPTIONALS_HPP_ +#define RFL_INTERNAL_NOOPTIONALS_HPP_ + +#include + +#include "../NoOptionals.hpp" +#include "../Processors.hpp" + +namespace rfl::internal { + +template +class no_optionals; + +template +class no_optionals : public std::false_type {}; + +template <> +class no_optionals : public std::true_type {}; + +template +struct no_optionals> { + static constexpr bool value = + (no_optionals::value || ... || no_optionals::value); +}; + +template +constexpr bool no_optionals_v = + no_optionals>>::value; + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/internal/underlying_enums_v.hpp b/include/rfl/internal/underlying_enums_v.hpp new file mode 100644 index 00000000..e67f1d3b --- /dev/null +++ b/include/rfl/internal/underlying_enums_v.hpp @@ -0,0 +1,32 @@ +#ifndef RFL_INTERNAL_UNDERLYINGENUMS_HPP_ +#define RFL_INTERNAL_UNDERLYINGENUMS_HPP_ + +#include + +#include "../Processors.hpp" +#include "../UnderlyingEnums.hpp" + +namespace rfl::internal { + +template +class underlying_enums; + +template +class underlying_enums : public std::false_type {}; + +template <> +class underlying_enums : public std::true_type {}; + +template +struct underlying_enums> { + static constexpr bool value = + (underlying_enums::value || ... || underlying_enums::value); +}; + +template +constexpr bool underlying_enums_v = + underlying_enums>>::value; + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/json/to_schema.hpp b/include/rfl/json/to_schema.hpp index 6630e573..00cbcca9 100644 --- a/include/rfl/json/to_schema.hpp +++ b/include/rfl/json/to_schema.hpp @@ -9,18 +9,14 @@ #include -// #include "../Literal.hpp" #include "../Processors.hpp" #include "../Variant.hpp" -// #include "../parsing/schema/Type.hpp" -// #include "../parsing/schema/ValidationType.hpp" +#include "../common.hpp" +#include "../internal/default_if_missing_v.hpp" #include "../parsing/schema/make.hpp" #include "Reader.hpp" #include "Writer.hpp" #include "schema/JSONSchema.hpp" -// #include "schema/Type.hpp" -// #include "write.hpp" -#include "../common.hpp" namespace rfl::json { @@ -43,7 +39,7 @@ std::string to_schema(const yyjson_write_flag _flag = 0, using P = Processors; const auto internal_schema = parsing::schema::make(); return to_schema_internal_schema(internal_schema, _flag, - P::default_if_missing_, comment); + internal::default_if_missing_v

, comment); } } // namespace rfl::json diff --git a/include/rfl/msgpack/Parser.hpp b/include/rfl/msgpack/Parser.hpp index e7fdae3d..fdb9d0ee 100644 --- a/include/rfl/msgpack/Parser.hpp +++ b/include/rfl/msgpack/Parser.hpp @@ -1,6 +1,7 @@ #ifndef RFL_MSGPACK_PARSER_HPP_ #define RFL_MSGPACK_PARSER_HPP_ +#include "../internal/no_field_names_v.hpp" #include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" @@ -12,37 +13,36 @@ namespace parsing { /// Because of that, we require all of the fields and then set them to nullptr, /// if necessary. template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> : public NamedTupleParser< msgpack::Reader, msgpack::Writer, /*_ignore_empty_containers=*/false, /*_all_required=*/true, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> { -}; + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> : public TupleParser> { -}; + rfl::Tuple> {}; template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> : public TupleParser> { -}; + std::tuple> {}; } // namespace parsing } // namespace rfl diff --git a/include/rfl/parsing/NamedTupleParser.hpp b/include/rfl/parsing/NamedTupleParser.hpp index d31d3941..be2ff594 100644 --- a/include/rfl/parsing/NamedTupleParser.hpp +++ b/include/rfl/parsing/NamedTupleParser.hpp @@ -10,6 +10,7 @@ #include "../NamedTuple.hpp" #include "../Result.hpp" #include "../always_false.hpp" +#include "../internal/default_if_missing_v.hpp" #include "../internal/has_default_val_v.hpp" #include "../internal/is_array.hpp" #include "../internal/is_attribute.hpp" @@ -345,7 +346,7 @@ struct NamedTupleParser { } } if constexpr (internal::has_default_val_v && - !ProcessorsType::default_if_missing_) { + !internal::default_if_missing_v) { handle_missing_fields(reader.found(), *_view, nullptr, &errors, std::make_integer_sequence()); } diff --git a/include/rfl/parsing/Parser_basic_type.hpp b/include/rfl/parsing/Parser_basic_type.hpp index ddbb5e09..27264aa6 100644 --- a/include/rfl/parsing/Parser_basic_type.hpp +++ b/include/rfl/parsing/Parser_basic_type.hpp @@ -15,7 +15,6 @@ #include "../internal/is_basic_type.hpp" #include "../internal/is_description.hpp" #include "../internal/is_literal.hpp" -#include "../internal/is_underlying_enums_v.hpp" #include "../internal/is_validator.hpp" #include "../internal/processed_t.hpp" #include "../internal/ptr_cast.hpp" diff --git a/include/rfl/parsing/Parser_box.hpp b/include/rfl/parsing/Parser_box.hpp index ab29a981..8d26013b 100644 --- a/include/rfl/parsing/Parser_box.hpp +++ b/include/rfl/parsing/Parser_box.hpp @@ -9,6 +9,7 @@ #include "../atomic/is_atomic.hpp" #include "../atomic/remove_atomic_t.hpp" #include "../atomic/set_atomic.hpp" +#include "../internal/default_if_missing_v.hpp" #include "../internal/has_default_val_v.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" @@ -27,7 +28,7 @@ struct Parser, ProcessorsType> { static_assert(!internal::has_default_val_v, "Atomic types cannot be mixed with rfl::DefaultVal"); - static_assert(!ProcessorsType::default_if_missing_, + static_assert(!internal::default_if_missing_v, "Atomic types cannot be mixed with rfl::DefaultIfMissing"); return Parser::read(_r, _var) diff --git a/include/rfl/parsing/Parser_default.hpp b/include/rfl/parsing/Parser_default.hpp index 4f1619c0..e2d6159c 100644 --- a/include/rfl/parsing/Parser_default.hpp +++ b/include/rfl/parsing/Parser_default.hpp @@ -8,6 +8,7 @@ #include "../always_false.hpp" #include "../enums.hpp" #include "../from_named_tuple.hpp" +#include "../internal/default_if_missing_v.hpp" #include "../internal/has_default_val_v.hpp" #include "../internal/has_reflection_method_v.hpp" #include "../internal/has_reflection_type_v.hpp" @@ -16,7 +17,6 @@ #include "../internal/is_deprecated.hpp" #include "../internal/is_description.hpp" #include "../internal/is_literal.hpp" -#include "../internal/is_underlying_enums_v.hpp" #include "../internal/is_validator.hpp" #include "../internal/processed_t.hpp" #include "../internal/ptr_cast.hpp" @@ -80,7 +80,7 @@ struct Parser { return Parser::read(_r, _var) .and_then(wrap_in_t); - } else if constexpr (ProcessorsType::default_if_missing_ || + } else if constexpr (internal::default_if_missing_v || internal::has_default_val_v) { return read_struct_with_default(_r, _var); diff --git a/include/rfl/parsing/Parser_enum.hpp b/include/rfl/parsing/Parser_enum.hpp index 9c156086..82716131 100644 --- a/include/rfl/parsing/Parser_enum.hpp +++ b/include/rfl/parsing/Parser_enum.hpp @@ -7,8 +7,9 @@ #include "../Result.hpp" #include "../config.hpp" #include "../enums.hpp" -#include "../thirdparty/enchantum/enchantum.hpp" #include "../internal/has_reflector.hpp" +#include "../internal/underlying_enums_v.hpp" +#include "../thirdparty/enchantum/enchantum.hpp" #include "AreReaderAndWriter.hpp" #include "Parent.hpp" #include "Parser_base.hpp" @@ -44,8 +45,8 @@ struct Parser { ProcessorsType>::read(_r, _var) .and_then(wrap_in_t); - } else if constexpr (ProcessorsType::underlying_enums_ || - schemaful::IsSchemafulReader) { + } else if constexpr (internal::underlying_enums_v || + schemaful::IsSchemafulReader) { static_assert(enchantum::ScopedEnum, "The enum must be a scoped enum in order to retrieve " "the underlying value."); @@ -62,8 +63,8 @@ struct Parser { if constexpr (internal::has_write_reflector) { Parser::ReflType, ProcessorsType>::write( _w, Reflector::from(_var), _parent); - } else if constexpr (ProcessorsType::underlying_enums_ || - schemaful::IsSchemafulWriter) { + } else if constexpr (internal::underlying_enums_v || + schemaful::IsSchemafulWriter) { const auto val = static_cast>(_var); ParentType::add_value(_w, val, _parent); } else { @@ -76,11 +77,11 @@ struct Parser { std::map* _definitions) { using U = std::remove_cvref_t; if constexpr (internal::has_read_reflector || - internal::has_write_reflector) { + internal::has_write_reflector) { return make_reference(_definitions); } else { return make_enum(_definitions); - } + } } private: @@ -88,7 +89,7 @@ struct Parser { static schema::Type make_enum( std::map* _definitions) { using Type = schema::Type; - if constexpr (ProcessorsType::underlying_enums_ || + if constexpr (internal::underlying_enums_v || schemaful::IsSchemafulReader) { return Type{Type::Integer{}}; } else if constexpr (enchantum::is_bitflag) { @@ -99,9 +100,10 @@ struct Parser { constexpr auto enumerators = get_enumerator_array(); for (const auto& [name, value] : enumerators) { auto desc = config::enum_descriptions::get(value); - described.values_.push_back(Type::DescribedLiteral::ValueWithDescription{ - .value_ = std::string(name), - .description_ = std::string(desc)}); + described.values_.push_back( + Type::DescribedLiteral::ValueWithDescription{ + .value_ = std::string(name), + .description_ = std::string(desc)}); } return Type{std::move(described)}; } else { @@ -119,8 +121,8 @@ struct Parser { const auto name = make_type_name(); if (_definitions->find(name) == _definitions->end()) { - (*_definitions)[name] = Parser::ReflType, - ProcessorsType>::to_schema(_definitions); + (*_definitions)[name] = Parser::ReflType, + ProcessorsType>::to_schema(_definitions); } return Type{Type::Reference{name}}; } diff --git a/include/rfl/parsing/Parser_named_tuple.hpp b/include/rfl/parsing/Parser_named_tuple.hpp index 3041e45f..3a03de2d 100644 --- a/include/rfl/parsing/Parser_named_tuple.hpp +++ b/include/rfl/parsing/Parser_named_tuple.hpp @@ -1,6 +1,10 @@ #ifndef RFL_PARSING_PARSER_NAMED_TUPLE_HPP_ #define RFL_PARSING_PARSER_NAMED_TUPLE_HPP_ +#include "../NamedTuple.hpp" +#include "../Processors.hpp" +#include "../internal/no_field_names_v.hpp" +#include "../internal/no_optionals_v.hpp" #include "NamedTupleParser.hpp" #include "Parser_base.hpp" @@ -8,14 +12,13 @@ namespace rfl { namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> : public NamedTupleParser< R, W, /*_ignore_empty_containers=*/false, - /*_all_required=*/ProcessorsType::all_required_, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> { -}; + /*_all_required=*/internal::no_optionals_v, + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; } // namespace parsing } // namespace rfl diff --git a/include/rfl/parsing/Parser_ptr.hpp b/include/rfl/parsing/Parser_ptr.hpp index c709e1a8..b602e64b 100644 --- a/include/rfl/parsing/Parser_ptr.hpp +++ b/include/rfl/parsing/Parser_ptr.hpp @@ -7,12 +7,12 @@ #include "../Ref.hpp" #include "../Result.hpp" #include "../always_false.hpp" +#include "../internal/allow_raw_ptrs_v.hpp" #include "Parent.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" -namespace rfl { -namespace parsing { +namespace rfl::parsing { template requires AreReaderAndWriter @@ -23,7 +23,7 @@ struct Parser { /// Expresses the variables as type T. static Result read(const R& _r, const InputVarType& _var) noexcept { - if constexpr (!ProcessorsType::allow_raw_ptrs_) { + if constexpr (!internal::allow_raw_ptrs_v) { static_assert( always_false_v, "Reading into raw pointers is dangerous and " @@ -63,7 +63,6 @@ struct Parser { } }; -} // namespace parsing -} // namespace rfl +} // namespace rfl::parsing #endif diff --git a/include/rfl/parsing/Parser_ref.hpp b/include/rfl/parsing/Parser_ref.hpp index c9af9b40..9f170e88 100644 --- a/include/rfl/parsing/Parser_ref.hpp +++ b/include/rfl/parsing/Parser_ref.hpp @@ -10,6 +10,7 @@ #include "../atomic/is_atomic.hpp" #include "../atomic/remove_atomic_t.hpp" #include "../atomic/set_atomic.hpp" +#include "../internal/default_if_missing_v.hpp" #include "../internal/has_default_val_v.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" @@ -27,7 +28,7 @@ struct Parser, ProcessorsType> { static_assert(!internal::has_default_val_v, "Atomic types cannot be mixed with rfl::DefaultVal"); - static_assert(!ProcessorsType::default_if_missing_, + static_assert(!internal::default_if_missing_v, "Atomic types cannot be mixed with rfl::DefaultIfMissing"); return Parser::read(_r, _var) diff --git a/include/rfl/parsing/Parser_rfl_tuple.hpp b/include/rfl/parsing/Parser_rfl_tuple.hpp index d536cc40..c10d0c67 100644 --- a/include/rfl/parsing/Parser_rfl_tuple.hpp +++ b/include/rfl/parsing/Parser_rfl_tuple.hpp @@ -2,6 +2,7 @@ #define RFL_PARSING_PARSER_RFL_TUPLE_HPP_ #include "../Tuple.hpp" +#include "../internal/no_optionals_v.hpp" #include "Parser_base.hpp" #include "TupleParser.hpp" @@ -9,12 +10,12 @@ namespace rfl { namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> - : public TupleParser> { -}; + : public TupleParser< + R, W, /*_ignore_empty_containers=*/false, + /*_all_required=*/internal::no_optionals_v, + ProcessorsType, rfl::Tuple> {}; } // namespace parsing } // namespace rfl diff --git a/include/rfl/parsing/Parser_rfl_variant.hpp b/include/rfl/parsing/Parser_rfl_variant.hpp index 63f598d5..88aa7c2d 100644 --- a/include/rfl/parsing/Parser_rfl_variant.hpp +++ b/include/rfl/parsing/Parser_rfl_variant.hpp @@ -7,6 +7,7 @@ #include "../Result.hpp" #include "../Variant.hpp" #include "../always_false.hpp" +#include "../internal/add_tags_to_variants_v.hpp" #include "../internal/all_fields.hpp" #include "../internal/nth_element_t.hpp" #include "FieldVariantParser.hpp" @@ -55,9 +56,11 @@ class Parser, ProcessorsType> { return _r.template read_union, V>(_u); }); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || - ProcessorsType::add_namespaced_tags_to_variants_) { - constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; + } else if constexpr (internal::add_tags_to_variants_v || + internal::add_namespaced_tags_to_variants_v< + ProcessorsType>) { + constexpr bool remove_namespaces = + internal::add_tags_to_variants_v; using FieldVariantType = rfl::Variant< VariantAlternativeWrapper...>; const auto from_field_variant = @@ -123,9 +126,11 @@ class Parser, ProcessorsType> { }, _variant); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || - ProcessorsType::add_namespaced_tags_to_variants_) { - constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; + } else if constexpr (internal::add_tags_to_variants_v || + internal::add_namespaced_tags_to_variants_v< + ProcessorsType>) { + constexpr bool remove_namespaces = + internal::add_tags_to_variants_v; using FieldVariantType = rfl::Variant...>; @@ -151,9 +156,11 @@ class Parser, ProcessorsType> { return FieldVariantParser::to_schema(_definitions); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || - ProcessorsType::add_namespaced_tags_to_variants_) { - constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; + } else if constexpr (internal::add_tags_to_variants_v || + internal::add_namespaced_tags_to_variants_v< + ProcessorsType>) { + constexpr bool remove_namespaces = + internal::add_tags_to_variants_v; using FieldVariantType = rfl::Variant< VariantAlternativeWrapper...>; return Parser::to_schema( diff --git a/include/rfl/parsing/Parser_shared_ptr.hpp b/include/rfl/parsing/Parser_shared_ptr.hpp index 78d21bdd..e405d9d3 100644 --- a/include/rfl/parsing/Parser_shared_ptr.hpp +++ b/include/rfl/parsing/Parser_shared_ptr.hpp @@ -11,6 +11,7 @@ #include "../atomic/is_atomic.hpp" #include "../atomic/remove_atomic_t.hpp" #include "../atomic/set_atomic.hpp" +#include "../internal/default_if_missing_v.hpp" #include "../internal/has_default_val_v.hpp" #include "Parent.hpp" #include "Parser_base.hpp" @@ -35,7 +36,7 @@ struct Parser, ProcessorsType> { static_assert(!internal::has_default_val_v, "Atomic types cannot be mixed with rfl::DefaultVal"); - static_assert(!ProcessorsType::default_if_missing_, + static_assert(!internal::default_if_missing_v, "Atomic types cannot be mixed with rfl::DefaultIfMissing"); return Parser::read(_r, _var) diff --git a/include/rfl/parsing/Parser_span.hpp b/include/rfl/parsing/Parser_span.hpp index 2593821c..e27ca75a 100644 --- a/include/rfl/parsing/Parser_span.hpp +++ b/include/rfl/parsing/Parser_span.hpp @@ -10,6 +10,7 @@ #include "../Result.hpp" #include "../always_false.hpp" +#include "../internal/allow_raw_ptrs_v.hpp" #include "Parent.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" @@ -24,7 +25,7 @@ struct Parser, ProcessorsType> { static Result> read(const R& _r, const InputVarType& _var) noexcept { - if constexpr (!ProcessorsType::allow_raw_ptrs_) { + if constexpr (!internal::allow_raw_ptrs_v) { static_assert( always_false_v, "Reading into std::span is dangerous and " diff --git a/include/rfl/parsing/Parser_string_view.hpp b/include/rfl/parsing/Parser_string_view.hpp index d09273d3..8b879d64 100644 --- a/include/rfl/parsing/Parser_string_view.hpp +++ b/include/rfl/parsing/Parser_string_view.hpp @@ -8,6 +8,7 @@ #include "../Result.hpp" #include "../always_false.hpp" +#include "../internal/allow_raw_ptrs_v.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" @@ -21,7 +22,7 @@ struct Parser { static Result read(const R& _r, const InputVarType& _var) noexcept { - if constexpr (!ProcessorsType::allow_raw_ptrs_) { + if constexpr (!internal::allow_raw_ptrs_v) { static_assert( always_false_v, "Reading into std::string_view is dangerous and " diff --git a/include/rfl/parsing/Parser_tagged_union.hpp b/include/rfl/parsing/Parser_tagged_union.hpp index 758dfeda..3abc55ca 100644 --- a/include/rfl/parsing/Parser_tagged_union.hpp +++ b/include/rfl/parsing/Parser_tagged_union.hpp @@ -8,6 +8,7 @@ #include "../Result.hpp" #include "../TaggedUnion.hpp" #include "../always_false.hpp" +#include "../internal/no_field_names_v.hpp" #include "../internal/strings/strings.hpp" #include "../named_tuple_t.hpp" #include "../visit.hpp" @@ -33,7 +34,8 @@ struct Parser, using InputObjectType = typename R::InputObjectType; using InputVarType = typename R::InputVarType; - constexpr static bool no_field_names_ = ProcessorsType::no_field_names_; + constexpr static bool no_field_names_ = + internal::no_field_names_v; using InputObjectOrArrayType = std::conditional_t +#include "../internal/no_optionals_v.hpp" #include "Parser_base.hpp" #include "TupleParser.hpp" @@ -10,12 +11,12 @@ namespace rfl { namespace parsing { template -requires AreReaderAndWriter> + requires AreReaderAndWriter> struct Parser, ProcessorsType> - : public TupleParser> { -}; + : public TupleParser< + R, W, /*_ignore_empty_containers=*/false, + /*_all_required=*/internal::no_optionals_v, + ProcessorsType, std::tuple> {}; } // namespace parsing } // namespace rfl diff --git a/include/rfl/parsing/Parser_unique_ptr.hpp b/include/rfl/parsing/Parser_unique_ptr.hpp index 2f65f0dd..3434bd8e 100644 --- a/include/rfl/parsing/Parser_unique_ptr.hpp +++ b/include/rfl/parsing/Parser_unique_ptr.hpp @@ -11,6 +11,7 @@ #include "../atomic/is_atomic.hpp" #include "../atomic/remove_atomic_t.hpp" #include "../atomic/set_atomic.hpp" +#include "../internal/default_if_missing_v.hpp" #include "../internal/has_default_val_v.hpp" #include "Parent.hpp" #include "Parser_base.hpp" @@ -35,7 +36,7 @@ struct Parser, ProcessorsType> { static_assert(!internal::has_default_val_v, "Atomic types cannot be mixed with rfl::DefaultVal"); - static_assert(!ProcessorsType::default_if_missing_, + static_assert(!internal::default_if_missing_v, "Atomic types cannot be mixed with rfl::DefaultIfMissing"); return Parser::read(_r, _var) diff --git a/include/rfl/parsing/Parser_variant.hpp b/include/rfl/parsing/Parser_variant.hpp index 0820858b..33b1cf08 100644 --- a/include/rfl/parsing/Parser_variant.hpp +++ b/include/rfl/parsing/Parser_variant.hpp @@ -11,6 +11,7 @@ #include "../Result.hpp" #include "../Variant.hpp" #include "../always_false.hpp" +#include "../internal/add_tags_to_variants_v.hpp" #include "../internal/all_fields.hpp" #include "../internal/to_ptr_field.hpp" #include "FieldVariantParser.hpp" @@ -71,9 +72,11 @@ class Parser, ProcessorsType> { return _r.template read_union, V>(_u); }); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || - ProcessorsType::add_namespaced_tags_to_variants_) { - constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; + } else if constexpr (internal::add_tags_to_variants_v || + internal::add_namespaced_tags_to_variants_v< + ProcessorsType>) { + constexpr bool remove_namespaces = + internal::add_tags_to_variants_v; using FieldVariantType = rfl::Variant< VariantAlternativeWrapper...>; const auto from_field_variant = @@ -151,9 +154,11 @@ class Parser, ProcessorsType> { }, _variant); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || - ProcessorsType::add_namespaced_tags_to_variants_) { - constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; + } else if constexpr (internal::add_tags_to_variants_v || + internal::add_namespaced_tags_to_variants_v< + ProcessorsType>) { + constexpr bool remove_namespaces = + internal::add_tags_to_variants_v; using FieldVariantType = rfl::Variant...>; @@ -179,9 +184,11 @@ class Parser, ProcessorsType> { return FieldVariantParser::to_schema(_definitions); - } else if constexpr (ProcessorsType::add_tags_to_variants_ || - ProcessorsType::add_namespaced_tags_to_variants_) { - constexpr bool remove_namespaces = ProcessorsType::add_tags_to_variants_; + } else if constexpr (internal::add_tags_to_variants_v || + internal::add_namespaced_tags_to_variants_v< + ProcessorsType>) { + constexpr bool remove_namespaces = + internal::add_tags_to_variants_v; using FieldVariantType = rfl::Variant< VariantAlternativeWrapper...>; return Parser::to_schema( diff --git a/include/rfl/parsing/ViewReader.hpp b/include/rfl/parsing/ViewReader.hpp index 990fa8a2..8e761f2d 100644 --- a/include/rfl/parsing/ViewReader.hpp +++ b/include/rfl/parsing/ViewReader.hpp @@ -11,6 +11,7 @@ #include "../Result.hpp" #include "../Tuple.hpp" #include "../internal/is_array.hpp" +#include "../internal/no_extra_fields_v.hpp" #include "Parser_base.hpp" #include "schemaful/IsSchemafulReader.hpp" @@ -136,7 +137,7 @@ class ViewReader { assign_to_extra_fields(_r, _current_name_or_index, _var, _view, _errors, _found, _set); } - } else if constexpr (ProcessorsType::no_extra_fields_) { + } else if constexpr (internal::no_extra_fields_v) { static_assert( !schemaful::IsSchemafulReader, "Passing rfl::NoExtraFields to a schemaful format does not make " diff --git a/include/rfl/parsing/ViewReaderWithDefault.hpp b/include/rfl/parsing/ViewReaderWithDefault.hpp index fa7d1002..4796a262 100644 --- a/include/rfl/parsing/ViewReaderWithDefault.hpp +++ b/include/rfl/parsing/ViewReaderWithDefault.hpp @@ -12,6 +12,7 @@ #include "../Result.hpp" #include "../Tuple.hpp" #include "../internal/is_array.hpp" +#include "../internal/no_extra_fields_v.hpp" #include "Parser_base.hpp" namespace rfl::parsing { @@ -112,7 +113,7 @@ class ViewReaderWithDefault { if (!already_assigned) { assign_to_extra_fields(_r, _current_name, _var, _view, _errors); } - } else if constexpr (ProcessorsType::no_extra_fields_) { + } else if constexpr (internal::no_extra_fields_v) { if (!already_assigned) { std::stringstream stream; stream << "Value named '" << std::string(_current_name) diff --git a/include/rfl/parsing/tabular/ArrowReader.hpp b/include/rfl/parsing/tabular/ArrowReader.hpp index d281608c..90f18171 100644 --- a/include/rfl/parsing/tabular/ArrowReader.hpp +++ b/include/rfl/parsing/tabular/ArrowReader.hpp @@ -14,6 +14,11 @@ #include "../../Tuple.hpp" #include "../../apply.hpp" #include "../../get.hpp" +#include "../../internal/add_tags_to_variants_v.hpp" +#include "../../internal/default_if_missing_v.hpp" +#include "../../internal/no_extra_fields_v.hpp" +#include "../../internal/no_field_names_v.hpp" +#include "../../internal/no_optionals_v.hpp" #include "../../named_tuple_t.hpp" #include "../../to_view.hpp" #include "../../view_t.hpp" @@ -24,18 +29,19 @@ namespace rfl::parsing::tabular { template class ArrowReader { - static_assert(!Processors::add_tags_to_variants_, + static_assert(!internal::add_tags_to_variants_v>, "rfl::AddTagsToVariants cannot be used for tabular data."); - static_assert(!Processors::add_namespaced_tags_to_variants_, - "rfl::AddNamespacedTagsToVariants cannot be used for tabular data."); - static_assert(!Processors::all_required_, + static_assert( + !internal::add_namespaced_tags_to_variants_v>, + "rfl::AddNamespacedTagsToVariants cannot be used for tabular data."); + static_assert(!internal::no_optionals_v>, "rfl::NoOptionals cannot be used for tabular data."); - static_assert(!Processors::default_if_missing_, + static_assert(!internal::default_if_missing_v>, "rfl::DefaultIfMissing cannot be used for tabular data."); - static_assert(!Processors::no_extra_fields_, + static_assert(!internal::no_extra_fields_v>, "rfl::NoExtraFields cannot be used for tabular data (neither " "can rfl::ExtraFields)."); - static_assert(!Processors::no_field_names_, + static_assert(!internal::no_field_names_v>, "rfl::NoFieldNames cannot be used for tabular data."); public: diff --git a/include/rfl/parsing/tabular/ArrowWriter.hpp b/include/rfl/parsing/tabular/ArrowWriter.hpp index fbe1444d..087c5761 100644 --- a/include/rfl/parsing/tabular/ArrowWriter.hpp +++ b/include/rfl/parsing/tabular/ArrowWriter.hpp @@ -10,6 +10,11 @@ #include "../../Processors.hpp" #include "../../Tuple.hpp" #include "../../get.hpp" +#include "../../internal/add_tags_to_variants_v.hpp" +#include "../../internal/default_if_missing_v.hpp" +#include "../../internal/no_extra_fields_v.hpp" +#include "../../internal/no_field_names_v.hpp" +#include "../../internal/no_optionals_v.hpp" #include "../../named_tuple_t.hpp" #include "../../to_view.hpp" #include "add_to_builder.hpp" @@ -21,18 +26,19 @@ namespace rfl::parsing::tabular { template class ArrowWriter { - static_assert(!Processors::add_tags_to_variants_, + static_assert(!internal::add_tags_to_variants_v>, "rfl::AddTagsToVariants cannot be used for tabular data."); - static_assert(!Processors::add_namespaced_tags_to_variants_, - "rfl::AddNamespacedTagsToVariants cannot be used for tabular data."); - static_assert(!Processors::all_required_, + static_assert( + !internal::add_namespaced_tags_to_variants_v>, + "rfl::AddNamespacedTagsToVariants cannot be used for tabular data."); + static_assert(!internal::no_optionals_v>, "rfl::NoOptionals cannot be used for tabular data."); - static_assert(!Processors::default_if_missing_, + static_assert(!internal::default_if_missing_v>, "rfl::DefaultIfMissing cannot be used for tabular data."); - static_assert(!Processors::no_extra_fields_, + static_assert(!internal::no_extra_fields_v>, "rfl::NoExtraFields cannot be used for tabular data (neither " "can rfl::ExtraFields)."); - static_assert(!Processors::no_field_names_, + static_assert(!internal::no_field_names_v>, "rfl::NoFieldNames cannot be used for tabular data."); public: diff --git a/include/rfl/toml/read.hpp b/include/rfl/toml/read.hpp index ae7c2168..6f063ae4 100644 --- a/include/rfl/toml/read.hpp +++ b/include/rfl/toml/read.hpp @@ -7,6 +7,7 @@ #include #include "../Processors.hpp" +#include "../internal/no_field_names_v.hpp" #include "../internal/wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" @@ -20,7 +21,7 @@ template auto read(InputVarType _var) { const auto r = Reader(); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); return Parser::read(r, _var); diff --git a/include/rfl/toml/write.hpp b/include/rfl/toml/write.hpp index 9d4f306f..e7de4a33 100644 --- a/include/rfl/toml/write.hpp +++ b/include/rfl/toml/write.hpp @@ -8,6 +8,7 @@ #include #include "../Processors.hpp" +#include "../internal/no_field_names_v.hpp" #include "../parsing/Parent.hpp" #include "Parser.hpp" @@ -21,7 +22,7 @@ std::ostream& write(const auto& _obj, std::ostream& _stream) { ::toml::table root; auto w = Writer(&root); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); Parser::write(w, _obj, typename ParentType::Root{}); @@ -38,7 +39,7 @@ std::string write(const auto& _obj) { ::toml::table root; auto w = Writer(&root); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); Parser::write(w, _obj, typename ParentType::Root{}); diff --git a/include/rfl/ubjson/Parser.hpp b/include/rfl/ubjson/Parser.hpp index 534de1ae..ce65680b 100644 --- a/include/rfl/ubjson/Parser.hpp +++ b/include/rfl/ubjson/Parser.hpp @@ -2,6 +2,7 @@ #define RFL_UBJSON_PARSER_HPP_ #include "../Tuple.hpp" +#include "../internal/no_field_names_v.hpp" #include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" @@ -20,8 +21,8 @@ struct Parser, ubjson::Reader, ubjson::Writer, /*_ignore_empty_containers=*/false, /*_all_required=*/true, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> {}; + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; template requires AreReaderAndWriter> diff --git a/include/rfl/xml/Parser.hpp b/include/rfl/xml/Parser.hpp index f04b7183..71e63168 100644 --- a/include/rfl/xml/Parser.hpp +++ b/include/rfl/xml/Parser.hpp @@ -6,6 +6,7 @@ #include "../Generic.hpp" #include "../always_false.hpp" #include "../internal/is_attribute.hpp" +#include "../internal/no_optionals_v.hpp" #include "../parsing/NamedTupleParser.hpp" #include "../parsing/Parser.hpp" #include "Reader.hpp" @@ -21,11 +22,11 @@ template NamedTuple> struct Parser, ProcessorsType> - : public NamedTupleParser {}; + : public NamedTupleParser< + xml::Reader, xml::Writer, + /*_ignore_empty_containers=*/true, + /*_all_required=*/internal::no_optionals_v, + /*_no_field_names_=*/false, ProcessorsType, FieldTypes...> {}; /// The generic parser is also special, because we need to ignore empty /// containers, which means that we need to try to read the value as an array or diff --git a/include/rfl/xml/read.hpp b/include/rfl/xml/read.hpp index ef2b0c9c..54d7f775 100644 --- a/include/rfl/xml/read.hpp +++ b/include/rfl/xml/read.hpp @@ -8,6 +8,7 @@ #include "../Processors.hpp" #include "../internal/get_type_name.hpp" +#include "../internal/no_field_names_v.hpp" #include "../internal/remove_namespaces.hpp" #include "Parser.hpp" #include "Reader.hpp" @@ -21,7 +22,7 @@ template auto read(const InputVarType& _var) { const auto r = Reader(); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); return Parser::read(r, _var); diff --git a/include/rfl/xml/write.hpp b/include/rfl/xml/write.hpp index fd2859fb..e0879734 100644 --- a/include/rfl/xml/write.hpp +++ b/include/rfl/xml/write.hpp @@ -10,6 +10,7 @@ #include "../Processors.hpp" #include "../internal/StringLiteral.hpp" #include "../internal/get_type_name.hpp" +#include "../internal/no_field_names_v.hpp" #include "../internal/remove_namespaces.hpp" #include "../parsing/Parent.hpp" #include "Parser.hpp" @@ -53,7 +54,7 @@ std::ostream& write(const auto& _obj, std::ostream& _stream, auto w = Writer(doc, root_name.str()); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); Parser::write(w, _obj, typename ParentType::Root{}); diff --git a/include/rfl/yaml/read.hpp b/include/rfl/yaml/read.hpp index 36a34177..df51ecee 100644 --- a/include/rfl/yaml/read.hpp +++ b/include/rfl/yaml/read.hpp @@ -8,9 +8,11 @@ #include #include "../Processors.hpp" +#include "../internal/no_field_names_v.hpp" #include "../internal/wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" + namespace rfl { namespace yaml { @@ -21,7 +23,7 @@ template auto read(const InputVarType& _var) { const auto r = Reader(); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); return Parser::read(r, _var); diff --git a/include/rfl/yaml/write.hpp b/include/rfl/yaml/write.hpp index 48cadc25..5a9d44c4 100644 --- a/include/rfl/yaml/write.hpp +++ b/include/rfl/yaml/write.hpp @@ -9,6 +9,7 @@ #include #include "../Processors.hpp" +#include "../internal/no_field_names_v.hpp" #include "../parsing/Parent.hpp" #include "Parser.hpp" @@ -23,7 +24,7 @@ std::ostream& write(const auto& _obj, std::ostream& _stream) { const auto out = Ref::make(); auto w = Writer(out); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); Parser::write(w, _obj, typename ParentType::Root{}); @@ -39,7 +40,7 @@ std::string write(const auto& _obj) { const auto out = Ref::make(); auto w = Writer(out); using ProcessorsType = Processors; - static_assert(!ProcessorsType::no_field_names_, + static_assert(!internal::no_field_names_v, "The NoFieldNames processor is not supported for BSON, XML, " "TOML, or YAML."); Parser::write(w, _obj, typename ParentType::Root{}); diff --git a/include/rfl/yas/Parser.hpp b/include/rfl/yas/Parser.hpp index 9403b032..ce5e4c83 100644 --- a/include/rfl/yas/Parser.hpp +++ b/include/rfl/yas/Parser.hpp @@ -5,6 +5,7 @@ #include "../NamedTuple.hpp" #include "../Tuple.hpp" #include "../always_false.hpp" +#include "../internal/no_field_names_v.hpp" #include "../parsing/Parser.hpp" #include "Reader.hpp" #include "Writer.hpp" @@ -24,8 +25,8 @@ struct Parser, yas::Reader, yas::Writer, /*_ignore_empty_containers=*/false, /*_all_required=*/true, - /*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType, - FieldTypes...> {}; + /*_no_field_names=*/internal::no_field_names_v, + ProcessorsType, FieldTypes...> {}; template requires AreReaderAndWriter> diff --git a/tests/json/test_no_extra_fields_with_default.cpp b/tests/json/test_no_extra_fields_with_default.cpp index 96f8a288..b2b87abd 100644 --- a/tests/json/test_no_extra_fields_with_default.cpp +++ b/tests/json/test_no_extra_fields_with_default.cpp @@ -17,5 +17,12 @@ TEST(json, test_no_extra_fields_with_default) { R"({"first_name":"Homer","last_name":"Simpson","extra_field":0})"); EXPECT_EQ(homer && true, false); + + using P = rfl::Processors; + + auto homer2 = rfl::json::read( + R"({"first_name":"Homer","last_name":"Simpson","extra_field":0})"); + + EXPECT_EQ(homer2 && true, false); } } // namespace test_no_extra_fields_with_default