Use exceptions inside the writers (#535)

Adds error handling using exceptions in the write processes.
This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-10-27 23:38:20 +01:00
committed by GitHub
parent 3ae683387e
commit 2b1cd83677
31 changed files with 867 additions and 673 deletions
+25 -25
View File
@@ -36,57 +36,57 @@ struct RFL_API Writer {
~Writer();
OutputArrayType array_as_root(const size_t _size) const noexcept;
OutputArrayType array_as_root(const size_t _size) const;
OutputObjectType object_as_root(const size_t _size) const noexcept;
OutputObjectType object_as_root(const size_t _size) const;
OutputVarType null_as_root() const noexcept;
OutputVarType null_as_root() const;
template <class T>
OutputVarType value_as_root(const T& _var) const noexcept {
OutputVarType value_as_root(const T& _var) const {
return insert_value(_var);
}
OutputArrayType add_array_to_array(const size_t _size,
OutputArrayType* _parent) const noexcept;
OutputArrayType* _parent) const;
OutputArrayType add_array_to_object(const std::string_view& _name,
const size_t _size,
OutputObjectType* _parent) const noexcept;
OutputObjectType* _parent) const;
OutputObjectType add_object_to_array(const size_t _size,
OutputArrayType* _parent) const noexcept;
OutputArrayType* _parent) const;
OutputObjectType add_object_to_object(
const std::string_view& _name, const size_t _size,
OutputObjectType* _parent) const noexcept;
OutputObjectType add_object_to_object(const std::string_view& _name,
const size_t _size,
OutputObjectType* _parent) const;
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 {
return insert_value(_var);
}
template <class T>
OutputVarType add_value_to_object(
const std::string_view& _name, const T& _var,
OutputObjectType* /*_parent*/) const noexcept {
OutputVarType add_value_to_object(const std::string_view& _name,
const T& _var,
OutputObjectType* /*_parent*/) const {
return insert_value(_name, _var);
}
OutputVarType add_null_to_array(OutputArrayType* _parent) const noexcept;
OutputVarType add_null_to_array(OutputArrayType* _parent) const;
OutputVarType add_null_to_object(const std::string_view& _name,
OutputObjectType* _parent) const noexcept;
OutputObjectType* _parent) const;
void end_array(OutputArrayType* _arr) const noexcept;
void end_array(OutputArrayType* _arr) const;
void end_object(OutputObjectType* _obj) const noexcept;
void end_object(OutputObjectType* _obj) const;
private:
template <class T>
OutputVarType insert_value(const std::string_view& _name,
const T& _var) const noexcept {
const T& _var) const {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
fbb_->String(_name.data(), _var);
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
@@ -107,7 +107,7 @@ struct RFL_API Writer {
}
template <class T>
OutputVarType insert_value(const T& _var) const noexcept {
OutputVarType insert_value(const T& _var) const {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
fbb_->String(_var);
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
@@ -125,13 +125,13 @@ struct RFL_API Writer {
return OutputVarType{};
}
OutputArrayType new_array(const std::string_view& _name) const noexcept;
OutputArrayType new_array(const std::string_view& _name) const;
OutputArrayType new_array() const noexcept;
OutputArrayType new_array() const;
OutputObjectType new_object(const std::string_view& _name) const noexcept;
OutputObjectType new_object(const std::string_view& _name) const;
OutputObjectType new_object() const noexcept;
OutputObjectType new_object() const;
private:
Ref<flexbuffers::Builder> fbb_;