filestream.h

Engine/source/persistence/rapidjson/filestream.h

More...

Classes:

class

(Depreciated) Wrapper of C file stream for input or output.

Namespaces:

namespace

main RapidJSON namespace

Detailed Description

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