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