All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
filestream.h
1 #ifndef RAPIDJSON_FILESTREAM_H_
2 #define RAPIDJSON_FILESTREAM_H_
3 
4 #include "rapidjson.h"
5 #include <cstdio>
6 
7 namespace rapidjson {
8 
9 //! (Depreciated) Wrapper of C file stream for input or output.
10 /*!
11  This simple wrapper does not check the validity of the stream.
12  \note implements Stream concept
13  \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.
14 */
15 class FileStream {
16 public:
17  typedef char Ch; //!< Character type. Only support char.
18 
19  FileStream(FILE* fp) : fp_(fp), current_('\0'), count_(0) { Read(); }
20  char Peek() const { return current_; }
21  char Take() { char c = current_; Read(); return c; }
22  size_t Tell() const { return count_; }
23  void Put(char c) { fputc(c, fp_); }
24  void Flush() { fflush(fp_); }
25 
26  // Not implemented
27  char* PutBegin() { return 0; }
28  size_t PutEnd(char*) { return 0; }
29 
30 private:
31  // Prohibit copy constructor & assignment operator.
32  FileStream(const FileStream&);
33  FileStream& operator=(const FileStream&);
34 
35  void Read() {
36  RAPIDJSON_ASSERT(fp_ != 0);
37  int c = fgetc(fp_);
38  if (c != EOF) {
39  current_ = (char)c;
40  count_++;
41  }
42  else if (current_ != '\0')
43  current_ = '\0';
44  }
45 
46  FILE* fp_;
47  char current_;
48  size_t count_;
49 };
50 
51 } // namespace rapidjson
52 
53 #endif // RAPIDJSON_FILESTREAM_H_
char Ch
Character type. Only support char.
Definition: filestream.h:17
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:146
common definitions and configuration
(Depreciated) Wrapper of C file stream for input or output.
Definition: filestream.h:15