mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 02:36:18 +08:00
Use std::string_view for the field names during the write process
This commit is contained in:
@@ -103,7 +103,7 @@ struct Writer {
|
||||
/// Adds an empty array to an existing object. The key or name of the field is
|
||||
/// signified by `_name`. Returns the new array for further modification.
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept;
|
||||
|
||||
/// Adds an empty object to an existing array. Returns the new
|
||||
@@ -114,7 +114,7 @@ struct Writer {
|
||||
/// Adds an empty object to an existing object. The key or name of the field
|
||||
/// is signified by `_name`. Returns the new object for further modification.
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept;
|
||||
|
||||
/// Adds a basic value (bool, numeric, string) to an array. Returns an
|
||||
@@ -127,7 +127,7 @@ struct Writer {
|
||||
/// or name of the field is signified by `name`. Returns an
|
||||
/// OutputVarType containing the new value.
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(const std::string& _name, const T& _var,
|
||||
OutputVarType add_value_to_object(const std::string_view& _name, const T& _var,
|
||||
OutputObjectType* _parent) const noexcept;
|
||||
|
||||
/// Adds a null value to an array. Returns an
|
||||
@@ -137,7 +137,7 @@ struct Writer {
|
||||
/// Adds a null value to an existing object. The key
|
||||
/// or name of the field is signified by `name`. Returns an
|
||||
/// OutputVarType containing the null value.
|
||||
OutputVarType add_null_to_object(const std::string& _name,
|
||||
OutputVarType add_null_to_object(const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept;
|
||||
|
||||
/// Signifies to the writer that we do not want to add any further elements to
|
||||
|
||||
+12
-11
@@ -93,10 +93,10 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
bson_array_builder_t* val;
|
||||
bson_append_array_builder_begin(_parent->val_, _name.c_str(),
|
||||
bson_append_array_builder_begin(_parent->val_, _name.data(),
|
||||
static_cast<int>(_name.size()), &val);
|
||||
return OutputArrayType(val, IsObject{_parent->val_});
|
||||
}
|
||||
@@ -110,10 +110,10 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
subdocs_->emplace_back(rfl::Box<BSONType>());
|
||||
bson_append_document_begin(_parent->val_, _name.c_str(),
|
||||
bson_append_document_begin(_parent->val_, _name.data(),
|
||||
static_cast<int>(_name.size()),
|
||||
&(subdocs_->back()->val_));
|
||||
return OutputObjectType(&subdocs_->back()->val_, IsObject{_parent->val_});
|
||||
@@ -140,21 +140,22 @@ class Writer {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(const std::string& _name, const T& _var,
|
||||
OutputVarType add_value_to_object(const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
||||
bson_append_utf8(_parent->val_, _name.c_str(),
|
||||
bson_append_utf8(_parent->val_, _name.data(),
|
||||
static_cast<int>(_name.size()), _var.c_str(),
|
||||
static_cast<int>(_var.size()));
|
||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||
bson_append_bool(_parent->val_, _name.c_str(),
|
||||
bson_append_bool(_parent->val_, _name.data(),
|
||||
static_cast<int>(_name.size()), _var);
|
||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
||||
bson_append_double(_parent->val_, _name.c_str(),
|
||||
bson_append_double(_parent->val_, _name.data(),
|
||||
static_cast<int>(_name.size()),
|
||||
static_cast<double>(_var));
|
||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||
bson_append_int64(_parent->val_, _name.c_str(),
|
||||
bson_append_int64(_parent->val_, _name.data(),
|
||||
static_cast<int>(_name.size()),
|
||||
static_cast<std::int64_t>(_var));
|
||||
} else {
|
||||
@@ -168,9 +169,9 @@ class Writer {
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
OutputVarType add_null_to_object(const std::string& _name,
|
||||
OutputVarType add_null_to_object(const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
bson_append_null(_parent->val_, _name.c_str(),
|
||||
bson_append_null(_parent->val_, _name.data(),
|
||||
static_cast<int>(_name.size()));
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
cbor_encode_text_string(_parent->encoder_, _name.c_str(), _name.size());
|
||||
cbor_encode_text_string(_parent->encoder_, _name.data(), _name.size());
|
||||
return new_array(_size, _parent->encoder_);
|
||||
}
|
||||
|
||||
@@ -79,9 +79,9 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
cbor_encode_text_string(_parent->encoder_, _name.c_str(), _name.size());
|
||||
cbor_encode_text_string(_parent->encoder_, _name.data(), _name.size());
|
||||
return new_object(_size, _parent->encoder_);
|
||||
}
|
||||
|
||||
@@ -92,9 +92,10 @@ class Writer {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(const std::string& _name, const T& _var,
|
||||
OutputVarType add_value_to_object(const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
cbor_encode_text_string(_parent->encoder_, _name.c_str(), _name.size());
|
||||
cbor_encode_text_string(_parent->encoder_, _name.data(), _name.size());
|
||||
return new_value(_var, _parent->encoder_);
|
||||
}
|
||||
|
||||
@@ -103,9 +104,9 @@ class Writer {
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
OutputVarType add_null_to_object(const std::string& _name,
|
||||
OutputVarType add_null_to_object(const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
cbor_encode_text_string(_parent->encoder_, _name.c_str(), _name.size());
|
||||
cbor_encode_text_string(_parent->encoder_, _name.data(), _name.size());
|
||||
cbor_encode_null(_parent->encoder_);
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ struct Writer {
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return new_array(_name);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ struct Writer {
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return new_object(_name);
|
||||
}
|
||||
@@ -87,7 +87,8 @@ struct Writer {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(const std::string& _name, const T& _var,
|
||||
OutputVarType add_value_to_object(const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return insert_value(_name, _var);
|
||||
}
|
||||
@@ -97,9 +98,9 @@ struct Writer {
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
OutputVarType add_null_to_object(const std::string& _name,
|
||||
OutputVarType add_null_to_object(const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
fbb_->Null(_name.c_str());
|
||||
fbb_->Null(_name.data());
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
@@ -113,16 +114,16 @@ struct Writer {
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
OutputVarType insert_value(const std::string& _name,
|
||||
OutputVarType insert_value(const std::string_view& _name,
|
||||
const T& _var) const noexcept {
|
||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
||||
fbb_->String(_name.c_str(), _var);
|
||||
fbb_->String(_name.data(), _var);
|
||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||
fbb_->Bool(_name.c_str(), _var);
|
||||
fbb_->Bool(_name.data(), _var);
|
||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
||||
fbb_->Double(_name.c_str(), _var);
|
||||
fbb_->Double(_name.data(), _var);
|
||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||
fbb_->Int(_name.c_str(), _var);
|
||||
fbb_->Int(_name.data(), _var);
|
||||
} else {
|
||||
static_assert(always_false_v<T>, "Unsupported type");
|
||||
}
|
||||
@@ -145,8 +146,8 @@ struct Writer {
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
OutputArrayType new_array(const std::string& _name) const noexcept {
|
||||
const auto start = fbb_->StartVector(_name.c_str());
|
||||
OutputArrayType new_array(const std::string_view& _name) const noexcept {
|
||||
const auto start = fbb_->StartVector(_name.data());
|
||||
return OutputArrayType{start};
|
||||
}
|
||||
|
||||
@@ -155,8 +156,8 @@ struct Writer {
|
||||
return OutputArrayType{start};
|
||||
}
|
||||
|
||||
OutputObjectType new_object(const std::string& _name) const noexcept {
|
||||
const auto start = fbb_->StartMap(_name.c_str());
|
||||
OutputObjectType new_object(const std::string_view& _name) const noexcept {
|
||||
const auto start = fbb_->StartMap(_name.data());
|
||||
return OutputObjectType{start};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace internal {
|
||||
/// for the parameters names in the NamedTuples.
|
||||
template <size_t N>
|
||||
struct StringLiteral {
|
||||
constexpr StringLiteral(const auto... _chars) : arr_{_chars...} {}
|
||||
constexpr StringLiteral(const auto... _chars) : arr_{_chars..., '\0'} {}
|
||||
|
||||
constexpr StringLiteral(const char (&_str)[N]) {
|
||||
std::copy_n(_str, N - 1, std::data(arr_));
|
||||
std::copy_n(_str, N, std::data(arr_));
|
||||
}
|
||||
|
||||
/// Returns the value as a string.
|
||||
@@ -28,7 +28,7 @@ struct StringLiteral {
|
||||
return std::string_view(std::data(arr_), N - 1);
|
||||
}
|
||||
|
||||
std::array<char, N - 1> arr_{};
|
||||
std::array<char, N> arr_{};
|
||||
};
|
||||
|
||||
template <size_t N1, size_t N2>
|
||||
|
||||
@@ -81,10 +81,10 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const auto arr = yyjson_mut_arr(doc_);
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.c_str()),
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.data()),
|
||||
arr);
|
||||
return OutputArrayType(arr);
|
||||
}
|
||||
@@ -97,10 +97,10 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const auto obj = yyjson_mut_obj(doc_);
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.c_str()),
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.data()),
|
||||
obj);
|
||||
return OutputObjectType(obj);
|
||||
}
|
||||
@@ -114,10 +114,11 @@ class Writer {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(const std::string& _name, const T& _var,
|
||||
OutputVarType add_value_to_object(const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const auto val = from_basic_type(_var);
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.c_str()),
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.data()),
|
||||
val.val_);
|
||||
return OutputVarType(val);
|
||||
}
|
||||
@@ -128,10 +129,10 @@ class Writer {
|
||||
return OutputVarType(null);
|
||||
}
|
||||
|
||||
OutputVarType add_null_to_object(const std::string& _name,
|
||||
OutputVarType add_null_to_object(const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
const auto null = yyjson_mut_null(doc_);
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.c_str()),
|
||||
yyjson_mut_obj_add(_parent->val_, yyjson_mut_strcpy(doc_, _name.data()),
|
||||
null);
|
||||
return OutputVarType(null);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#define RFL_PARSING_ISWRITER_HPP_
|
||||
|
||||
#include <concepts>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "../Result.hpp"
|
||||
|
||||
@@ -9,7 +11,8 @@ namespace rfl {
|
||||
namespace parsing {
|
||||
|
||||
template <class W, class T>
|
||||
concept IsWriter = requires(W w, T t, std::string name, std::string basic_value,
|
||||
concept IsWriter = requires(W w, T t, std::string_view name,
|
||||
std::string basic_value,
|
||||
typename W::OutputArrayType arr,
|
||||
typename W::OutputObjectType obj,
|
||||
typename W::OutputVarType var, size_t size) {
|
||||
|
||||
@@ -46,21 +46,21 @@ struct MapParser {
|
||||
|
||||
if constexpr (std::is_integral_v<ReflT> ||
|
||||
std::is_floating_point_v<ReflT>) {
|
||||
const auto new_parent =
|
||||
typename ParentType::Object{std::to_string(k.reflection()), &obj};
|
||||
const auto name = std::to_string(k.reflection());
|
||||
const auto new_parent = typename ParentType::Object{name, &obj};
|
||||
Parser<R, W, std::remove_cvref_t<ValueType>>::write(_w, v,
|
||||
new_parent);
|
||||
} else {
|
||||
const auto new_parent =
|
||||
typename ParentType::Object{k.reflection(), &obj};
|
||||
const auto name = k.reflection();
|
||||
const auto new_parent = typename ParentType::Object{name, &obj};
|
||||
Parser<R, W, std::remove_cvref_t<ValueType>>::write(_w, v,
|
||||
new_parent);
|
||||
}
|
||||
|
||||
} else if constexpr (std::is_integral_v<KeyType> ||
|
||||
std::is_floating_point_v<KeyType>) {
|
||||
const auto new_parent =
|
||||
typename ParentType::Object{std::to_string(k), &obj};
|
||||
const auto name = std::to_string(k);
|
||||
const auto new_parent = typename ParentType::Object{name, &obj};
|
||||
Parser<R, W, std::remove_cvref_t<ValueType>>::write(_w, v, new_parent);
|
||||
} else {
|
||||
const auto new_parent = typename ParentType::Object{k, &obj};
|
||||
|
||||
@@ -187,7 +187,7 @@ struct NamedTupleParser {
|
||||
typename std::tuple_element<_i, std::tuple<FieldTypes...>>::type;
|
||||
using ValueType = std::remove_cvref_t<typename FieldType::Type>;
|
||||
const auto& value = rfl::get<_i>(_tup);
|
||||
const auto name = FieldType::name_.str();
|
||||
constexpr auto name = FieldType::name_.string_view();
|
||||
const auto new_parent = typename ParentType::Object{name, _ptr};
|
||||
if constexpr (!_all_required &&
|
||||
!is_required<ValueType, _ignore_empty_containers>()) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define RFL_PARSING_PARENT_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
|
||||
#include "../always_false.hpp"
|
||||
@@ -21,7 +22,7 @@ struct Parent {
|
||||
};
|
||||
|
||||
struct Object {
|
||||
std::string name_;
|
||||
std::string_view name_;
|
||||
OutputObjectType* obj_;
|
||||
bool is_attribute_ = false;
|
||||
Object as_attribute() const { return Object{name_, obj_, true}; }
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <concepts>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "../Result.hpp"
|
||||
|
||||
@@ -11,7 +12,7 @@ namespace parsing {
|
||||
|
||||
/// Determines whether a writer supports attributes.
|
||||
template <class W>
|
||||
concept supports_attributes = requires(W w, std::string name,
|
||||
concept supports_attributes = requires(W w, std::string_view name,
|
||||
typename W::OutputObjectType obj,
|
||||
bool is_attribute) {
|
||||
{
|
||||
|
||||
+16
-15
@@ -22,9 +22,10 @@ struct Writer {
|
||||
static constexpr const char* XML_CONTENT = "xml_content";
|
||||
|
||||
struct XMLOutputArray {
|
||||
XMLOutputArray(const std::string& _name, const Ref<pugi::xml_node>& _node)
|
||||
XMLOutputArray(const std::string_view& _name,
|
||||
const Ref<pugi::xml_node>& _node)
|
||||
: name_(_name), node_(_node) {}
|
||||
std::string name_;
|
||||
std::string_view name_;
|
||||
Ref<pugi::xml_node> node_;
|
||||
};
|
||||
|
||||
@@ -80,7 +81,7 @@ struct Writer {
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return OutputArrayType(_name, _parent->node_);
|
||||
}
|
||||
@@ -88,15 +89,15 @@ struct Writer {
|
||||
OutputObjectType add_object_to_array(
|
||||
const size_t _size, OutputArrayType* _parent) const noexcept {
|
||||
auto node_child = Ref<pugi::xml_node>::make(
|
||||
_parent->node_->append_child(_parent->name_.c_str()));
|
||||
_parent->node_->append_child(_parent->name_.data()));
|
||||
return OutputObjectType(node_child);
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
auto node_child =
|
||||
Ref<pugi::xml_node>::make(_parent->node_->append_child(_name.c_str()));
|
||||
Ref<pugi::xml_node>::make(_parent->node_->append_child(_name.data()));
|
||||
return OutputObjectType(node_child);
|
||||
}
|
||||
|
||||
@@ -105,25 +106,25 @@ struct Writer {
|
||||
OutputArrayType* _parent) const noexcept {
|
||||
const auto str = to_string(_var);
|
||||
auto node_child = Ref<pugi::xml_node>::make(
|
||||
_parent->node_->append_child(_parent->name_.c_str()));
|
||||
_parent->node_->append_child(_parent->name_.data()));
|
||||
node_child->append_child(pugi::node_pcdata).set_value(str.c_str());
|
||||
return OutputVarType(node_child);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(
|
||||
const std::string& _name, const T& _var, OutputObjectType* _parent,
|
||||
const std::string_view& _name, const T& _var, OutputObjectType* _parent,
|
||||
const bool _is_attribute = false) const noexcept {
|
||||
const auto str = to_string(_var);
|
||||
if (_is_attribute) {
|
||||
_parent->node_->append_attribute(_name.c_str()) = str.c_str();
|
||||
_parent->node_->append_attribute(_name.data()) = str.c_str();
|
||||
return OutputVarType(_parent->node_);
|
||||
} else if (_name == XML_CONTENT) {
|
||||
_parent->node_->append_child(pugi::node_pcdata).set_value(str.c_str());
|
||||
return OutputVarType(_parent->node_);
|
||||
} else {
|
||||
auto node_child = Ref<pugi::xml_node>::make(
|
||||
_parent->node_->append_child(_name.c_str()));
|
||||
auto node_child =
|
||||
Ref<pugi::xml_node>::make(_parent->node_->append_child(_name.data()));
|
||||
node_child->append_child(pugi::node_pcdata).set_value(str.c_str());
|
||||
return OutputVarType(node_child);
|
||||
}
|
||||
@@ -131,20 +132,20 @@ struct Writer {
|
||||
|
||||
OutputVarType add_null_to_array(OutputArrayType* _parent) const noexcept {
|
||||
auto node_child = Ref<pugi::xml_node>::make(
|
||||
_parent->node_->append_child(_parent->name_.c_str()));
|
||||
_parent->node_->append_child(_parent->name_.data()));
|
||||
return OutputVarType(node_child);
|
||||
}
|
||||
|
||||
OutputVarType add_null_to_object(
|
||||
const std::string& _name, OutputObjectType* _parent,
|
||||
const std::string_view& _name, OutputObjectType* _parent,
|
||||
const bool _is_attribute = false) const noexcept {
|
||||
if (_is_attribute) {
|
||||
return OutputVarType(_parent->node_);
|
||||
} else if (_name == XML_CONTENT) {
|
||||
return OutputVarType(_parent->node_);
|
||||
} else {
|
||||
auto node_child = Ref<pugi::xml_node>::make(
|
||||
_parent->node_->append_child(_name.c_str()));
|
||||
auto node_child =
|
||||
Ref<pugi::xml_node>::make(_parent->node_->append_child(_name.data()));
|
||||
return OutputVarType(node_child);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-10
@@ -58,7 +58,7 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputArrayType add_array_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return new_array(_name);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class Writer {
|
||||
}
|
||||
|
||||
OutputObjectType add_object_to_object(
|
||||
const std::string& _name, const size_t _size,
|
||||
const std::string_view& _name, const size_t _size,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return new_object(_name);
|
||||
}
|
||||
@@ -81,7 +81,8 @@ class Writer {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
OutputVarType add_value_to_object(const std::string& _name, const T& _var,
|
||||
OutputVarType add_value_to_object(const std::string_view& _name,
|
||||
const T& _var,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return insert_value(_name, _var);
|
||||
}
|
||||
@@ -90,7 +91,7 @@ class Writer {
|
||||
return insert_value(YAML::Null);
|
||||
}
|
||||
|
||||
OutputVarType add_null_to_object(const std::string& _name,
|
||||
OutputVarType add_null_to_object(const std::string_view& _name,
|
||||
OutputObjectType* _parent) const noexcept {
|
||||
return insert_value(_name, YAML::Null);
|
||||
}
|
||||
@@ -105,9 +106,9 @@ class Writer {
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
OutputVarType insert_value(const std::string& _name,
|
||||
OutputVarType insert_value(const std::string_view& _name,
|
||||
const T& _var) const noexcept {
|
||||
(*out_) << YAML::Key << _name << YAML::Value << _var;
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value << _var;
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
@@ -117,8 +118,8 @@ class Writer {
|
||||
return OutputVarType{};
|
||||
}
|
||||
|
||||
OutputArrayType new_array(const std::string& _name) const noexcept {
|
||||
(*out_) << YAML::Key << _name << YAML::Value << YAML::BeginSeq;
|
||||
OutputArrayType new_array(const std::string_view& _name) const noexcept {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value << YAML::BeginSeq;
|
||||
return OutputArrayType{};
|
||||
}
|
||||
|
||||
@@ -127,8 +128,8 @@ class Writer {
|
||||
return OutputArrayType{};
|
||||
}
|
||||
|
||||
OutputObjectType new_object(const std::string& _name) const noexcept {
|
||||
(*out_) << YAML::Key << _name << YAML::Value << YAML::BeginMap;
|
||||
OutputObjectType new_object(const std::string_view& _name) const noexcept {
|
||||
(*out_) << YAML::Key << _name.data() << YAML::Value << YAML::BeginMap;
|
||||
return OutputObjectType{};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user