diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index 635601d..d54676e 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -742,6 +742,11 @@ typename T::ValueType& SetValueByPointer(T& root, const GenericPointer +typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, const typename T::ValueType& value, typename T::AllocatorType& a) { + return pointer.Set(root, value, a); +} + template typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, const typename T::Ch* value, typename T::AllocatorType& a) { return pointer.Set(root, value, a); @@ -765,6 +770,11 @@ typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], ty return GenericPointer(source, N - 1).Set(root, value, a); } +template +typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::ValueType& value, typename T::AllocatorType& a) { + return GenericPointer(source, N - 1).Set(root, value, a); +} + template typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::Ch* value, typename T::AllocatorType& a) { return GenericPointer(source, N - 1).Set(root, value, a); @@ -790,6 +800,11 @@ typename T::ValueType& SetValueByPointer(T& root, const GenericPointer +typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, const typename T::ValueType& value) { + return pointer.Set(root, value); +} + template typename T::ValueType& SetValueByPointer(T& root, const GenericPointer& pointer, const typename T::Ch* value) { return pointer.Set(root, value); @@ -813,6 +828,11 @@ typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], ty return GenericPointer(source, N - 1).Set(root, value); } +template +typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::ValueType& value) { + return GenericPointer(source, N - 1).Set(root, value); +} + template typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::Ch* value) { return GenericPointer(source, N - 1).Set(root, value); diff --git a/test/unittest/pointertest.cpp b/test/unittest/pointertest.cpp index cc067e7..004fa22 100644 --- a/test/unittest/pointertest.cpp +++ b/test/unittest/pointertest.cpp @@ -693,6 +693,11 @@ TEST(Pointer, Set) { Pointer("/foo/null").Set(d, Value().Move(), a); EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull()); + // Const Value version + const Value foo(d["foo"], a); + Pointer("/clone").Set(d, foo, a); + EXPECT_EQ(foo, *GetValueByPointer(d, "/clone")); + // Generic version Pointer("/foo/int").Set(d, -1, a); EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt()); @@ -747,6 +752,11 @@ TEST(Pointer, Set_NoAllocator) { Pointer("/foo/null").Set(d, Value().Move()); EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull()); + // Const Value version + const Value foo(d["foo"], d.GetAllocator()); + Pointer("/clone").Set(d, foo); + EXPECT_EQ(foo, *GetValueByPointer(d, "/clone")); + // Generic version Pointer("/foo/int").Set(d, -1); EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt()); @@ -1066,6 +1076,11 @@ TEST(Pointer, SetValueByPointer_Pointer) { SetValueByPointer(d, Pointer("/foo/null"), Value().Move(), a); EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull()); + // Const Value version + const Value foo(d["foo"], d.GetAllocator()); + SetValueByPointer(d, Pointer("/clone"), foo, a); + EXPECT_EQ(foo, *GetValueByPointer(d, "/clone")); + // Generic version SetValueByPointer(d, Pointer("/foo/int"), -1, a); EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt()); @@ -1118,6 +1133,11 @@ TEST(Pointer, SetValueByPointer_String) { SetValueByPointer(d, "/foo/null", Value().Move(), a); EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull()); + // Const Value version + const Value foo(d["foo"], d.GetAllocator()); + SetValueByPointer(d, "/clone", foo, a); + EXPECT_EQ(foo, *GetValueByPointer(d, "/clone")); + // Generic version SetValueByPointer(d, "/foo/int", -1, a); EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt()); @@ -1169,6 +1189,11 @@ TEST(Pointer, SetValueByPointer_Pointer_NoAllocator) { SetValueByPointer(d, Pointer("/foo/null"), Value().Move()); EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull()); + // Const Value version + const Value foo(d["foo"], d.GetAllocator()); + SetValueByPointer(d, Pointer("/clone"), foo); + EXPECT_EQ(foo, *GetValueByPointer(d, "/clone")); + // Generic version SetValueByPointer(d, Pointer("/foo/int"), -1); EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt()); @@ -1220,6 +1245,11 @@ TEST(Pointer, SetValueByPointer_String_NoAllocator) { SetValueByPointer(d, "/foo/null", Value().Move()); EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull()); + // Const Value version + const Value foo(d["foo"], d.GetAllocator()); + SetValueByPointer(d, "/clone", foo); + EXPECT_EQ(foo, *GetValueByPointer(d, "/clone")); + // Generic version SetValueByPointer(d, "/foo/int", -1); EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt());