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
c3133def
Commit
c3133def
authored
Feb 07, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed IStreamWrapper/OStreamWrapper
parent
b9bca8e5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
18 deletions
+26
-18
istreamwrapper.h
include/rapidjson/istreamwrapper.h
+6
-2
ostreamwrapper.h
include/rapidjson/ostreamwrapper.h
+6
-2
istreamwrappertest.cpp
test/unittest/istreamwrappertest.cpp
+11
-11
ostreamwrappertest.cpp
test/unittest/ostreamwrappertest.cpp
+3
-3
No files found.
include/rapidjson/istreamwrapper.h
View file @
c3133def
...
...
@@ -13,6 +13,7 @@
// specific language governing permissions and limitations under the License.
#include "stream.h"
#include <iosfwd>
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
...
...
@@ -38,10 +39,10 @@ RAPIDJSON_NAMESPACE_BEGIN
*/
template
<
typename
StreamType
>
class
IStreamWrapper
{
class
Basic
IStreamWrapper
{
public
:
typedef
typename
StreamType
::
char_type
Ch
;
IStreamWrapper
(
StreamType
&
stream
)
:
stream_
(
stream
),
count_
(),
peekBuffer_
()
{}
Basic
IStreamWrapper
(
StreamType
&
stream
)
:
stream_
(
stream
),
count_
(),
peekBuffer_
()
{}
Ch
Peek
()
const
{
typename
StreamType
::
int_type
c
=
stream_
.
peek
();
...
...
@@ -91,6 +92,9 @@ private:
mutable
Ch
peekBuffer_
[
4
];
};
typedef
BasicIStreamWrapper
<
std
::
istream
>
IStreamWrapper
;
typedef
BasicIStreamWrapper
<
std
::
wistream
>
WIStreamWrapper
;
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
...
...
include/rapidjson/ostreamwrapper.h
View file @
c3133def
...
...
@@ -13,6 +13,7 @@
// specific language governing permissions and limitations under the License.
#include "stream.h"
#include <iosfwd>
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
...
...
@@ -38,10 +39,10 @@ RAPIDJSON_NAMESPACE_BEGIN
*/
template
<
typename
StreamType
>
class
OStreamWrapper
{
class
Basic
OStreamWrapper
{
public
:
typedef
typename
StreamType
::
char_type
Ch
;
OStreamWrapper
(
StreamType
&
stream
)
:
stream_
(
stream
)
{}
Basic
OStreamWrapper
(
StreamType
&
stream
)
:
stream_
(
stream
)
{}
void
Put
(
Ch
c
)
{
stream_
.
put
(
c
);
...
...
@@ -62,6 +63,9 @@ private:
StreamType
&
stream_
;
};
typedef
BasicOStreamWrapper
<
std
::
ostream
>
OStreamWrapper
;
typedef
BasicOStreamWrapper
<
std
::
wostream
>
WOStreamWrapper
;
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
...
...
test/unittest/istreamwrappertest.cpp
View file @
c3133def
...
...
@@ -29,7 +29,7 @@ static void TestStringStream() {
{
StringStreamType
iss
;
IStreamWrapper
<
StringStreamType
>
is
(
iss
);
Basic
IStreamWrapper
<
StringStreamType
>
is
(
iss
);
EXPECT_EQ
(
0
,
is
.
Tell
());
if
(
sizeof
(
Ch
)
==
1
)
{
EXPECT_EQ
(
0
,
is
.
Peek4
());
...
...
@@ -43,7 +43,7 @@ static void TestStringStream() {
{
Ch
s
[]
=
{
'A'
,
'B'
,
'C'
,
'\0'
};
StringStreamType
iss
(
s
);
IStreamWrapper
<
StringStreamType
>
is
(
iss
);
Basic
IStreamWrapper
<
StringStreamType
>
is
(
iss
);
EXPECT_EQ
(
0
,
is
.
Tell
());
if
(
sizeof
(
Ch
)
==
1
)
EXPECT_EQ
(
0
,
is
.
Peek4
());
// less than 4 bytes
...
...
@@ -61,7 +61,7 @@ static void TestStringStream() {
{
Ch
s
[]
=
{
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'\0'
};
StringStreamType
iss
(
s
);
IStreamWrapper
<
StringStreamType
>
is
(
iss
);
Basic
IStreamWrapper
<
StringStreamType
>
is
(
iss
);
if
(
sizeof
(
Ch
)
==
1
)
{
const
Ch
*
c
=
is
.
Peek4
();
for
(
int
i
=
0
;
i
<
4
;
i
++
)
...
...
@@ -118,8 +118,8 @@ static bool Open(FileStreamType& fs, const char* filename) {
TEST
(
IStreamWrapper
,
ifstream
)
{
ifstream
ifs
;
ASSERT_TRUE
(
Open
(
ifs
,
"utf8bom.json"
));
IStreamWrapper
<
ifstream
>
isw
(
ifs
);
EncodedInputStream
<
UTF8
<>
,
IStreamWrapper
<
ifstream
>
>
eis
(
isw
);
IStreamWrapper
isw
(
ifs
);
EncodedInputStream
<
UTF8
<>
,
IStreamWrapper
>
eis
(
isw
);
Document
d
;
EXPECT_TRUE
(
!
d
.
ParseStream
(
eis
).
HasParseError
());
EXPECT_TRUE
(
d
.
IsObject
());
...
...
@@ -129,8 +129,8 @@ TEST(IStreamWrapper, ifstream) {
TEST
(
IStreamWrapper
,
fstream
)
{
fstream
fs
;
ASSERT_TRUE
(
Open
(
fs
,
"utf8bom.json"
));
IStreamWrapper
<
fstream
>
isw
(
fs
);
EncodedInputStream
<
UTF8
<>
,
IStreamWrapper
<
fstream
>
>
eis
(
isw
);
IStreamWrapper
isw
(
fs
);
EncodedInputStream
<
UTF8
<>
,
IStreamWrapper
>
eis
(
isw
);
Document
d
;
EXPECT_TRUE
(
!
d
.
ParseStream
(
eis
).
HasParseError
());
EXPECT_TRUE
(
d
.
IsObject
());
...
...
@@ -147,9 +147,9 @@ TEST(IStreamWrapper, wifstream) {
ASSERT_TRUE(Open(ifs, "utf16bebom.json"));
ifs.imbue(std::locale(ifs.getloc(),
new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>));
IStreamWrapper<wifstream>
isw(ifs);
WIStreamWrapper
isw(ifs);
GenericDocument<UTF16<> > d;
d.ParseStream<kParseDefaultFlags, UTF16<>,
IStreamWrapper<wifstream>
>(isw);
d.ParseStream<kParseDefaultFlags, UTF16<>,
WIStreamWrapper
>(isw);
EXPECT_TRUE(!d.HasParseError());
EXPECT_TRUE(d.IsObject());
EXPECT_EQ(5, d.MemberCount());
...
...
@@ -160,9 +160,9 @@ TEST(IStreamWrapper, wfstream) {
ASSERT_TRUE(Open(fs, "utf16bebom.json"));
fs.imbue(std::locale(fs.getloc(),
new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>));
IStreamWrapper<wfstream>
isw(fs);
WIStreamWrapper
isw(fs);
GenericDocument<UTF16<> > d;
d.ParseStream<kParseDefaultFlags, UTF16<>,
IStreamWrapper<wfstream>
>(isw);
d.ParseStream<kParseDefaultFlags, UTF16<>,
WIStreamWrapper
>(isw);
EXPECT_TRUE(!d.HasParseError());
EXPECT_TRUE(d.IsObject());
EXPECT_EQ(5, d.MemberCount());
...
...
test/unittest/ostreamwrappertest.cpp
View file @
c3133def
...
...
@@ -29,7 +29,7 @@ static void TestStringStream() {
Ch
s
[]
=
{
'A'
,
'B'
,
'C'
};
StringStreamType
oss
(
s
);
OStreamWrapper
<
StringStreamType
>
os
(
oss
);
Basic
OStreamWrapper
<
StringStreamType
>
os
(
oss
);
for
(
size_t
i
=
0
;
i
<
3
;
i
++
)
os
.
Put
(
s
[
i
]);
os
.
Flush
();
...
...
@@ -54,7 +54,7 @@ TEST(OStreamWrapper, wstringstream) {
}
TEST
(
OStreamWrapper
,
cout
)
{
OStreamWrapper
<
ostream
>
os
(
cout
);
OStreamWrapper
os
(
cout
);
const
char
*
s
=
"Hello World!
\n
"
;
while
(
*
s
)
os
.
Put
(
*
s
++
);
...
...
@@ -70,7 +70,7 @@ static void TestFileStream() {
const
char
*
s
=
"Hello World!
\n
"
;
{
ofstream
ofs
(
filename
,
ios
::
out
|
ios
::
binary
);
OStreamWrapper
<
ofstream
>
osw
(
ofs
);
Basic
OStreamWrapper
<
ofstream
>
osw
(
ofs
);
for
(
const
char
*
p
=
s
;
*
p
;
p
++
)
osw
.
Put
(
*
p
);
osw
.
Flush
();
...
...
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