Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 2 additions & 52 deletions include/rfl/Processors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
#include <type_traits>
#include <utility>

#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 {

Expand All @@ -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 <class T, class NamedTupleType>
static auto process(NamedTupleType&& _named_tuple) {
return _named_tuple;
return std::forward<NamedTupleType>(_named_tuple);
}
};

template <class Head, class... Tail>
struct Processors<Head, Tail...> {
static constexpr bool add_tags_to_variants_ =
std::disjunction_v<internal::is_add_tags_to_variants<Head>,
internal::is_add_tags_to_variants<Tail>...>;

static constexpr bool add_namespaced_tags_to_variants_ =
std::disjunction_v<internal::is_add_namespaced_tags_to_variants<Head>,
internal::is_add_namespaced_tags_to_variants<Tail>...>;

static constexpr bool allow_raw_ptrs_ =
std::disjunction_v<internal::is_allow_raw_ptrs<Head>,
internal::is_allow_raw_ptrs<Tail>...>;

static constexpr bool all_required_ =
std::disjunction_v<internal::is_no_optionals<Head>,
internal::is_no_optionals<Tail>...>;

static constexpr bool default_if_missing_ =
std::disjunction_v<internal::is_default_if_missing<Head>,
internal::is_default_if_missing<Tail>...>;

static constexpr bool no_extra_fields_ =
std::disjunction_v<internal::is_no_extra_fields<Head>,
internal::is_no_extra_fields<Tail>...>;

static constexpr bool no_field_names_ =
std::disjunction_v<internal::is_no_field_names<Head>,
internal::is_no_field_names<Tail>...>;

static constexpr bool underlying_enums_ =
std::disjunction_v<internal::is_underlying_enums<Head>,
internal::is_underlying_enums<Tail>...>;

template <class T, class NamedTupleType>
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<Tail...>::template process<T>(
Head::template process<T>(std::move(_named_tuple)));
}
Expand Down
5 changes: 3 additions & 2 deletions include/rfl/avro/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,8 +26,8 @@ struct Parser<avro::Reader, avro::Writer, NamedTuple<FieldTypes...>,
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>,
ProcessorsType, FieldTypes...> {};

template <class ProcessorsType, class... Ts>
requires AreReaderAndWriter<avro::Reader, avro::Writer, rfl::Tuple<Ts...>>
Expand Down
5 changes: 3 additions & 2 deletions include/rfl/boost_serialization/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,8 +29,8 @@ struct Parser<boost_serialization::Reader<IArchive>,
boost_serialization::Writer<OArchive>,
/*_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>,
ProcessorsType, FieldTypes...> {};

template <class IArchive, class OArchive, class ProcessorsType, class... Ts>
requires AreReaderAndWriter<boost_serialization::Reader<IArchive>,
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/bson/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,7 +24,7 @@ template <class T, class... Ps>
Result<internal::wrap_in_rfl_array_t<T>> read(const InputVarType& _obj) {
const auto r = Reader();
using ProcessorsType = Processors<Ps...>;
static_assert(!ProcessorsType::no_field_names_,
static_assert(!internal::no_field_names_v<ProcessorsType>,
"The NoFieldNames processor is not supported for BSON, XML, "
"TOML, or YAML.");
return Parser<T, ProcessorsType>::read(r, _obj);
Expand Down
3 changes: 2 additions & 1 deletion include/rfl/bson/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,7 +33,7 @@ Result<std::pair<uint8_t*, size_t>> to_buffer(const auto& _obj) noexcept {
bson_writer_begin(bson_writer.get(), &doc);
const auto rfl_writer = Writer(doc);
using ProcessorsType = Processors<Ps...>;
static_assert(!ProcessorsType::no_field_names_,
static_assert(!internal::no_field_names_v<ProcessorsType>,
"The NoFieldNames processor is not supported for BSON, XML, "
"TOML, or YAML.");
const auto nothing = [&]() -> Result<Nothing> {
Expand Down
5 changes: 3 additions & 2 deletions include/rfl/capnproto/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,8 +25,8 @@ struct Parser<capnproto::Reader, capnproto::Writer, NamedTuple<FieldTypes...>,
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>,
ProcessorsType, FieldTypes...> {};

template <class ProcessorsType, class... Ts>
requires AreReaderAndWriter<capnproto::Reader, capnproto::Writer,
Expand Down
5 changes: 3 additions & 2 deletions include/rfl/cereal/Parser.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RFL_CEREAL_PARSER_HPP_
#define RFL_CEREAL_PARSER_HPP_

#include "../internal/no_field_names_v.hpp"
#include "../parsing/Parser.hpp"
#include "Reader.hpp"
#include "Writer.hpp"
Expand All @@ -20,8 +21,8 @@ struct Parser<cereal::Reader, cereal::Writer, NamedTuple<FieldTypes...>,
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>,
ProcessorsType, FieldTypes...> {};

template <class ProcessorsType, class... Ts>
requires AreReaderAndWriter<cereal::Reader, cereal::Writer, rfl::Tuple<Ts...>>
Expand Down
60 changes: 60 additions & 0 deletions include/rfl/internal/add_tags_to_variants_v.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef RFL_INTERNAL_ADDTAGSTOVARIANTS_HPP_
#define RFL_INTERNAL_ADDTAGSTOVARIANTS_HPP_

#include <type_traits>

#include "../AddTagsToVariants.hpp"
#include "../Processors.hpp"

namespace rfl::internal {

template <class T>
class add_tags_to_variants;

template <class T>
class add_tags_to_variants : public std::false_type {};
Comment thread
liuzicheng1987 marked this conversation as resolved.

template <>
class add_tags_to_variants<AddTagsToVariants> : public std::true_type {};

template <class Head, class... Tail>
struct add_tags_to_variants<Processors<Head, Tail...>> {
static constexpr bool value = (add_tags_to_variants<Head>::value || ... ||
add_tags_to_variants<Tail>::value);
};

template <class T>
constexpr bool add_tags_to_variants_v =
add_tags_to_variants<std::remove_cvref_t<std::remove_pointer_t<T>>>::value;

template <class T>
class add_namespaced_tags_to_variants;

template <class T>
class add_namespaced_tags_to_variants : public std::false_type {};

template <>
class add_namespaced_tags_to_variants<AddNamespacedTagsToVariants>
: public std::true_type {};

template <class Head, class... Tail>
struct add_namespaced_tags_to_variants<Processors<Head, Tail...>> {
static constexpr bool value =
(add_namespaced_tags_to_variants<Head>::value || ... ||
add_namespaced_tags_to_variants<Tail>::value);

static_assert(
!add_tags_to_variants<Processors<Head, Tail...>>::value ||
!add_namespaced_tags_to_variants<Processors<Head, Tail...>>::value,
"Cannot use both AddTagsToVariants and AddNamespacedTagsToVariants in "
"the same Processors list.");
};

template <class T>
constexpr bool add_namespaced_tags_to_variants_v =
add_namespaced_tags_to_variants<
std::remove_cvref_t<std::remove_pointer_t<T>>>::value;

} // namespace rfl::internal

#endif
32 changes: 32 additions & 0 deletions include/rfl/internal/allow_raw_ptrs_v.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef RFL_INTERNAL_ALLOWRAWPTRS_HPP_
#define RFL_INTERNAL_ALLOWRAWPTRS_HPP_

#include <type_traits>

#include "../AllowRawPtrs.hpp"
#include "../Processors.hpp"

namespace rfl::internal {

template <class T>
class allow_raw_ptrs;

template <class T>
class allow_raw_ptrs : public std::false_type {};

template <>
class allow_raw_ptrs<AllowRawPtrs> : public std::true_type {};

template <class Head, class... Tail>
struct allow_raw_ptrs<Processors<Head, Tail...>> {
static constexpr bool value =
(allow_raw_ptrs<Head>::value || ... || allow_raw_ptrs<Tail>::value);
};

template <class T>
constexpr bool allow_raw_ptrs_v =
allow_raw_ptrs<std::remove_cvref_t<std::remove_pointer_t<T>>>::value;

} // namespace rfl::internal

#endif
32 changes: 32 additions & 0 deletions include/rfl/internal/default_if_missing_v.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef RFL_INTERNAL_DEFAULTIFMISSING_HPP_
#define RFL_INTERNAL_DEFAULTIFMISSING_HPP_

#include <type_traits>

#include "../DefaultIfMissing.hpp"
#include "../Processors.hpp"

namespace rfl::internal {

template <class T>
class default_if_missing;

template <class T>
class default_if_missing : public std::false_type {};

template <>
class default_if_missing<DefaultIfMissing> : public std::true_type {};

template <class Head, class... Tail>
struct default_if_missing<Processors<Head, Tail...>> {
static constexpr bool value = (default_if_missing<Head>::value || ... ||
default_if_missing<Tail>::value);
};

template <class T>
constexpr bool default_if_missing_v =
default_if_missing<std::remove_cvref_t<std::remove_pointer_t<T>>>::value;

} // namespace rfl::internal

#endif
40 changes: 0 additions & 40 deletions include/rfl/internal/is_add_tags_to_variants_v.hpp

This file was deleted.

27 changes: 0 additions & 27 deletions include/rfl/internal/is_allow_raw_ptrs_v.hpp

This file was deleted.

Loading
Loading