From c6d30125104b377cabd2e9534686dfae3064df31 Mon Sep 17 00:00:00 2001 From: hazby2002 <1094501217@qq.com> Date: Tue, 2 Jan 2024 18:03:40 +0800 Subject: [PATCH] Remove Result. --- include/rfl/Result.hpp | 11 ----------- include/rfl/flexbuf/read.hpp | 9 +++++---- include/rfl/json/read.hpp | 7 ++++--- include/rfl/parsing/IsReader.hpp | 29 +++++++++++++++++------------ include/rfl/xml/read.hpp | 7 ++++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/include/rfl/Result.hpp b/include/rfl/Result.hpp index b3be13ef..95d7316a 100644 --- a/include/rfl/Result.hpp +++ b/include/rfl/Result.hpp @@ -342,17 +342,6 @@ class Result { std::variant t_or_err_; }; -/// This is simply to get the compilation to pass. -template -struct Result : public Result> { - using StdArray = internal::to_std_array_t; - using Base = Result; - using Base::Base; - - Result(const Base& other) : Base(other) {} - Result(Base&& other) : Base(std::move(other)) {} -}; - } // namespace rfl #endif diff --git a/include/rfl/flexbuf/read.hpp b/include/rfl/flexbuf/read.hpp index 9c320ca4..7f596b93 100644 --- a/include/rfl/flexbuf/read.hpp +++ b/include/rfl/flexbuf/read.hpp @@ -7,6 +7,7 @@ #include #include "../Result.hpp" +#include "../wrap_in_rfl_array_t.hpp" #include "Parser.hpp" namespace rfl { @@ -16,14 +17,14 @@ using InputVarType = typename Reader::InputVarType; /// Parses an object from flexbuf var. template -Result read(const InputVarType& _obj) { +Result> read(const InputVarType& _obj) { const auto r = Reader(); return Parser::read(r, _obj); } /// Parses an object from flexbuf using reflection. template -Result read(const char* _bytes, const size_t _size) { +Result> read(const char* _bytes, const size_t _size) { const InputVarType root = flexbuffers::GetRoot(reinterpret_cast(_bytes), _size); return read(root); @@ -31,13 +32,13 @@ Result read(const char* _bytes, const size_t _size) { /// Parses an object from flexbuf using reflection. template -Result read(const std::vector& _bytes) { +Result> read(const std::vector& _bytes) { return read(_bytes.data(), _bytes.size()); } /// Parses an object directly from a stream. template -Result read(std::istream& _stream) { +Result> read(std::istream& _stream) { std::istreambuf_iterator begin(_stream), end; const auto bytes = std::vector(begin, end); return read(bytes.data(), bytes.size()); diff --git a/include/rfl/json/read.hpp b/include/rfl/json/read.hpp index 9de24ba2..cea84ab1 100644 --- a/include/rfl/json/read.hpp +++ b/include/rfl/json/read.hpp @@ -6,6 +6,7 @@ #include #include +#include "../wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" @@ -17,14 +18,14 @@ using InputVarType = typename Reader::InputVarType; /// Parses an object from a JSON var. template -Result read(const InputVarType& _obj) { +Result> read(const InputVarType& _obj) { const auto r = Reader(); return Parser::read(r, _obj); } /// Parses an object from JSON using reflection. template -Result read(const std::string& _json_str) { +Result> read(const std::string& _json_str) { using PtrType = std::unique_ptr; yyjson_doc* doc = yyjson_read(_json_str.c_str(), _json_str.size(), 0); const auto ptr = PtrType(doc, yyjson_doc_free); @@ -33,7 +34,7 @@ Result read(const std::string& _json_str) { /// Parses an object from a stringstream. template -Result read(std::istream& _stream) { +Result> read(std::istream& _stream) { const auto json_str = std::string(std::istreambuf_iterator(_stream), std::istreambuf_iterator()); return read(json_str); diff --git a/include/rfl/parsing/IsReader.hpp b/include/rfl/parsing/IsReader.hpp index b8af6333..bd845eb6 100644 --- a/include/rfl/parsing/IsReader.hpp +++ b/include/rfl/parsing/IsReader.hpp @@ -10,16 +10,17 @@ #include #include "../Result.hpp" +#include "../internal/is_basic_type.hpp" +#include "../wrap_in_rfl_array_t.hpp" namespace rfl { namespace parsing { template -concept IsReader = requires(R r, std::string name, - std::function fct, - typename R::InputArrayType arr, - typename R::InputObjectType obj, - typename R::InputVarType var) { +concept IsReader = requires( + R r, std::string name, std::function fct, + typename R::InputArrayType arr, typename R::InputObjectType obj, + typename R::InputVarType var) { /// Any Reader needs to define the following: /// /// 1) An InputArrayType, which must be an array-like data structure. @@ -34,21 +35,23 @@ concept IsReader = requires(R r, std::string name, /// Retrieves a particular field from an object. { r.get_field(name, obj) - } -> std::same_as>; + } -> std::same_as>; /// Determines whether a variable is empty (the NULL type). { r.is_empty(var) } -> std::same_as; /// Transforms var to a basic type (bool, integral, /// floating point, std::string) - { r.template to_basic_type(var) } -> std::same_as>; + { + r.template to_basic_type>(var) + } -> std::same_as>>; /// fct is a function that turns the field name into the field index of the /// struct. It returns -1, if the fields does not exist on the struct. This /// returns an std::array that can be used to build up the struct. { r.template to_fields_array<6>(fct, obj) - } -> std::same_as, 6>>; + } -> std::same_as, 6>>; /// Casts var as an InputArrayType. { r.to_array(var) } -> std::same_as>; @@ -57,13 +60,13 @@ concept IsReader = requires(R r, std::string name, /// a vector. { r.to_map(obj) - } -> std::same_as< - std::vector>>; + } -> std::same_as< + std::vector>>; /// Casts var as an InputObjectType. { r.to_object(var) - } -> std::same_as>; + } -> std::same_as>; /// Iterates through an array and writes the contained vars into /// a vector. @@ -71,7 +74,9 @@ concept IsReader = requires(R r, std::string name, /// Uses the custom constructor, if it has been determined that T has one /// (see above). - { r.template use_custom_constructor(var) } -> std::same_as>; + { + r.template use_custom_constructor>(var) + } -> std::same_as>>; }; } // namespace parsing diff --git a/include/rfl/xml/read.hpp b/include/rfl/xml/read.hpp index 3aa49a29..0ef26ed4 100644 --- a/include/rfl/xml/read.hpp +++ b/include/rfl/xml/read.hpp @@ -7,6 +7,7 @@ #include "../internal/get_type_name.hpp" #include "../internal/remove_namespaces.hpp" +#include "../wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" @@ -17,14 +18,14 @@ using InputVarType = typename Reader::InputVarType; /// Parses an object from a XML var. template -Result read(const InputVarType& _var) { +Result> read(const InputVarType& _var) { const auto r = Reader(); return Parser::read(r, _var); } /// Parses an object from XML using reflection. template -Result read(const std::string& _xml_str) { +Result> read(const std::string& _xml_str) { pugi::xml_document doc; const auto result = doc.load_string(_xml_str.c_str()); if (!result) { @@ -37,7 +38,7 @@ Result read(const std::string& _xml_str) { /// Parses an object from a stringstream. template -Result read(std::istream& _stream) { +Result> read(std::istream& _stream) { const auto xml_str = std::string(std::istreambuf_iterator(_stream), std::istreambuf_iterator()); return read(xml_str);