Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
e27f7e71
Commit
e27f7e71
authored
Aug 28, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #119 from miloyip/issue116extramemberapi
Three new APIs are added for JSON object type.
parents
991aeaa0
284dcf3d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
document.h
include/rapidjson/document.h
+18
-2
valuetest.cpp
test/unittest/valuetest.cpp
+13
-0
No files found.
include/rapidjson/document.h
View file @
e27f7e71
...
@@ -534,9 +534,8 @@ public:
...
@@ -534,9 +534,8 @@ public:
break
;
break
;
case
kObjectFlag
:
case
kObjectFlag
:
for
(
MemberIterator
m
=
MemberBegin
();
m
!=
MemberEnd
();
++
m
)
{
for
(
MemberIterator
m
=
MemberBegin
();
m
!=
MemberEnd
();
++
m
)
m
->~
Member
();
m
->~
Member
();
}
Allocator
::
Free
(
data_
.
o
.
members
);
Allocator
::
Free
(
data_
.
o
.
members
);
break
;
break
;
...
@@ -745,6 +744,12 @@ public:
...
@@ -745,6 +744,12 @@ public:
/*! \post IsObject() == true */
/*! \post IsObject() == true */
GenericValue
&
SetObject
()
{
this
->~
GenericValue
();
new
(
this
)
GenericValue
(
kObjectType
);
return
*
this
;
}
GenericValue
&
SetObject
()
{
this
->~
GenericValue
();
new
(
this
)
GenericValue
(
kObjectType
);
return
*
this
;
}
//! Get the number of members in the object.
SizeType
MemberCount
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
size
;
}
//! Check whether the object is empty.
bool
ObjectEmpty
()
const
{
RAPIDJSON_ASSERT
(
IsObject
());
return
data_
.
o
.
size
==
0
;
}
//! Get the value associated with the name.
//! Get the value associated with the name.
/*!
/*!
\note In version 0.1x, if the member is not found, this function returns a null value. This makes issue 7.
\note In version 0.1x, if the member is not found, this function returns a null value. This makes issue 7.
...
@@ -936,6 +941,17 @@ public:
...
@@ -936,6 +941,17 @@ public:
return
AddMember
(
n
,
v
,
allocator
);
return
AddMember
(
n
,
v
,
allocator
);
}
}
//! Remove all members in the object.
/*! This function do not deallocate memory in the object, i.e. the capacity is unchanged.
\note Linear time complexity.
*/
void
RemoveAllMembers
()
{
RAPIDJSON_ASSERT
(
IsObject
());
for
(
MemberIterator
m
=
MemberBegin
();
m
!=
MemberEnd
();
++
m
)
m
->~
Member
();
data_
.
o
.
size
=
0
;
}
//! Remove a member in object by its name.
//! Remove a member in object by its name.
/*! \param name Name of member to be removed.
/*! \param name Name of member to be removed.
\return Whether the member existed.
\return Whether the member existed.
...
...
test/unittest/valuetest.cpp
View file @
e27f7e71
...
@@ -763,14 +763,21 @@ TEST(Value, Object) {
...
@@ -763,14 +763,21 @@ TEST(Value, Object) {
EXPECT_EQ
(
kObjectType
,
x
.
GetType
());
EXPECT_EQ
(
kObjectType
,
x
.
GetType
());
EXPECT_TRUE
(
x
.
IsObject
());
EXPECT_TRUE
(
x
.
IsObject
());
EXPECT_TRUE
(
x
.
ObjectEmpty
());
EXPECT_EQ
(
0u
,
x
.
MemberCount
());
EXPECT_EQ
(
kObjectType
,
y
.
GetType
());
EXPECT_EQ
(
kObjectType
,
y
.
GetType
());
EXPECT_TRUE
(
y
.
IsObject
());
EXPECT_TRUE
(
y
.
IsObject
());
EXPECT_TRUE
(
y
.
ObjectEmpty
());
EXPECT_EQ
(
0u
,
y
.
MemberCount
());
// AddMember()
// AddMember()
x
.
AddMember
(
"A"
,
"Apple"
,
allocator
);
x
.
AddMember
(
"A"
,
"Apple"
,
allocator
);
EXPECT_FALSE
(
x
.
ObjectEmpty
());
EXPECT_EQ
(
1u
,
x
.
MemberCount
());
Value
value
(
"Banana"
,
6
);
Value
value
(
"Banana"
,
6
);
x
.
AddMember
(
"B"
,
"Banana"
,
allocator
);
x
.
AddMember
(
"B"
,
"Banana"
,
allocator
);
EXPECT_EQ
(
2u
,
x
.
MemberCount
());
// AddMember<T>(StringRefType, T, Allocator)
// AddMember<T>(StringRefType, T, Allocator)
{
{
...
@@ -791,6 +798,7 @@ TEST(Value, Object) {
...
@@ -791,6 +798,7 @@ TEST(Value, Object) {
EXPECT_EQ
(
INT64_C
(
-
4294967296
),
o
[
"int64"
].
GetInt64
());
EXPECT_EQ
(
INT64_C
(
-
4294967296
),
o
[
"int64"
].
GetInt64
());
EXPECT_EQ
(
UINT64_C
(
4294967296
),
o
[
"uint64"
].
GetUint64
());
EXPECT_EQ
(
UINT64_C
(
4294967296
),
o
[
"uint64"
].
GetUint64
());
EXPECT_STREQ
(
"Jelly"
,
o
[
"string"
].
GetString
());
EXPECT_STREQ
(
"Jelly"
,
o
[
"string"
].
GetString
());
EXPECT_EQ
(
8u
,
o
.
MemberCount
());
}
}
// Tests a member with null character
// Tests a member with null character
...
@@ -955,6 +963,11 @@ TEST(Value, Object) {
...
@@ -955,6 +963,11 @@ TEST(Value, Object) {
}
}
}
}
// RemoveAllMembers()
x
.
RemoveAllMembers
();
EXPECT_TRUE
(
x
.
ObjectEmpty
());
EXPECT_EQ
(
0u
,
x
.
MemberCount
());
// SetObject()
// SetObject()
Value
z
;
Value
z
;
z
.
SetObject
();
z
.
SetObject
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment