mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 08:46:19 +08:00
Fixed return type
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user