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
92554b52
Commit
92554b52
authored
Nov 30, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master' into issue120floatprecision
parents
23b7a5ec
7eee4303
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
116 additions
and
92 deletions
+116
-92
tutorial.cpp
example/tutorial/tutorial.cpp
+1
-0
document.h
include/rapidjson/document.h
+20
-3
filereadstream.h
include/rapidjson/filereadstream.h
+2
-2
filestream.h
include/rapidjson/filestream.h
+2
-2
filewritestream.h
include/rapidjson/filewritestream.h
+2
-2
stringbuffertest.cpp
test/unittest/stringbuffertest.cpp
+89
-83
No files found.
example/tutorial/tutorial.cpp
View file @
92554b52
...
...
@@ -7,6 +7,7 @@
#include <cstdio>
using
namespace
rapidjson
;
using
namespace
std
;
int
main
(
int
,
char
*
[])
{
////////////////////////////////////////////////////////////////////////////
...
...
include/rapidjson/document.h
View file @
92554b52
...
...
@@ -1896,9 +1896,26 @@ template <typename SourceAllocator>
inline
GenericValue
<
Encoding
,
Allocator
>::
GenericValue
(
const
GenericValue
<
Encoding
,
SourceAllocator
>&
rhs
,
Allocator
&
allocator
)
{
GenericDocument
<
Encoding
,
Allocator
>
d
(
&
allocator
);
rhs
.
Accept
(
d
);
RawAssign
(
*
d
.
stack_
.
template
Pop
<
GenericValue
>
(
1
));
switch
(
rhs
.
GetType
())
{
case
kObjectType
:
case
kArrayType
:
{
// perform deep copy via SAX Handler
GenericDocument
<
Encoding
,
Allocator
>
d
(
&
allocator
);
rhs
.
Accept
(
d
);
RawAssign
(
*
d
.
stack_
.
template
Pop
<
GenericValue
>
(
1
));
}
break
;
case
kStringType
:
if
(
rhs
.
flags_
==
kConstStringFlag
)
{
flags_
=
rhs
.
flags_
;
data_
=
*
reinterpret_cast
<
const
Data
*>
(
&
rhs
.
data_
);
}
else
{
SetStringRaw
(
StringRef
(
rhs
.
GetString
(),
rhs
.
GetStringLength
()),
allocator
);
}
break
;
default
:
// kNumberType, kTrueType, kFalseType, kNullType
flags_
=
rhs
.
flags_
;
data_
=
*
reinterpret_cast
<
const
Data
*>
(
&
rhs
.
data_
);
}
}
RAPIDJSON_NAMESPACE_END
...
...
include/rapidjson/filereadstream.h
View file @
92554b52
...
...
@@ -40,7 +40,7 @@ public:
\param buffer user-supplied buffer.
\param bufferSize size of buffer in bytes. Must >=4 bytes.
*/
FileReadStream
(
FILE
*
fp
,
char
*
buffer
,
size_t
bufferSize
)
:
fp_
(
fp
),
buffer_
(
buffer
),
bufferSize_
(
bufferSize
),
bufferLast_
(
0
),
current_
(
buffer_
),
readCount_
(
0
),
count_
(
0
),
eof_
(
false
)
{
FileReadStream
(
std
::
FILE
*
fp
,
char
*
buffer
,
size_t
bufferSize
)
:
fp_
(
fp
),
buffer_
(
buffer
),
bufferSize_
(
bufferSize
),
bufferLast_
(
0
),
current_
(
buffer_
),
readCount_
(
0
),
count_
(
0
),
eof_
(
false
)
{
RAPIDJSON_ASSERT
(
fp_
!=
0
);
RAPIDJSON_ASSERT
(
bufferSize
>=
4
);
Read
();
...
...
@@ -79,7 +79,7 @@ private:
}
}
FILE
*
fp_
;
std
::
FILE
*
fp_
;
Ch
*
buffer_
;
size_t
bufferSize_
;
Ch
*
bufferLast_
;
...
...
include/rapidjson/filestream.h
View file @
92554b52
...
...
@@ -36,7 +36,7 @@ class FileStream {
public
:
typedef
char
Ch
;
//!< Character type. Only support char.
FileStream
(
FILE
*
fp
)
:
fp_
(
fp
),
current_
(
'\0'
),
count_
(
0
)
{
Read
();
}
FileStream
(
std
::
FILE
*
fp
)
:
fp_
(
fp
),
current_
(
'\0'
),
count_
(
0
)
{
Read
();
}
char
Peek
()
const
{
return
current_
;
}
char
Take
()
{
char
c
=
current_
;
Read
();
return
c
;
}
size_t
Tell
()
const
{
return
count_
;
}
...
...
@@ -63,7 +63,7 @@ private:
current_
=
'\0'
;
}
FILE
*
fp_
;
std
::
FILE
*
fp_
;
char
current_
;
size_t
count_
;
};
...
...
include/rapidjson/filewritestream.h
View file @
92554b52
...
...
@@ -34,7 +34,7 @@ class FileWriteStream {
public
:
typedef
char
Ch
;
//!< Character type. Only support char.
FileWriteStream
(
FILE
*
fp
,
char
*
buffer
,
size_t
bufferSize
)
:
fp_
(
fp
),
buffer_
(
buffer
),
bufferEnd_
(
buffer
+
bufferSize
),
current_
(
buffer_
)
{
FileWriteStream
(
std
::
FILE
*
fp
,
char
*
buffer
,
size_t
bufferSize
)
:
fp_
(
fp
),
buffer_
(
buffer
),
bufferEnd_
(
buffer
+
bufferSize
),
current_
(
buffer_
)
{
RAPIDJSON_ASSERT
(
fp_
!=
0
);
}
...
...
@@ -80,7 +80,7 @@ private:
FileWriteStream
(
const
FileWriteStream
&
);
FileWriteStream
&
operator
=
(
const
FileWriteStream
&
);
FILE
*
fp_
;
std
::
FILE
*
fp_
;
char
*
buffer_
;
char
*
bufferEnd_
;
char
*
current_
;
...
...
test/unittest/stringbuffertest.cpp
View file @
92554b52
...
...
@@ -25,48 +25,48 @@
using
namespace
rapidjson
;
TEST
(
StringBuffer
,
InitialSize
)
{
StringBuffer
buffer
;
EXPECT_EQ
(
0u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
""
,
buffer
.
GetString
());
StringBuffer
buffer
;
EXPECT_EQ
(
0u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
""
,
buffer
.
GetString
());
}
TEST
(
StringBuffer
,
Put
)
{
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
EXPECT_EQ
(
1u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
"A"
,
buffer
.
GetString
());
EXPECT_EQ
(
1u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
"A"
,
buffer
.
GetString
());
}
TEST
(
StringBuffer
,
Clear
)
{
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
buffer
.
Put
(
'B'
);
buffer
.
Put
(
'C'
);
buffer
.
Clear
();
EXPECT_EQ
(
0u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
""
,
buffer
.
GetString
());
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
buffer
.
Put
(
'B'
);
buffer
.
Put
(
'C'
);
buffer
.
Clear
();
EXPECT_EQ
(
0u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
""
,
buffer
.
GetString
());
}
TEST
(
StringBuffer
,
Push
)
{
StringBuffer
buffer
;
buffer
.
Push
(
5
);
StringBuffer
buffer
;
buffer
.
Push
(
5
);
EXPECT_EQ
(
5u
,
buffer
.
GetSize
());
EXPECT_EQ
(
5u
,
buffer
.
GetSize
());
}
TEST
(
StringBuffer
,
Pop
)
{
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
buffer
.
Put
(
'B'
);
buffer
.
Put
(
'C'
);
buffer
.
Put
(
'D'
);
buffer
.
Put
(
'E'
);
buffer
.
Pop
(
3
);
EXPECT_EQ
(
2u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
"AB"
,
buffer
.
GetString
());
StringBuffer
buffer
;
buffer
.
Put
(
'A'
);
buffer
.
Put
(
'B'
);
buffer
.
Put
(
'C'
);
buffer
.
Put
(
'D'
);
buffer
.
Put
(
'E'
);
buffer
.
Pop
(
3
);
EXPECT_EQ
(
2u
,
buffer
.
GetSize
());
EXPECT_STREQ
(
"AB"
,
buffer
.
GetString
());
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
...
...
@@ -74,67 +74,73 @@ TEST(StringBuffer, Pop) {
#include <type_traits>
TEST
(
StringBuffer
,
Traits
)
{
static_assert
(
std
::
is_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_default_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_copy_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_move_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_default_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_copy_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_move_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_assignable
<
StringBuffer
,
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_copy_assignable
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_move_assignable
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_assignable
<
StringBuffer
,
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_copy_assignable
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_move_assignable
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_destructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_nothrow_destructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_default_constructible
<
StringBuffer
>::
value
,
""
);
#ifndef _MSC_VER
static_assert
(
!
std
::
is_copy_constructible
<
StringBuffer
>::
value
,
""
);
#endif
static_assert
(
std
::
is_move_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_default_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_copy_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_move_constructible
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_assignable
<
StringBuffer
,
StringBuffer
>::
value
,
""
);
#ifndef _MSC_VER
static_assert
(
!
std
::
is_copy_assignable
<
StringBuffer
>::
value
,
""
);
#endif
static_assert
(
std
::
is_move_assignable
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_assignable
<
StringBuffer
,
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_copy_assignable
<
StringBuffer
>::
value
,
""
);
static_assert
(
!
std
::
is_nothrow_move_assignable
<
StringBuffer
>::
value
,
""
);
static_assert
(
std
::
is_destructible
<
StringBuffer
>::
value
,
""
);
#ifndef _MSC_VER
static_assert
(
std
::
is_nothrow_destructible
<
StringBuffer
>::
value
,
""
);
#endif
}
TEST
(
StringBuffer
,
MoveConstructor
)
{
StringBuffer
x
;
x
.
Put
(
'A'
);
x
.
Put
(
'B'
);
x
.
Put
(
'C'
);
x
.
Put
(
'D'
);
EXPECT_EQ
(
4u
,
x
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
x
.
GetString
());
// StringBuffer y(x); // does not compile (!is_copy_constructible)
StringBuffer
y
(
std
::
move
(
x
));
EXPECT_EQ
(
0u
,
x
.
GetSize
());
EXPECT_EQ
(
4u
,
y
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
y
.
GetString
());
// StringBuffer z = y; // does not compile (!is_copy_assignable)
StringBuffer
z
=
std
::
move
(
y
);
EXPECT_EQ
(
0u
,
y
.
GetSize
());
EXPECT_EQ
(
4u
,
z
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
z
.
GetString
());
StringBuffer
x
;
x
.
Put
(
'A'
);
x
.
Put
(
'B'
);
x
.
Put
(
'C'
);
x
.
Put
(
'D'
);
EXPECT_EQ
(
4u
,
x
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
x
.
GetString
());
// StringBuffer y(x); // does not compile (!is_copy_constructible)
StringBuffer
y
(
std
::
move
(
x
));
EXPECT_EQ
(
0u
,
x
.
GetSize
());
EXPECT_EQ
(
4u
,
y
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
y
.
GetString
());
// StringBuffer z = y; // does not compile (!is_copy_assignable)
StringBuffer
z
=
std
::
move
(
y
);
EXPECT_EQ
(
0u
,
y
.
GetSize
());
EXPECT_EQ
(
4u
,
z
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
z
.
GetString
());
}
TEST
(
StringBuffer
,
MoveAssignment
)
{
StringBuffer
x
;
x
.
Put
(
'A'
);
x
.
Put
(
'B'
);
x
.
Put
(
'C'
);
x
.
Put
(
'D'
);
EXPECT_EQ
(
4u
,
x
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
x
.
GetString
());
StringBuffer
y
;
// y = x; // does not compile (!is_copy_assignable)
y
=
std
::
move
(
x
);
EXPECT_EQ
(
0u
,
x
.
GetSize
());
EXPECT_EQ
(
4u
,
y
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
y
.
GetString
());
StringBuffer
x
;
x
.
Put
(
'A'
);
x
.
Put
(
'B'
);
x
.
Put
(
'C'
);
x
.
Put
(
'D'
);
EXPECT_EQ
(
4u
,
x
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
x
.
GetString
());
StringBuffer
y
;
// y = x; // does not compile (!is_copy_assignable)
y
=
std
::
move
(
x
);
EXPECT_EQ
(
0u
,
x
.
GetSize
());
EXPECT_EQ
(
4u
,
y
.
GetSize
());
EXPECT_STREQ
(
"ABCD"
,
y
.
GetString
());
}
#endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
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