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
bc9d7866
Commit
bc9d7866
authored
Sep 03, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #128 from pah/feature/cxx11-move
Initial C++11 move support
parents
15d70d6a
8ae2266c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
12 deletions
+129
-12
Doxyfile
build/Doxyfile
+2
-1
document.h
include/rapidjson/document.h
+0
-0
meta.h
include/rapidjson/internal/meta.h
+6
-2
rapidjson.h
include/rapidjson/rapidjson.h
+43
-2
valuetest.cpp
test/unittest/valuetest.cpp
+78
-7
No files found.
build/Doxyfile
View file @
bc9d7866
...
...
@@ -2004,7 +2004,8 @@ PREDEFINED = \
# definition found in the source code.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
EXPAND_AS_DEFINED =
EXPAND_AS_DEFINED = \
RAPIDJSON_NOEXCEPT
# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
# remove all references to function-like macros that are alone on a line, have
...
...
include/rapidjson/document.h
View file @
bc9d7866
This diff is collapsed.
Click to expand it.
include/rapidjson/internal/meta.h
View file @
bc9d7866
...
...
@@ -21,6 +21,10 @@
#ifndef RAPIDJSON_INTERNAL_META_H_
#define RAPIDJSON_INTERNAL_META_H_
#ifndef RAPIDJSON_RAPIDJSON_H_
#error <rapidjson.h> not yet included. Do not include this file directly.
#endif
#ifdef __GNUC__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF
(
effc
++
)
...
...
@@ -30,7 +34,7 @@ RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF
(
6334
)
#endif
#if
def
RAPIDJSON_HAS_CXX11_TYPETRAITS
#if RAPIDJSON_HAS_CXX11_TYPETRAITS
#include <type_traits>
#endif
...
...
@@ -100,7 +104,7 @@ template <typename T> struct IsPointer<T*> : TrueType {};
///////////////////////////////////////////////////////////////////////////////
// IsBaseOf
//
#if
def
RAPIDJSON_HAS_CXX11_TYPETRAITS
#if RAPIDJSON_HAS_CXX11_TYPETRAITS
template
<
typename
B
,
typename
D
>
struct
IsBaseOf
:
BoolType
<
::
std
::
is_base_of
<
B
,
D
>::
value
>
{};
...
...
include/rapidjson/rapidjson.h
View file @
bc9d7866
...
...
@@ -318,7 +318,12 @@ template<int x> struct StaticAssertTest {};
///////////////////////////////////////////////////////////////////////////////
// RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF
#if defined(__clang__) || (defined(__GNUC__) && RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__) >= RAPIDJSON_VERSION_CODE(4,2,0))
#if defined(__GNUC__)
#define RAPIDJSON_GNUC \
RAPIDJSON_VERSION_CODE
(
__GNUC__
,
__GNUC_MINOR__
,
__GNUC_PATCHLEVEL__
)
#endif
#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
...
...
@@ -326,7 +331,7 @@ template<int x> struct StaticAssertTest {};
RAPIDJSON_DIAG_PRAGMA
(
ignored
RAPIDJSON_STRINGIFY
(
RAPIDJSON_JOIN
(
-
W
,
x
)))
// push/pop support in Clang and GCC>=4.6
#if defined(__clang__) || (defined(
__GNUC__) && RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
>= RAPIDJSON_VERSION_CODE(4,6,0))
#if defined(__clang__) || (defined(
RAPIDJSON_GNUC) && RAPIDJSON_GNUC
>= RAPIDJSON_VERSION_CODE(4,6,0))
#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
#else // GCC >= 4.2, < 4.6
...
...
@@ -352,6 +357,42 @@ template<int x> struct StaticAssertTest {};
#endif // RAPIDJSON_DIAG_*
///////////////////////////////////////////////////////////////////////////////
// C++11 features
#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
#if defined(__clang__)
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS __has_feature(cxx_rvalue_references)
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
(
defined
(
_MSC_VER
)
&&
_MSC_VER
>=
1600
)
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
#else
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
#endif
#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
#ifndef RAPIDJSON_HAS_CXX11_NOEXCEPT
#if defined(__clang__)
#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
// (defined(_MSC_VER) && _MSC_VER >= ????) // not yet supported
#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
#else
#define RAPIDJSON_HAS_CXX11_NOEXCEPT 0
#endif
#endif
#if RAPIDJSON_HAS_CXX11_NOEXCEPT
#define RAPIDJSON_NOEXCEPT noexcept
#else
#define RAPIDJSON_NOEXCEPT
/* noexcept */
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
// no automatic detection, yet
#ifndef RAPIDJSON_HAS_CXX11_TYPETRAITS
#define RAPIDJSON_HAS_CXX11_TYPETRAITS 0
#endif
//!@endcond
///////////////////////////////////////////////////////////////////////////////
...
...
test/unittest/valuetest.cpp
View file @
bc9d7866
...
...
@@ -24,7 +24,7 @@
using
namespace
rapidjson
;
TEST
(
Value
,
default_c
onstructor
)
{
TEST
(
Value
,
DefaultC
onstructor
)
{
Value
x
;
EXPECT_EQ
(
kNullType
,
x
.
GetType
());
EXPECT_TRUE
(
x
.
IsNull
());
...
...
@@ -38,7 +38,32 @@ TEST(Value, default_constructor) {
// Value y = x;
//}
TEST
(
Value
,
assignment_operator
)
{
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
TEST
(
Value
,
MoveConstructor
)
{
typedef
GenericValue
<
UTF8
<>
,
CrtAllocator
>
Value
;
Value
::
AllocatorType
allocator
;
Value
x
((
Value
(
kArrayType
)));
x
.
Reserve
(
4u
,
allocator
);
x
.
PushBack
(
1
,
allocator
).
PushBack
(
2
,
allocator
).
PushBack
(
3
,
allocator
).
PushBack
(
4
,
allocator
);
EXPECT_TRUE
(
x
.
IsArray
());
EXPECT_EQ
(
4u
,
x
.
Size
());
// Value y(x); // should not compile
Value
y
(
std
::
move
(
x
));
EXPECT_TRUE
(
x
.
IsNull
());
EXPECT_TRUE
(
y
.
IsArray
());
EXPECT_EQ
(
4u
,
y
.
Size
());
// Value z = y; // should not compile
Value
z
=
std
::
move
(
y
);
EXPECT_TRUE
(
y
.
IsNull
());
EXPECT_TRUE
(
z
.
IsArray
());
EXPECT_EQ
(
4u
,
z
.
Size
());
}
#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
TEST
(
Value
,
AssignmentOperator
)
{
Value
x
(
1234
);
Value
y
;
y
=
x
;
...
...
@@ -63,6 +88,22 @@ TEST(Value, assignment_operator) {
y
=
StringRef
(
mstr
);
EXPECT_TRUE
(
y
.
IsString
());
EXPECT_EQ
(
y
.
GetString
(),
mstr
);
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
// C++11 move assignment
x
=
Value
(
"World"
);
EXPECT_TRUE
(
x
.
IsString
());
EXPECT_STREQ
(
"World"
,
x
.
GetString
());
x
=
std
::
move
(
y
);
EXPECT_TRUE
(
y
.
IsNull
());
EXPECT_TRUE
(
x
.
IsString
());
EXPECT_EQ
(
x
.
GetString
(),
mstr
);
y
=
std
::
move
(
Value
().
SetInt
(
1234
));
EXPECT_TRUE
(
y
.
IsInt
());
EXPECT_EQ
(
1234
,
y
);
#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
}
template
<
typename
A
,
typename
B
>
...
...
@@ -81,7 +122,7 @@ void TestUnequal(const A& a, const B& b) {
EXPECT_TRUE
(
b
!=
a
);
}
TEST
(
Value
,
equalto_o
perator
)
{
TEST
(
Value
,
EqualtoO
perator
)
{
Value
::
AllocatorType
allocator
;
Value
x
(
kObjectType
);
x
.
AddMember
(
"hello"
,
"world"
,
allocator
)
...
...
@@ -555,7 +596,7 @@ TEST(Value, String) {
EXPECT_STREQ
(
"World"
,
w
.
GetString
());
EXPECT_EQ
(
5u
,
w
.
GetStringLength
());
#if
def
RAPIDJSON_HAS_STDSTRING
#if RAPIDJSON_HAS_STDSTRING
{
std
::
string
str
=
"Hello World"
;
str
[
5
]
=
'\0'
;
...
...
@@ -643,6 +684,21 @@ TEST(Value, Array) {
EXPECT_TRUE
(
y
[
4u
].
IsString
());
EXPECT_STREQ
(
"foo"
,
y
[
4u
].
GetString
());
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
// PushBack(GenericValue&&, Allocator&);
{
Value
y
(
kArrayType
);
y
.
PushBack
(
Value
(
true
),
allocator
);
y
.
PushBack
(
std
::
move
(
Value
(
kArrayType
).
PushBack
(
Value
(
1
),
allocator
).
PushBack
(
"foo"
,
allocator
)),
allocator
);
EXPECT_EQ
(
2u
,
y
.
Size
());
EXPECT_TRUE
(
y
[
0u
].
IsTrue
());
EXPECT_TRUE
(
y
[
1u
].
IsArray
());
EXPECT_EQ
(
2u
,
y
[
1u
].
Size
());
EXPECT_TRUE
(
y
[
1u
][
0u
].
IsInt
());
EXPECT_TRUE
(
y
[
1u
][
1u
].
IsString
());
}
#endif
// iterator
Value
::
ValueIterator
itr
=
x
.
Begin
();
EXPECT_TRUE
(
itr
!=
x
.
End
());
...
...
@@ -751,7 +807,6 @@ TEST(Value, Array) {
}
// Working in gcc without C++11, but VS2013 cannot compile. To be diagnosed.
#if 0
// http://en.wikipedia.org/wiki/Erase-remove_idiom
x
.
Clear
();
for
(
int
i
=
0
;
i
<
10
;
i
++
)
...
...
@@ -760,11 +815,11 @@ TEST(Value, Array) {
else
x
.
PushBack
(
Value
(
kNullType
).
Move
(),
allocator
);
x.Erase(std::remove(x.Begin(), x.End(), Value(kNullType)), x.End());
const
Value
null
(
kNullType
);
x
.
Erase
(
std
::
remove
(
x
.
Begin
(),
x
.
End
(),
null
),
x
.
End
());
EXPECT_EQ
(
5u
,
x
.
Size
());
for
(
int
i
=
0
;
i
<
5
;
i
++
)
EXPECT_EQ
(
i
*
2
,
x
[
i
]);
#endif
// SetArray()
Value
z
;
...
...
@@ -818,6 +873,22 @@ TEST(Value, Object) {
EXPECT_EQ
(
8u
,
o
.
MemberCount
());
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
// AddMember(GenericValue&&, ...) variants
{
Value
o
(
kObjectType
);
o
.
AddMember
(
Value
(
"true"
),
Value
(
true
),
allocator
);
o
.
AddMember
(
Value
(
"false"
),
Value
(
false
).
Move
(),
allocator
);
// value is lvalue ref
o
.
AddMember
(
Value
(
"int"
).
Move
(),
Value
(
-
1
),
allocator
);
// name is lvalue ref
o
.
AddMember
(
"uint"
,
std
::
move
(
Value
().
SetUint
(
1u
)),
allocator
);
// name is literal, value is rvalue
EXPECT_TRUE
(
o
[
"true"
].
GetBool
());
EXPECT_FALSE
(
o
[
"false"
].
GetBool
());
EXPECT_EQ
(
-
1
,
o
[
"int"
].
GetInt
());
EXPECT_EQ
(
1u
,
o
[
"uint"
].
GetUint
());
EXPECT_EQ
(
4u
,
o
.
MemberCount
());
}
#endif
// Tests a member with null character
Value
name
;
const
Value
C0D
(
"C
\0
D"
,
3
);
...
...
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