Commit d0146c44 authored by Milo Yip's avatar Milo Yip

Merge pull request #45 from miloyip/Swap

Added GenericValue::Swap()
parents 009c4005 1aa84342
......@@ -368,6 +368,14 @@ public:
return *this;
}
GenericValue& Swap(GenericValue& other) {
char temp[sizeof(GenericValue)];
memcpy(&temp[0], this, sizeof(GenericValue));
memcpy(this, &other, sizeof(GenericValue));
memcpy(&other, temp, sizeof(GenericValue));
return *this;
}
//@}
//!@name Type
......
......@@ -56,6 +56,16 @@ TEST(Value, CopyFrom)
EXPECT_NE(v1[1].GetString(), v2[1].GetString()); // string got copied
}
TEST(Value, Swap) {
Value v1(1234);
Value v2(kObjectType);
EXPECT_EQ(&v1, &v1.Swap(v2));
EXPECT_TRUE(v1.IsObject());
EXPECT_TRUE(v2.IsInt());
EXPECT_EQ(1234, v2.GetInt());
}
TEST(Value, Null) {
// Default constructor
Value x;
......
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