diff --git a/include/rfl/internal/is_basic_type.hpp b/include/rfl/internal/is_basic_type.hpp new file mode 100644 index 00000000..f4d0ad1b --- /dev/null +++ b/include/rfl/internal/is_basic_type.hpp @@ -0,0 +1,19 @@ +#ifndef RFL_INTERNAL_ISBASICTYPE_HPP_ +#define RFL_INTERNAL_ISBASICTYPE_HPP_ + +#include +#include + +namespace rfl { +namespace internal { + +template +constexpr bool is_basic_type_v = std::is_floating_point_v> || + std::is_integral_v> || + std::is_same, std::string>() || + std::is_same, bool>(); + +} // namespace internal +} // namespace rfl + +#endif diff --git a/include/rfl/parsing/Parser.hpp b/include/rfl/parsing/Parser.hpp index d6395ab0..d6b291ea 100644 --- a/include/rfl/parsing/Parser.hpp +++ b/include/rfl/parsing/Parser.hpp @@ -33,6 +33,7 @@ #include "rfl/internal/all_fields.hpp" #include "rfl/internal/has_reflection_method_v.hpp" #include "rfl/internal/has_reflection_type_v.hpp" +#include "rfl/internal/is_basic_type.hpp" #include "rfl/internal/no_duplicate_field_names.hpp" #include "rfl/internal/to_ptr_named_tuple.hpp" #include "rfl/named_tuple_t.hpp" @@ -77,8 +78,7 @@ struct Parser { }; return Parser::read(_r, _var).and_then( wrap_in_t); - } else if constexpr (std::is_class_v && - !std::is_same()) { + } else if constexpr (std::is_class_v && std::is_aggregate_v) { using NamedTupleType = named_tuple_t; const auto to_struct = [](NamedTupleType&& _n) -> Result { try { @@ -89,8 +89,14 @@ struct Parser { }; return Parser::read(_r, _var).and_then( to_struct); - } else { + } else if constexpr (internal::is_basic_type_v) { return _r.template to_basic_type>(_var); + } else { + static_assert( + always_false_v, + "Unsupported type. Please refer to the sections on custom " + "classes and custom parsers for information on how add " + "support for your own classes."); } } } @@ -111,8 +117,14 @@ struct Parser { const auto ptr_named_tuple = internal::to_ptr_named_tuple(_var); using PtrNamedTupleType = std::decay_t; return Parser::write(_w, ptr_named_tuple); - } else { + } else if constexpr (internal::is_basic_type_v) { return _w.from_basic_type(_var); + } else { + static_assert( + always_false_v, + "Unsupported type. Please refer to the sections on custom " + "classes and custom parsers for information on how add " + "support for your own classes."); } } }; @@ -125,11 +137,12 @@ struct Parser { /// Expresses the variables as type T. static Result read(const R& _r, const InputVarType& _var) noexcept { - static_assert( - always_false_v, - "Reading into raw pointers is dangerous and therefore unsupported. " - "Please consider using std::unique_ptr, rfl::Box, std::shared_ptr, " - "rfl::Ref or std::optional instead."); + static_assert(always_false_v, + "Reading into raw pointers is dangerous and " + "therefore unsupported. " + "Please consider using std::unique_ptr, rfl::Box, " + "std::shared_ptr, " + "rfl::Ref or std::optional instead."); return Error("Unsupported."); } @@ -269,8 +282,8 @@ struct Parser> { // ---------------------------------------------------------------------------- -/// Used for maps for which the key type is std::string. These are represented -/// as objects. +/// Used for maps for which the key type is std::string. These are +/// represented as objects. template requires AreReaderAndWriter struct MapParser {