2011-11-18 17:01:23 +00:00
|
|
|
#ifndef RAPIDJSON_FILESTREAM_H_
|
|
|
|
#define RAPIDJSON_FILESTREAM_H_
|
|
|
|
|
2011-11-21 06:56:47 +00:00
|
|
|
#include "rapidjson.h"
|
2011-11-18 17:01:23 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
namespace rapidjson {
|
|
|
|
|
2011-11-21 06:56:47 +00:00
|
|
|
//! (Depreciated) Wrapper of C file stream for input or output.
|
2011-11-18 17:01:23 +00:00
|
|
|
/*!
|
|
|
|
This simple wrapper does not check the validity of the stream.
|
2014-06-25 19:21:17 +08:00
|
|
|
\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.
|
2011-11-18 17:01:23 +00:00
|
|
|
*/
|
|
|
|
class FileStream {
|
|
|
|
public:
|
|
|
|
typedef char Ch; //!< Character type. Only support char.
|
|
|
|
|
2014-02-01 18:03:52 +01:00
|
|
|
FileStream(FILE* fp) : fp_(fp), current_('\0'), count_(0) { Read(); }
|
2011-11-18 17:01:23 +00:00
|
|
|
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_); }
|
2011-11-22 05:10:46 +00:00
|
|
|
void Flush() { fflush(fp_); }
|
2011-11-18 17:01:23 +00:00
|
|
|
|
|
|
|
// Not implemented
|
|
|
|
char* PutBegin() { return 0; }
|
|
|
|
size_t PutEnd(char*) { return 0; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Read() {
|
|
|
|
RAPIDJSON_ASSERT(fp_ != 0);
|
|
|
|
int c = fgetc(fp_);
|
|
|
|
if (c != EOF) {
|
|
|
|
current_ = (char)c;
|
|
|
|
count_++;
|
|
|
|
}
|
2011-11-21 10:00:33 +00:00
|
|
|
else if (current_ != '\0')
|
2011-11-18 17:01:23 +00:00
|
|
|
current_ = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* fp_;
|
|
|
|
char current_;
|
|
|
|
size_t count_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rapidjson
|
|
|
|
|
|
|
|
#endif // RAPIDJSON_FILESTREAM_H_
|