mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-04 19:13:40 +01:00
Merge pull request #1821 from slsyy/master
Add implicit conversion from Object and Array to Value (#1404)
This commit is contained in:
commit
585042c02b
@ -2612,6 +2612,7 @@ public:
|
||||
GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; }
|
||||
~GenericArray() {}
|
||||
|
||||
operator ValueType&() const { return value_; }
|
||||
SizeType Size() const { return value_.Size(); }
|
||||
SizeType Capacity() const { return value_.Capacity(); }
|
||||
bool Empty() const { return value_.Empty(); }
|
||||
@ -2667,6 +2668,7 @@ public:
|
||||
GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; }
|
||||
~GenericObject() {}
|
||||
|
||||
operator ValueType&() const { return value_; }
|
||||
SizeType MemberCount() const { return value_.MemberCount(); }
|
||||
SizeType MemberCapacity() const { return value_.MemberCapacity(); }
|
||||
bool ObjectEmpty() const { return value_.ObjectEmpty(); }
|
||||
|
@ -1529,6 +1529,38 @@ TEST(Pointer, Ambiguity) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Pointer, ResolveOnObject) {
|
||||
Document d;
|
||||
EXPECT_FALSE(d.Parse("{\"a\": 123}").HasParseError());
|
||||
|
||||
{
|
||||
Value::ConstObject o = static_cast<const Document&>(d).GetObject();
|
||||
EXPECT_EQ(123, Pointer("/a").Get(o)->GetInt());
|
||||
}
|
||||
|
||||
{
|
||||
Value::Object o = d.GetObject();
|
||||
Pointer("/a").Set(o, 456, d.GetAllocator());
|
||||
EXPECT_EQ(456, Pointer("/a").Get(o)->GetInt());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Pointer, ResolveOnArray) {
|
||||
Document d;
|
||||
EXPECT_FALSE(d.Parse("[1, 2, 3]").HasParseError());
|
||||
|
||||
{
|
||||
Value::ConstArray a = static_cast<const Document&>(d).GetArray();
|
||||
EXPECT_EQ(2, Pointer("/1").Get(a)->GetInt());
|
||||
}
|
||||
|
||||
{
|
||||
Value::Array a = d.GetArray();
|
||||
Pointer("/1").Set(a, 123, d.GetAllocator());
|
||||
EXPECT_EQ(123, Pointer("/1").Get(a)->GetInt());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Pointer, LessThan) {
|
||||
static const struct {
|
||||
const char *str;
|
||||
|
Loading…
x
Reference in New Issue
Block a user