Merge pull request #300 from miloyip/RemoveFileStream
Remove deprecated FileStream
This commit is contained in:
commit
94c0082e38
@ -2,7 +2,6 @@
|
|||||||
// This example shows writing JSON string with writer directly.
|
// This example shows writing JSON string with writer directly.
|
||||||
|
|
||||||
#include "rapidjson/prettywriter.h" // for stringify JSON
|
#include "rapidjson/prettywriter.h" // for stringify JSON
|
||||||
#include "rapidjson/filestream.h" // wrapper of C stream for prettywriter as output
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -144,13 +143,15 @@ int main(int, char*[]) {
|
|||||||
|
|
||||||
employees.push_back(Employee("Percy TSE", 30, false));
|
employees.push_back(Employee("Percy TSE", 30, false));
|
||||||
|
|
||||||
FileStream s(stdout);
|
StringBuffer sb;
|
||||||
PrettyWriter<FileStream> writer(s); // Can also use Writer for condensed formatting
|
PrettyWriter<StringBuffer> writer(sb);
|
||||||
|
|
||||||
writer.StartArray();
|
writer.StartArray();
|
||||||
for (std::vector<Employee>::const_iterator employeeItr = employees.begin(); employeeItr != employees.end(); ++employeeItr)
|
for (std::vector<Employee>::const_iterator employeeItr = employees.begin(); employeeItr != employees.end(); ++employeeItr)
|
||||||
employeeItr->Serialize(writer);
|
employeeItr->Serialize(writer);
|
||||||
writer.EndArray();
|
writer.EndArray();
|
||||||
|
|
||||||
|
puts(sb.GetString());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "rapidjson/document.h" // rapidjson's DOM-style API
|
#include "rapidjson/document.h" // rapidjson's DOM-style API
|
||||||
#include "rapidjson/prettywriter.h" // for stringify JSON
|
#include "rapidjson/prettywriter.h" // for stringify JSON
|
||||||
#include "rapidjson/filestream.h" // wrapper of C stream for prettywriter as output
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
@ -143,9 +142,10 @@ int main(int, char*[]) {
|
|||||||
// 4. Stringify JSON
|
// 4. Stringify JSON
|
||||||
|
|
||||||
printf("\nModified JSON with reformatting:\n");
|
printf("\nModified JSON with reformatting:\n");
|
||||||
FileStream f(stdout);
|
StringBuffer sb;
|
||||||
PrettyWriter<FileStream> writer(f);
|
PrettyWriter<StringBuffer> writer(sb);
|
||||||
document.Accept(writer); // Accept() traverses the DOM and generates Handler events.
|
document.Accept(writer); // Accept() traverses the DOM and generates Handler events.
|
||||||
|
puts(sb.GetString());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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 <cstdio>
|
|
||||||
|
|
||||||
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_
|
|
@ -26,7 +26,6 @@
|
|||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/prettywriter.h"
|
#include "rapidjson/prettywriter.h"
|
||||||
#include "rapidjson/stringbuffer.h"
|
#include "rapidjson/stringbuffer.h"
|
||||||
#include "rapidjson/filestream.h"
|
|
||||||
#include "rapidjson/filereadstream.h"
|
#include "rapidjson/filereadstream.h"
|
||||||
#include "rapidjson/encodedstream.h"
|
#include "rapidjson/encodedstream.h"
|
||||||
#include "rapidjson/memorystream.h"
|
#include "rapidjson/memorystream.h"
|
||||||
@ -324,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) {
|
TEST_F(RapidJson, FileReadStream) {
|
||||||
for (size_t i = 0; i < kTrialCount; i++) {
|
for (size_t i = 0; i < kTrialCount; i++) {
|
||||||
FILE *fp = fopen(filename_, "rb");
|
FILE *fp = fopen(filename_, "rb");
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#include "unittest.h"
|
#include "unittest.h"
|
||||||
#include "rapidjson/filestream.h"
|
|
||||||
#include "rapidjson/filereadstream.h"
|
#include "rapidjson/filereadstream.h"
|
||||||
#include "rapidjson/filewritestream.h"
|
#include "rapidjson/filewritestream.h"
|
||||||
#include "rapidjson/encodedstream.h"
|
#include "rapidjson/encodedstream.h"
|
||||||
@ -60,24 +59,6 @@ protected:
|
|||||||
size_t length_;
|
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) {
|
TEST_F(FileStreamTest, FileReadStream) {
|
||||||
FILE *fp = fopen(filename_, "rb");
|
FILE *fp = fopen(filename_, "rb");
|
||||||
ASSERT_TRUE(fp != 0);
|
ASSERT_TRUE(fp != 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user