Fixed return type

This commit is contained in:
Patrick Urbanke
2024-01-04 22:19:52 +01:00
parent b63c246f92
commit 5e9a660fa2
3 changed files with 8 additions and 3 deletions
+5 -1
View File
@@ -6,6 +6,7 @@
#include <istream>
#include <string>
#include "../internal/wrap_in_rfl_array_t.hpp"
#include "Parser.hpp"
#include "Reader.hpp"
@@ -24,9 +25,12 @@ auto read(const InputVarType& _obj) {
/// Parses an object from JSON using reflection.
template <class T>
auto read(const std::string& _json_str) {
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _json_str) {
using PtrType = std::unique_ptr<yyjson_doc, void (*)(yyjson_doc*)>;
yyjson_doc* doc = yyjson_read(_json_str.c_str(), _json_str.size(), 0);
if (!doc) {
return Error("Could not parse document!");
}
const auto ptr = PtrType(doc, yyjson_doc_free);
return read<T>(InputVarType(yyjson_doc_get_root(doc)));
}
+1 -1
View File
@@ -24,7 +24,7 @@ auto read(const InputVarType& _var) {
/// Parses an object from XML using reflection.
template <class T>
auto read(const std::string& _xml_str) {
Result<T> read(const std::string& _xml_str) {
pugi::xml_document doc;
const auto result = doc.load_string(_xml_str.c_str());
if (!result) {
+2 -1
View File
@@ -6,6 +6,7 @@
#include <istream>
#include <string>
#include "../internal/wrap_in_rfl_array_t.hpp"
#include "Parser.hpp"
#include "Reader.hpp"
@@ -23,7 +24,7 @@ auto read(const InputVarType& _var) {
/// Parses an object from YAML using reflection.
template <class T>
auto read(const std::string& _yaml_str) {
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _yaml_str) {
try {
const auto var = InputVarType(YAML::Load(_yaml_str));
return read<T>(var);