From 67be9ed2cb89edeb3548f2d907a8a282fff451c7 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 11:08:47 +0800 Subject: [PATCH 1/2] Remove depreciated FileStream --- example/serialize/serialize.cpp | 7 ++-- example/tutorial/tutorial.cpp | 6 +-- include/rapidjson/filestream.h | 67 -------------------------------- test/perftest/rapidjsontest.cpp | 1 - test/unittest/filestreamtest.cpp | 19 --------- 5 files changed, 7 insertions(+), 93 deletions(-) delete mode 100644 include/rapidjson/filestream.h diff --git a/example/serialize/serialize.cpp b/example/serialize/serialize.cpp index 4f9278b44..7427939a9 100644 --- a/example/serialize/serialize.cpp +++ b/example/serialize/serialize.cpp @@ -2,7 +2,6 @@ // This example shows writing JSON string with writer directly. #include "rapidjson/prettywriter.h" // for stringify JSON -#include "rapidjson/filestream.h" // wrapper of C stream for prettywriter as output #include #include #include @@ -144,13 +143,15 @@ int main(int, char*[]) { employees.push_back(Employee("Percy TSE", 30, false)); - FileStream s(stdout); - PrettyWriter writer(s); // Can also use Writer for condensed formatting + StringBuffer sb; + PrettyWriter writer(sb); writer.StartArray(); for (std::vector::const_iterator employeeItr = employees.begin(); employeeItr != employees.end(); ++employeeItr) employeeItr->Serialize(writer); writer.EndArray(); + puts(sb.GetString()); + return 0; } diff --git a/example/tutorial/tutorial.cpp b/example/tutorial/tutorial.cpp index 49704c197..206fdb9da 100644 --- a/example/tutorial/tutorial.cpp +++ b/example/tutorial/tutorial.cpp @@ -3,7 +3,6 @@ #include "rapidjson/document.h" // rapidjson's DOM-style API #include "rapidjson/prettywriter.h" // for stringify JSON -#include "rapidjson/filestream.h" // wrapper of C stream for prettywriter as output #include using namespace rapidjson; @@ -143,9 +142,10 @@ int main(int, char*[]) { // 4. Stringify JSON printf("\nModified JSON with reformatting:\n"); - FileStream f(stdout); - PrettyWriter writer(f); + StringBuffer sb; + PrettyWriter writer(sb); document.Accept(writer); // Accept() traverses the DOM and generates Handler events. + puts(sb.GetString()); return 0; } diff --git a/include/rapidjson/filestream.h b/include/rapidjson/filestream.h deleted file mode 100644 index 12701e28a..000000000 --- a/include/rapidjson/filestream.h +++ /dev/null @@ -1,67 +0,0 @@ -// Tencent is pleased to support the open source community by making RapidJSON available. -// -// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. -// -// Licensed under the MIT License (the "License"); you may not use this file except -// in compliance with the License. You may obtain a copy of the License at -// -// http://opensource.org/licenses/MIT -// -// Unless required by applicable law or agreed to in writing, software distributed -// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, either express or implied. See the License for the -// specific language governing permissions and limitations under the License. - -#ifndef RAPIDJSON_FILESTREAM_H_ -#define RAPIDJSON_FILESTREAM_H_ - -#include "rapidjson.h" -#include - -RAPIDJSON_NAMESPACE_BEGIN - -//! (Deprecated) Wrapper of C file stream for input or output. -/*! - This simple wrapper does not check the validity of the stream. - \note implements Stream concept - \note deprecated: This was only for basic testing in version 0.1, it is found that the performance is very low by using fgetc(). Use FileReadStream instead. -*/ -class FileStream { -public: - typedef char Ch; //!< Character type. Only support char. - - 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_; } - void Put(char c) { fputc(c, fp_); } - void Flush() { fflush(fp_); } - - // Not implemented - char* PutBegin() { return 0; } - size_t PutEnd(char*) { return 0; } - -private: - // Prohibit copy constructor & assignment operator. - FileStream(const FileStream&); - FileStream& operator=(const FileStream&); - - void Read() { - RAPIDJSON_ASSERT(fp_ != 0); - int c = fgetc(fp_); - if (c != EOF) { - current_ = (char)c; - count_++; - } - else if (current_ != '\0') - current_ = '\0'; - } - - std::FILE* fp_; - char current_; - size_t count_; -}; - -RAPIDJSON_NAMESPACE_END - -#endif // RAPIDJSON_FILESTREAM_H_ diff --git a/test/perftest/rapidjsontest.cpp b/test/perftest/rapidjsontest.cpp index 74bdf27b4..315403c63 100644 --- a/test/perftest/rapidjsontest.cpp +++ b/test/perftest/rapidjsontest.cpp @@ -26,7 +26,6 @@ #include "rapidjson/document.h" #include "rapidjson/prettywriter.h" #include "rapidjson/stringbuffer.h" -#include "rapidjson/filestream.h" #include "rapidjson/filereadstream.h" #include "rapidjson/encodedstream.h" #include "rapidjson/memorystream.h" diff --git a/test/unittest/filestreamtest.cpp b/test/unittest/filestreamtest.cpp index a17633287..253a9d8e6 100644 --- a/test/unittest/filestreamtest.cpp +++ b/test/unittest/filestreamtest.cpp @@ -19,7 +19,6 @@ // THE SOFTWARE. #include "unittest.h" -#include "rapidjson/filestream.h" #include "rapidjson/filereadstream.h" #include "rapidjson/filewritestream.h" #include "rapidjson/encodedstream.h" @@ -60,24 +59,6 @@ class FileStreamTest : public ::testing::Test { size_t length_; }; -// Deprecated -//TEST_F(FileStreamTest, FileStream_Read) { -// FILE *fp = fopen(filename_, "rb"); -// ASSERT_TRUE(fp != 0); -// FileStream s(fp); -// -// for (size_t i = 0; i < length_; i++) { -// EXPECT_EQ(json_[i], s.Peek()); -// EXPECT_EQ(json_[i], s.Peek()); // 2nd time should be the same -// EXPECT_EQ(json_[i], s.Take()); -// } -// -// EXPECT_EQ(length_, s.Tell()); -// EXPECT_EQ('\0', s.Peek()); -// -// fclose(fp); -//} - TEST_F(FileStreamTest, FileReadStream) { FILE *fp = fopen(filename_, "rb"); ASSERT_TRUE(fp != 0); From 9dcc1f44f59cf046a079f6f19bfcaa78d29ba1a4 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 11:09:45 +0800 Subject: [PATCH 2/2] Remove deprecated test --- test/perftest/rapidjsontest.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/perftest/rapidjsontest.cpp b/test/perftest/rapidjsontest.cpp index 315403c63..875c5ebdc 100644 --- a/test/perftest/rapidjsontest.cpp +++ b/test/perftest/rapidjsontest.cpp @@ -323,17 +323,6 @@ TEST_F(RapidJson, UTF8_Validate) { } } -// Deprecated. -//TEST_F(RapidJson, FileStream_Read) { -// for (size_t i = 0; i < kTrialCount; i++) { -// FILE *fp = fopen(filename_, "rb"); -// FileStream s(fp); -// while (s.Take() != '\0') -// ; -// fclose(fp); -// } -//} - TEST_F(RapidJson, FileReadStream) { for (size_t i = 0; i < kTrialCount; i++) { FILE *fp = fopen(filename_, "rb");