blwegh
This commit is contained in:
parent
f668a2eb4c
commit
50083503cf
224 changed files with 16150 additions and 19488 deletions
|
@ -45,12 +45,10 @@ namespace rfl {
|
|||
|
||||
template <class T>
|
||||
static constexpr bool has_custom_constructor =
|
||||
(requires(InputVarType var) { T::from_yaml_obj(var); });
|
||||
(requires(InputVarType var) { T::from_yaml_obj(var); });
|
||||
|
||||
rfl::Result<InputVarType> get_field(
|
||||
const std::string& _name,
|
||||
const InputObjectType& _obj
|
||||
) const noexcept {
|
||||
rfl::Result<InputVarType> get_field(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 + "'.");
|
||||
|
@ -58,9 +56,7 @@ namespace rfl {
|
|||
return var;
|
||||
}
|
||||
|
||||
bool is_empty(const InputVarType& _var) const noexcept {
|
||||
return !_var.node_ && true;
|
||||
}
|
||||
bool is_empty(const InputVarType& _var) const noexcept { return !_var.node_ && true; }
|
||||
|
||||
template <class T>
|
||||
rfl::Result<T> to_basic_type(const InputVarType& _var) const noexcept {
|
||||
|
@ -76,8 +72,7 @@ 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,10 +80,8 @@ namespace rfl {
|
|||
}
|
||||
|
||||
template <class ArrayReader>
|
||||
std::optional<Error> read_array(
|
||||
const ArrayReader& _array_reader,
|
||||
const InputArrayType& _arr
|
||||
) const noexcept {
|
||||
std::optional<Error> read_array(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) {
|
||||
|
@ -99,10 +92,8 @@ namespace rfl {
|
|||
}
|
||||
|
||||
template <class ObjectReader>
|
||||
std::optional<Error> read_object(
|
||||
const ObjectReader& _object_reader,
|
||||
const InputObjectType& _obj
|
||||
) const noexcept {
|
||||
std::optional<Error>
|
||||
read_object(const ObjectReader& _object_reader, const InputObjectType& _obj) const noexcept {
|
||||
for (const auto& p : _obj.node_) {
|
||||
try {
|
||||
const auto k = p.first.as<std::string>();
|
||||
|
@ -112,8 +103,7 @@ 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!");
|
||||
}
|
||||
|
@ -121,8 +111,7 @@ 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()); }
|
||||
|
|
|
@ -34,64 +34,53 @@ namespace rfl {
|
|||
|
||||
~Writer() = default;
|
||||
|
||||
OutputArrayType array_as_root(const size_t _size) const noexcept {
|
||||
return new_array();
|
||||
}
|
||||
OutputArrayType array_as_root(const size_t _size) const noexcept { return new_array(); }
|
||||
|
||||
OutputObjectType object_as_root(const size_t _size) const noexcept {
|
||||
return new_object();
|
||||
}
|
||||
OutputObjectType object_as_root(const size_t _size) const noexcept { return new_object(); }
|
||||
|
||||
OutputVarType null_as_root() const noexcept {
|
||||
return insert_value(YAML::Null);
|
||||
}
|
||||
OutputVarType null_as_root() const noexcept { return insert_value(YAML::Null); }
|
||||
|
||||
template <class T>
|
||||
OutputVarType value_as_root(const T& _var) const noexcept {
|
||||
return insert_value(_var);
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_array(
|
||||
const size_t _size,
|
||||
OutputArrayType* _parent
|
||||
) const noexcept {
|
||||
OutputArrayType add_array_to_array(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 std::string_view& _name,
|
||||
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 {
|
||||
OutputObjectType add_object_to_array(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 std::string_view& _name,
|
||||
const size_t _size,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return new_object(_name);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_array(const T& _var, OutputArrayType* _parent)
|
||||
const noexcept {
|
||||
OutputVarType add_value_to_array(const T& _var, OutputArrayType* _parent) const noexcept {
|
||||
return insert_value(_var);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(
|
||||
const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent
|
||||
const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
return insert_value(_name, _var);
|
||||
}
|
||||
|
@ -100,25 +89,18 @@ namespace rfl {
|
|||
return insert_value(YAML::Null);
|
||||
}
|
||||
|
||||
OutputVarType add_null_to_object(
|
||||
const std::string_view& _name,
|
||||
OutputObjectType* _parent
|
||||
) const noexcept {
|
||||
OutputVarType add_null_to_object(const std::string_view& _name, OutputObjectType* _parent)
|
||||
const noexcept {
|
||||
return insert_value(_name, YAML::Null);
|
||||
}
|
||||
|
||||
void end_array(OutputArrayType* _arr) const noexcept {
|
||||
(*out_) << YAML::EndSeq;
|
||||
}
|
||||
void end_array(OutputArrayType* _arr) const noexcept { (*out_) << YAML::EndSeq; }
|
||||
|
||||
void end_object(OutputObjectType* _obj) const noexcept {
|
||||
(*out_) << YAML::EndMap;
|
||||
}
|
||||
void end_object(OutputObjectType* _obj) const noexcept { (*out_) << YAML::EndMap; }
|
||||
|
||||
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 {};
|
||||
}
|
||||
|
@ -139,8 +121,7 @@ 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 {};
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@ namespace rfl {
|
|||
|
||||
template <class T, class... Ps>
|
||||
Result<T> load(const std::string& _fname) {
|
||||
const auto read_string = [](const auto& _str) {
|
||||
return read<T, Ps...>(_str);
|
||||
};
|
||||
const auto read_string = [](const auto& _str) { return read<T, Ps...>(_str); };
|
||||
return rfl::io::load_string(_fname).and_then(read_string);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ 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,10 +33,8 @@ 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,7 @@ namespace rfl {
|
|||
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 {}
|
||||
);
|
||||
Parser<T, Processors<Ps...>>::write(w, _obj, typename ParentType::Root {});
|
||||
_stream << out->c_str();
|
||||
return _stream;
|
||||
}
|
||||
|
@ -35,9 +33,7 @@ namespace rfl {
|
|||
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 {}
|
||||
);
|
||||
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