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
9279e9ec
Commit
9279e9ec
authored
Mar 13, 2015
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #257 from pah/fixes/254-addmember
GenericValue::AddMember<T>: add missing overload (closes #254)
parents
c745c953
06c3ddba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
2 deletions
+52
-2
document.h
include/rapidjson/document.h
+39
-2
valuetest.cpp
test/unittest/valuetest.cpp
+13
-0
No files found.
include/rapidjson/document.h
View file @
9279e9ec
...
...
@@ -954,6 +954,44 @@ public:
return
*
this
;
}
//! Add a constant string value as member (name-value pair) to the object.
/*! \param name A string value as name of member.
\param value constant string reference as value of member.
\param allocator Allocator for reallocating memory. It must be the same one as used before. Commonly use GenericDocument::GetAllocator().
\return The value itself for fluent API.
\pre IsObject()
\note This overload is needed to avoid clashes with the generic primitive type AddMember(GenericValue&,T,Allocator&) overload below.
\note Amortized Constant time complexity.
*/
GenericValue
&
AddMember
(
GenericValue
&
name
,
StringRefType
value
,
Allocator
&
allocator
)
{
GenericValue
v
(
value
);
return
AddMember
(
name
,
v
,
allocator
);
}
//! Add any primitive value as member (name-value pair) to the object.
/*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t
\param name A string value as name of member.
\param value Value of primitive type \c T as value of member
\param allocator Allocator for reallocating memory. Commonly use GenericDocument::GetAllocator().
\return The value itself for fluent API.
\pre IsObject()
\note The source type \c T explicitly disallows all pointer types,
especially (\c const) \ref Ch*. This helps avoiding implicitly
referencing character strings with insufficient lifetime, use
\ref AddMember(StringRefType, GenericValue&, Allocator&) or \ref
AddMember(StringRefType, StringRefType, Allocator&).
All other pointer types would implicitly convert to \c bool,
use an explicit cast instead, if needed.
\note Amortized Constant time complexity.
*/
template
<
typename
T
>
RAPIDJSON_DISABLEIF_RETURN
((
internal
::
OrExpr
<
internal
::
IsPointer
<
T
>
,
internal
::
IsGenericValue
<
T
>
>
),
(
GenericValue
&
))
AddMember
(
GenericValue
&
name
,
T
value
,
Allocator
&
allocator
)
{
GenericValue
v
(
value
);
return
AddMember
(
name
,
v
,
allocator
);
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
GenericValue
&
AddMember
(
GenericValue
&&
name
,
GenericValue
&&
value
,
Allocator
&
allocator
)
{
return
AddMember
(
name
,
value
,
allocator
);
...
...
@@ -1021,8 +1059,7 @@ public:
RAPIDJSON_DISABLEIF_RETURN
((
internal
::
OrExpr
<
internal
::
IsPointer
<
T
>
,
internal
::
IsGenericValue
<
T
>
>
),
(
GenericValue
&
))
AddMember
(
StringRefType
name
,
T
value
,
Allocator
&
allocator
)
{
GenericValue
n
(
name
);
GenericValue
v
(
value
);
return
AddMember
(
n
,
v
,
allocator
);
return
AddMember
(
n
,
value
,
allocator
);
}
//! Remove all members in the object.
...
...
test/unittest/valuetest.cpp
View file @
9279e9ec
...
...
@@ -919,6 +919,19 @@ TEST(Value, Object) {
EXPECT_EQ
(
8u
,
o
.
MemberCount
());
}
// AddMember<T>(Value&, T, Allocator)
{
Value
o
(
kObjectType
);
Value
n
(
"s"
);
o
.
AddMember
(
n
,
"string"
,
allocator
);
EXPECT_EQ
(
1u
,
o
.
MemberCount
());
Value
count
(
"#"
);
o
.
AddMember
(
count
,
o
.
MemberCount
(),
allocator
);
EXPECT_EQ
(
2u
,
o
.
MemberCount
());
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
// AddMember(GenericValue&&, ...) variants
{
...
...
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