Commit c3133def authored by Milo Yip's avatar Milo Yip

Renamed IStreamWrapper/OStreamWrapper

parent b9bca8e5
......@@ -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 BasicIStreamWrapper {
public:
typedef typename StreamType::char_type Ch;
IStreamWrapper(StreamType& stream) : stream_(stream), count_(), peekBuffer_() {}
BasicIStreamWrapper(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
......
......@@ -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 BasicOStreamWrapper {
public:
typedef typename StreamType::char_type Ch;
OStreamWrapper(StreamType& stream) : stream_(stream) {}
BasicOStreamWrapper(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
......
......@@ -29,7 +29,7 @@ static void TestStringStream() {
{
StringStreamType iss;
IStreamWrapper<StringStreamType> is(iss);
BasicIStreamWrapper<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);
BasicIStreamWrapper<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);
BasicIStreamWrapper<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());
......
......@@ -29,7 +29,7 @@ static void TestStringStream() {
Ch s[] = { 'A', 'B', 'C' };
StringStreamType oss(s);
OStreamWrapper<StringStreamType> os(oss);
BasicOStreamWrapper<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);
BasicOStreamWrapper<ofstream> osw(ofs);
for (const char* p = s; *p; p++)
osw.Put(*p);
osw.Flush();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment