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
dd901f49
Commit
dd901f49
authored
Jul 03, 2015
by
Philipp A. Hartmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add GenericDocument<>::Swap
See #368.
parent
eb5818a5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
1 deletion
+42
-1
document.h
include/rapidjson/document.h
+16
-0
stack.h
include/rapidjson/internal/stack.h
+13
-0
documenttest.cpp
test/unittest/documenttest.cpp
+13
-1
No files found.
include/rapidjson/document.h
View file @
dd901f49
...
...
@@ -1803,6 +1803,22 @@ public:
}
#endif
//! Exchange the contents of this document with those of another.
/*!
\param other Another document.
\note Constant complexity.
\see GenericValue::Swap
*/
GenericDocument
&
Swap
(
GenericDocument
&
rhs
)
RAPIDJSON_NOEXCEPT
{
using
std
::
swap
;
ValueType
::
Swap
(
rhs
);
stack_
.
Swap
(
rhs
.
stack_
);
swap
(
allocator_
,
rhs
.
allocator_
);
swap
(
ownAllocator_
,
rhs
.
ownAllocator_
);
swap
(
parseResult_
,
rhs
.
parseResult_
);
return
*
this
;
}
//!@name Parse from stream
//!@{
...
...
include/rapidjson/internal/stack.h
View file @
dd901f49
...
...
@@ -15,6 +15,8 @@
#ifndef RAPIDJSON_INTERNAL_STACK_H_
#define RAPIDJSON_INTERNAL_STACK_H_
#include <algorithm> // std::swap
#include "../rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
...
...
@@ -81,6 +83,17 @@ public:
}
#endif
void
Swap
(
Stack
&
rhs
)
RAPIDJSON_NOEXCEPT
{
using
std
::
swap
;
swap
(
allocator_
,
rhs
.
allocator_
);
swap
(
ownAllocator_
,
rhs
.
ownAllocator_
);
swap
(
stack_
,
rhs
.
stack_
);
swap
(
stackTop_
,
rhs
.
stackTop_
);
swap
(
stackEnd_
,
rhs
.
stackEnd_
);
swap
(
initialCapacity_
,
rhs
.
initialCapacity_
);
}
void
Clear
()
{
stackTop_
=
stack_
;
}
void
ShrinkToFit
()
{
...
...
test/unittest/documenttest.cpp
View file @
dd901f49
...
...
@@ -202,7 +202,8 @@ TEST(Document, Swap) {
o
.
SetObject
().
AddMember
(
"a"
,
1
,
a
);
// Swap between Document and Value
d1
.
Swap
(
o
);
// d1.Swap(o); // doesn't compile
o
.
Swap
(
d1
);
EXPECT_TRUE
(
d1
.
IsObject
());
EXPECT_TRUE
(
o
.
IsArray
());
...
...
@@ -212,8 +213,19 @@ TEST(Document, Swap) {
d1
.
Swap
(
d2
);
EXPECT_TRUE
(
d1
.
IsArray
());
EXPECT_TRUE
(
d2
.
IsObject
());
EXPECT_EQ
(
&
d2
.
GetAllocator
(),
&
a
);
// reset value
Value
().
Swap
(
d1
);
EXPECT_TRUE
(
d1
.
IsNull
());
// reset document, including allocator
Document
().
Swap
(
d2
);
EXPECT_TRUE
(
d2
.
IsNull
());
EXPECT_NE
(
&
d2
.
GetAllocator
(),
&
a
);
}
// This should be slow due to assignment in inner-loop.
struct
OutputStringStream
:
public
std
::
ostringstream
{
typedef
char
Ch
;
...
...
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