diff --git a/include/rapidjson/istreamwrapper.h b/include/rapidjson/istreamwrapper.h index 066fabd..412509b 100644 --- a/include/rapidjson/istreamwrapper.h +++ b/include/rapidjson/istreamwrapper.h @@ -13,6 +13,7 @@ // specific language governing permissions and limitations under the License. #include "stream.h" +#include #ifdef __clang__ RAPIDJSON_DIAG_PUSH @@ -38,10 +39,10 @@ RAPIDJSON_NAMESPACE_BEGIN */ template -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 IStreamWrapper; +typedef BasicIStreamWrapper WIStreamWrapper; + #ifdef __clang__ RAPIDJSON_DIAG_POP #endif diff --git a/include/rapidjson/ostreamwrapper.h b/include/rapidjson/ostreamwrapper.h index 4cf407e..127deb3 100644 --- a/include/rapidjson/ostreamwrapper.h +++ b/include/rapidjson/ostreamwrapper.h @@ -13,6 +13,7 @@ // specific language governing permissions and limitations under the License. #include "stream.h" +#include #ifdef __clang__ RAPIDJSON_DIAG_PUSH @@ -38,10 +39,10 @@ RAPIDJSON_NAMESPACE_BEGIN */ template -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 OStreamWrapper; +typedef BasicOStreamWrapper WOStreamWrapper; + #ifdef __clang__ RAPIDJSON_DIAG_POP #endif diff --git a/test/unittest/istreamwrappertest.cpp b/test/unittest/istreamwrappertest.cpp index 9d9ff2f..f6b0fa9 100644 --- a/test/unittest/istreamwrappertest.cpp +++ b/test/unittest/istreamwrappertest.cpp @@ -29,7 +29,7 @@ static void TestStringStream() { { StringStreamType iss; - IStreamWrapper is(iss); + BasicIStreamWrapper 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 is(iss); + BasicIStreamWrapper 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 is(iss); + BasicIStreamWrapper 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 isw(ifs); - EncodedInputStream, IStreamWrapper > eis(isw); + IStreamWrapper isw(ifs); + EncodedInputStream, 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 isw(fs); - EncodedInputStream, IStreamWrapper > eis(isw); + IStreamWrapper isw(fs); + EncodedInputStream, 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)); - IStreamWrapper isw(ifs); + WIStreamWrapper isw(ifs); GenericDocument > d; - d.ParseStream, IStreamWrapper >(isw); + d.ParseStream, 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)); - IStreamWrapper isw(fs); + WIStreamWrapper isw(fs); GenericDocument > d; - d.ParseStream, IStreamWrapper >(isw); + d.ParseStream, WIStreamWrapper>(isw); EXPECT_TRUE(!d.HasParseError()); EXPECT_TRUE(d.IsObject()); EXPECT_EQ(5, d.MemberCount()); diff --git a/test/unittest/ostreamwrappertest.cpp b/test/unittest/ostreamwrappertest.cpp index ba231bd..a94b980 100644 --- a/test/unittest/ostreamwrappertest.cpp +++ b/test/unittest/ostreamwrappertest.cpp @@ -29,7 +29,7 @@ static void TestStringStream() { Ch s[] = { 'A', 'B', 'C' }; StringStreamType oss(s); - OStreamWrapper os(oss); + BasicOStreamWrapper 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 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 osw(ofs); + BasicOStreamWrapper osw(ofs); for (const char* p = s; *p; p++) osw.Put(*p); osw.Flush();