Welcome to mirror list, hosted at ThFree Co, Russian Federation.

filestream.h « rapidjson « include - github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0099d580ed6918b8db6be0068fc0950018aabaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef RAPIDJSON_FILESTREAM_H_
#define RAPIDJSON_FILESTREAM_H_

#include "rapidjson.h"
#include <cstdio>

namespace rapidjson {

//! (Depreciated) Wrapper of C file stream for input or output.
/*!
	This simple wrapper does not check the validity of the stream.
	\note implements Stream concept
	\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(FILE* fp) : fp_(fp), 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:
	void Read() {
		RAPIDJSON_ASSERT(fp_ != 0);
		int c = fgetc(fp_);
		if (c != EOF) {
			current_ = (char)c;
			count_++;
		}
		else if (current_ != '\0')
			current_ = '\0';
	}

	FILE* fp_;
	char current_;
	size_t count_;
};

} // namespace rapidjson

#endif // RAPIDJSON_FILESTREAM_H_