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
10ccdf88
Commit
10ccdf88
authored
Feb 21, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #554 from miloyip/issue552_movingschemadocument
Add move constructor for GenericSchemaDocument
parents
dd25c965
7a9166f3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
1 deletion
+40
-1
schema.h
include/rapidjson/schema.h
+22
-1
schematest.cpp
test/unittest/schematest.cpp
+18
-0
No files found.
include/rapidjson/schema.h
View file @
10ccdf88
...
@@ -1322,7 +1322,7 @@ public:
...
@@ -1322,7 +1322,7 @@ public:
\param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null.
\param remoteProvider An optional remote schema document provider for resolving remote reference. Can be null.
\param allocator An optional allocator instance for allocating memory. Can be null.
\param allocator An optional allocator instance for allocating memory. Can be null.
*/
*/
GenericSchemaDocument
(
const
ValueType
&
document
,
IRemoteSchemaDocumentProviderType
*
remoteProvider
=
0
,
Allocator
*
allocator
=
0
)
:
GenericSchemaDocument
(
const
ValueType
&
document
,
IRemoteSchemaDocumentProviderType
*
remoteProvider
=
0
,
Allocator
*
allocator
=
0
)
RAPIDJSON_NOEXCEPT
:
remoteProvider_
(
remoteProvider
),
remoteProvider_
(
remoteProvider
),
allocator_
(
allocator
),
allocator_
(
allocator
),
ownAllocator_
(),
ownAllocator_
(),
...
@@ -1357,6 +1357,22 @@ public:
...
@@ -1357,6 +1357,22 @@ public:
schemaRef_
.
ShrinkToFit
();
// Deallocate all memory for ref
schemaRef_
.
ShrinkToFit
();
// Deallocate all memory for ref
}
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
//! Move constructor in C++11
GenericSchemaDocument
(
GenericSchemaDocument
&&
rhs
)
RAPIDJSON_NOEXCEPT
:
remoteProvider_
(
rhs
.
remoteProvider_
),
allocator_
(
rhs
.
allocator_
),
ownAllocator_
(
rhs
.
ownAllocator_
),
root_
(
rhs
.
root_
),
schemaMap_
(
std
::
move
(
rhs
.
schemaMap_
)),
schemaRef_
(
std
::
move
(
rhs
.
schemaRef_
))
{
rhs
.
remoteProvider_
=
0
;
rhs
.
allocator_
=
0
;
rhs
.
ownAllocator_
=
0
;
}
#endif
//! Destructor
//! Destructor
~
GenericSchemaDocument
()
{
~
GenericSchemaDocument
()
{
while
(
!
schemaMap_
.
Empty
())
while
(
!
schemaMap_
.
Empty
())
...
@@ -1369,6 +1385,11 @@ public:
...
@@ -1369,6 +1385,11 @@ public:
const
SchemaType
&
GetRoot
()
const
{
return
*
root_
;
}
const
SchemaType
&
GetRoot
()
const
{
return
*
root_
;
}
private
:
private
:
//! Prohibit copying
GenericSchemaDocument
(
const
GenericSchemaDocument
&
);
//! Prohibit assignment
GenericSchemaDocument
&
operator
=
(
const
GenericSchemaDocument
&
);
struct
SchemaRefEntry
{
struct
SchemaRefEntry
{
SchemaRefEntry
(
const
PointerType
&
s
,
const
PointerType
&
t
,
const
SchemaType
**
outSchema
,
Allocator
*
allocator
)
:
source
(
s
,
allocator
),
target
(
t
,
allocator
),
schema
(
outSchema
)
{}
SchemaRefEntry
(
const
PointerType
&
s
,
const
PointerType
&
t
,
const
SchemaType
**
outSchema
,
Allocator
*
allocator
)
:
source
(
s
,
allocator
),
target
(
t
,
allocator
),
schema
(
outSchema
)
{}
PointerType
source
;
PointerType
source
;
...
...
test/unittest/schematest.cpp
View file @
10ccdf88
...
@@ -1152,6 +1152,24 @@ TEST(SchemaValidatingWriter, Simple) {
...
@@ -1152,6 +1152,24 @@ TEST(SchemaValidatingWriter, Simple) {
EXPECT_TRUE
(
validator
.
GetInvalidDocumentPointer
()
==
SchemaDocument
::
PointerType
(
""
));
EXPECT_TRUE
(
validator
.
GetInvalidDocumentPointer
()
==
SchemaDocument
::
PointerType
(
""
));
}
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
static
SchemaDocument
ReturnSchemaDocument
()
{
Document
sd
;
sd
.
Parse
(
"{
\"
type
\"
: [
\"
number
\"
,
\"
string
\"
] }"
);
SchemaDocument
s
(
sd
);
return
s
;
}
TEST
(
Schema
,
Issue552
)
{
SchemaDocument
s
=
ReturnSchemaDocument
();
VALIDATE
(
s
,
"42"
,
true
);
VALIDATE
(
s
,
"
\"
Life, the universe, and everything
\"
"
,
true
);
INVALIDATE
(
s
,
"[
\"
Life
\"
,
\"
the universe
\"
,
\"
and everything
\"
]"
,
""
,
"type"
,
""
);
}
#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
#ifdef __clang__
#ifdef __clang__
RAPIDJSON_DIAG_POP
RAPIDJSON_DIAG_POP
#endif
#endif
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