From ce6f9646c4470d359b62d9501c77dd941323db82 Mon Sep 17 00:00:00 2001 From: LuChiChick <1084116302@qq.com> Date: Tue, 21 Apr 2026 20:54:07 +0800 Subject: [PATCH] Added shallow copy constructors for Json_Array and Json_Object && Added a float type constructor for Json_Value && Fixed the incorrect indentation issue when pretty-printing an empty Json_Array. --- Inc/Json_Utilities.hpp | 5 +++++ Src/Json_Utilities.cpp | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Inc/Json_Utilities.hpp b/Inc/Json_Utilities.hpp index b6a4b6a..2bf383e 100644 --- a/Inc/Json_Utilities.hpp +++ b/Inc/Json_Utilities.hpp @@ -54,6 +54,8 @@ public: // 列表构造 Json_Arry(std::initializer_list init_list) : private_element_list(init_list) {}; Json_Arry(std::vector init_list) : private_element_list(init_list) {}; + // 浅拷贝构造 + Json_Arry(const Json_Arry &temp); // 深拷贝 Json_Arry &operator=(const Json_Arry &another); @@ -101,6 +103,7 @@ public: Json_Value(int64_t num_integer); Json_Value(int num_integer) : Json_Value((int64_t)num_integer) {}; Json_Value(double num_float); + Json_Value(float num_float) : Json_Value((double)num_float) {}; Json_Value(bool boolean); // 浅拷贝构造 Json_Value(const Json_Value &temp); @@ -165,6 +168,8 @@ public: // 列表构造 Json_Object(std::initializer_list init_list) : private_element_list(init_list) {}; Json_Object(std::vector init_list) : private_element_list(init_list) {}; + // 浅拷贝构造 + Json_Object(const Json_Object &temp); // 深拷贝 Json_Object &operator=(const Json_Object &another); diff --git a/Src/Json_Utilities.cpp b/Src/Json_Utilities.cpp index 508e581..0fc8c1e 100644 --- a/Src/Json_Utilities.cpp +++ b/Src/Json_Utilities.cpp @@ -786,7 +786,7 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_ fprintf(pFile, "\r\n"); } // 尾部缩进 - if (enable_pretty_print && (!value.isNull())) + if (enable_pretty_print && (!arry.isNull())) for (size_t count = 0; count < depth; count++) fprintf(pFile, " "); @@ -1041,6 +1041,13 @@ bool Json_Pair::isNull() const // ================================================================================================= +// 浅拷贝构造 +Json_Arry::Json_Arry(const Json_Arry &temp) +{ + // 执行深拷贝 + *this = temp; +} + // 深拷贝 Json_Arry &Json_Arry::operator=(const Json_Arry &another) { @@ -1075,6 +1082,13 @@ bool Json_Arry::isNull(void) const // ================================================================================================= +// 浅拷贝构造 +Json_Object::Json_Object(const Json_Object &temp) +{ + // 执行深拷贝 + *this = temp; +} + // 深拷贝 Json_Object &Json_Object::operator=(const Json_Object &another) {