weh
This commit is contained in:
parent
bd402f57f5
commit
3ea546fe08
166 changed files with 18360 additions and 18199 deletions
|
@ -48,8 +48,9 @@ namespace rfl {
|
|||
(requires(InputVarType var) { T::from_yaml_obj(var); });
|
||||
|
||||
rfl::Result<InputVarType> get_field(
|
||||
const std::string& _name,
|
||||
const InputObjectType& _obj) const noexcept {
|
||||
const std::string& _name,
|
||||
const InputObjectType& _obj
|
||||
) const noexcept {
|
||||
auto var = InputVarType(_obj.node_[_name]);
|
||||
if (!var.node_) {
|
||||
return rfl::Error("Object contains no field named '" + _name + "'.");
|
||||
|
@ -75,8 +76,8 @@ namespace rfl {
|
|||
} catch (std::exception& e) { return rfl::Error(e.what()); }
|
||||
}
|
||||
|
||||
rfl::Result<InputArrayType> to_array(
|
||||
const InputVarType& _var) const noexcept {
|
||||
rfl::Result<InputArrayType> to_array(const InputVarType& _var
|
||||
) const noexcept {
|
||||
if (!_var.node_.IsSequence()) {
|
||||
return rfl::Error("Could not cast to sequence!");
|
||||
}
|
||||
|
@ -85,8 +86,9 @@ namespace rfl {
|
|||
|
||||
template <class ArrayReader>
|
||||
std::optional<Error> read_array(
|
||||
const ArrayReader& _array_reader,
|
||||
const InputArrayType& _arr) const noexcept {
|
||||
const ArrayReader& _array_reader,
|
||||
const InputArrayType& _arr
|
||||
) const noexcept {
|
||||
for (size_t i = 0; i < _arr.node_.size(); ++i) {
|
||||
const auto err = _array_reader.read(_arr.node_[i]);
|
||||
if (err) { return err; }
|
||||
|
@ -96,8 +98,9 @@ namespace rfl {
|
|||
|
||||
template <class ObjectReader>
|
||||
std::optional<Error> read_object(
|
||||
const ObjectReader& _object_reader,
|
||||
const InputObjectType& _obj) const noexcept {
|
||||
const ObjectReader& _object_reader,
|
||||
const InputObjectType& _obj
|
||||
) const noexcept {
|
||||
for (const auto& p : _obj.node_) {
|
||||
try {
|
||||
const auto k = p.first.as<std::string>();
|
||||
|
@ -107,8 +110,8 @@ namespace rfl {
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
rfl::Result<InputObjectType> to_object(
|
||||
const InputVarType& _var) const noexcept {
|
||||
rfl::Result<InputObjectType> to_object(const InputVarType& _var
|
||||
) const noexcept {
|
||||
if (!_var.node_.IsMap()) {
|
||||
return rfl::Error("Could not cast to map!");
|
||||
}
|
||||
|
@ -116,8 +119,8 @@ namespace rfl {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
rfl::Result<T> use_custom_constructor(
|
||||
const InputVarType _var) const noexcept {
|
||||
rfl::Result<T> use_custom_constructor(const InputVarType _var
|
||||
) const noexcept {
|
||||
try {
|
||||
return T::from_yaml_obj(_var);
|
||||
} catch (std::exception& e) { return rfl::Error(e.what()); }
|
||||
|
|
|
@ -52,28 +52,32 @@ namespace rfl {
|
|||
}
|
||||
|
||||
OutputArrayType add_array_to_array(
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent
|
||||
) const noexcept {
|
||||
return new_array();
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string_view& _name,
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return new_array(_name);
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_array(
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent
|
||||
) const noexcept {
|
||||
return new_object();
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string_view& _name,
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return new_object(_name);
|
||||
}
|
||||
|
||||
|
@ -86,8 +90,9 @@ namespace rfl {
|
|||
template <class T>
|
||||
OutputVarType add_value_to_object(
|
||||
const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const T& _var,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return insert_value(_name, _var);
|
||||
}
|
||||
|
||||
|
@ -97,7 +102,8 @@ namespace rfl {
|
|||
|
||||
OutputVarType add_null_to_object(
|
||||
const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return insert_value(_name, YAML::Null);
|
||||
}
|
||||
|
||||
|
@ -111,8 +117,8 @@ namespace rfl {
|
|||
|
||||
private:
|
||||
template <class T>
|
||||
OutputVarType insert_value(const std::string_view& _name,
|
||||
const T& _var) const noexcept {
|
||||
OutputVarType insert_value(const std::string_view& _name, const T& _var)
|
||||
const noexcept {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value << _var;
|
||||
return OutputVarType {};
|
||||
}
|
||||
|
@ -133,8 +139,8 @@ namespace rfl {
|
|||
return OutputArrayType {};
|
||||
}
|
||||
|
||||
OutputObjectType new_object(
|
||||
const std::string_view& _name) const noexcept {
|
||||
OutputObjectType new_object(const std::string_view& _name
|
||||
) const noexcept {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value << YAML::BeginMap;
|
||||
return OutputObjectType {};
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ namespace rfl {
|
|||
|
||||
/// Parses an object from YAML using reflection.
|
||||
template <class T, class... Ps>
|
||||
Result<internal::wrap_in_rfl_array_t<T>> 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, Ps...>(var);
|
||||
|
@ -34,8 +34,10 @@ namespace rfl {
|
|||
/// Parses an object from a stringstream.
|
||||
template <class T, class... Ps>
|
||||
auto read(std::istream& _stream) {
|
||||
const auto yaml_str = std::string(std::istreambuf_iterator<char>(_stream),
|
||||
std::istreambuf_iterator<char>());
|
||||
const auto yaml_str = std::string(
|
||||
std::istreambuf_iterator<char>(_stream),
|
||||
std::istreambuf_iterator<char>()
|
||||
);
|
||||
return read<T, Ps...>(yaml_str);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,10 @@ namespace rfl {
|
|||
using T = std::remove_cvref_t<decltype(_obj)>;
|
||||
using ParentType = parsing::Parent<Writer>;
|
||||
const auto out = Ref<YAML::Emitter>::make();
|
||||
auto w = Writer(out);
|
||||
Parser<T, Processors<Ps...>>::write(w, _obj,
|
||||
typename ParentType::Root {});
|
||||
auto w = Writer(out);
|
||||
Parser<T, Processors<Ps...>>::write(
|
||||
w, _obj, typename ParentType::Root {}
|
||||
);
|
||||
_stream << out->c_str();
|
||||
return _stream;
|
||||
}
|
||||
|
@ -33,9 +34,10 @@ namespace rfl {
|
|||
using T = std::remove_cvref_t<decltype(_obj)>;
|
||||
using ParentType = parsing::Parent<Writer>;
|
||||
const auto out = Ref<YAML::Emitter>::make();
|
||||
auto w = Writer(out);
|
||||
Parser<T, Processors<Ps...>>::write(w, _obj,
|
||||
typename ParentType::Root {});
|
||||
auto w = Writer(out);
|
||||
Parser<T, Processors<Ps...>>::write(
|
||||
w, _obj, typename ParentType::Root {}
|
||||
);
|
||||
return out->c_str();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue