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
2ee15de4
Commit
2ee15de4
authored
May 02, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add no allocator overloads for Swap
parent
fd938658
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
pointer.h
include/rapidjson/pointer.h
+17
-1
pointertest.cpp
test/unittest/pointertest.cpp
+20
-0
No files found.
include/rapidjson/pointer.h
View file @
2ee15de4
...
...
@@ -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
...
...
test/unittest/pointertest.cpp
View file @
2ee15de4
...
...
@@ -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
());
}
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