15#ifndef RAPIDJSON_FILEWRITESTREAM_H_
16#define RAPIDJSON_FILEWRITESTREAM_H_
23RAPIDJSON_DIAG_OFF(unreachable-code)
36 FileWriteStream(std::FILE* fp,
char* buffer,
size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
41 if (current_ >= bufferEnd_)
47 void PutN(
char c,
size_t n) {
48 size_t avail =
static_cast<size_t>(bufferEnd_ - current_);
50 std::memset(current_, c, avail);
54 avail =
static_cast<size_t>(bufferEnd_ - current_);
58 std::memset(current_, c, n);
64 if (current_ != buffer_) {
65 size_t result = std::fwrite(buffer_, 1,
static_cast<size_t>(current_ - buffer_), fp_);
66 if (result <
static_cast<size_t>(current_ - buffer_)) {
Wrapper of C file stream for output using fwrite().
char Ch
Character type. Only support char.
FileWriteStream(std::FILE *fp, char *buffer, size_t bufferSize)
void PutN(char c, size_t n)
void PutN(FileWriteStream &stream, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)