Commit 2ee15de4 authored by miloyip's avatar miloyip

Add no allocator overloads for Swap

parent fd938658
......@@ -357,6 +357,11 @@ public:
return Create(root, allocator).Swap(value);
}
template <typename stackAllocator>
ValueType& Swap(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& root, ValueType& value) const {
return Create(root).Swap(value);
}
private:
void Parse(const Ch* source, size_t length) {
// Create own allocator if user did not supply.
......@@ -462,6 +467,8 @@ private:
PointerParseErrorCode parseErrorCode_;
};
typedef GenericPointer<Value> Pointer;
//////////////////////////////////////////////////////////////////////////////
template <typename T>
......@@ -717,7 +724,16 @@ typename T::ValueType& SwapValueByPointer(T& root, const CharType(&source)[N], t
return SwapValueByPointer(root, pointer, value, a);
}
typedef GenericPointer<Value> Pointer;
template <typename T>
typename T::ValueType& SwapValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, typename T::ValueType& value) {
return pointer.Swap(root, value);
}
template <typename T, typename CharType, size_t N>
typename T::ValueType& SwapValueByPointer(T& root, const CharType(&source)[N], typename T::ValueType& value) {
const GenericPointer<typename T::ValueType> pointer(source, N - 1);
return SwapValueByPointer(root, pointer, value);
}
RAPIDJSON_NAMESPACE_END
......
......@@ -526,6 +526,14 @@ TEST(Pointer, Swap) {
EXPECT_STREQ("bar", d["foo"][1].GetString());
}
TEST(Pointer, Swap_NoAllocator) {
Document d;
d.Parse(kJson);
Pointer("/foo/0").Swap(d, *Pointer("/foo/1").Get(d));
EXPECT_STREQ("baz", d["foo"][0].GetString());
EXPECT_STREQ("bar", d["foo"][1].GetString());
}
TEST(Pointer, CreateValueByPointer) {
Document d;
Document::AllocatorType& a = d.GetAllocator();
......@@ -958,3 +966,15 @@ TEST(Pointer, SwapValueByPointer) {
EXPECT_STREQ("bar", d["foo"][0].GetString());
EXPECT_STREQ("baz", d["foo"][1].GetString());
}
TEST(Pointer, SwapValueByPointer_NoAllocator) {
Document d;
d.Parse(kJson);
SwapValueByPointer(d, Pointer("/foo/0"), *GetValueByPointer(d, "/foo/1"));
EXPECT_STREQ("baz", d["foo"][0].GetString());
EXPECT_STREQ("bar", d["foo"][1].GetString());
SwapValueByPointer(d, "/foo/0", *GetValueByPointer(d, "/foo/1"));
EXPECT_STREQ("bar", d["foo"][0].GetString());
EXPECT_STREQ("baz", d["foo"][1].GetString());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment