Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
FileWriteStream Class Reference

Wrapper of C file stream for output using fwrite(). More...

#include <filewritestream.h>

Public Types

typedef char Ch
 Character type. Only support char.
 

Public Member Functions

 FileWriteStream (std::FILE *fp, char *buffer, size_t bufferSize)
 
void Put (char c)
 
void PutN (char c, size_t n)
 
void Flush ()
 
char Peek () const
 
char Take ()
 
size_t Tell () const
 
char * PutBegin ()
 
size_t PutEnd (char *)
 

Detailed Description

Note
implements Stream concept

Definition at line 32 of file filewritestream.h.

Member Typedef Documentation

◆ Ch

Definition at line 34 of file filewritestream.h.

Constructor & Destructor Documentation

◆ FileWriteStream()

FileWriteStream::FileWriteStream ( std::FILE * fp,
char * buffer,
size_t bufferSize )
inline

Definition at line 36 of file filewritestream.h.

36 : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
37 RAPIDJSON_ASSERT(fp_ != 0);
38 }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:406

Member Function Documentation

◆ Flush()

void FileWriteStream::Flush ( )
inline

Definition at line 63 of file filewritestream.h.

63 {
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_)) {
67 // failure deliberately ignored at this time
68 // added to avoid warn_unused_result build errors
69 }
70 current_ = buffer_;
71 }
72 }
Here is the caller graph for this function:

◆ Peek()

char FileWriteStream::Peek ( ) const
inline

Definition at line 75 of file filewritestream.h.

75{ RAPIDJSON_ASSERT(false); return 0; }

◆ Put()

void FileWriteStream::Put ( char c)
inline

Definition at line 40 of file filewritestream.h.

40 {
41 if (current_ >= bufferEnd_)
42 Flush();
43
44 *current_++ = c;
45 }
Here is the call graph for this function:

◆ PutBegin()

char * FileWriteStream::PutBegin ( )
inline

Definition at line 78 of file filewritestream.h.

78{ RAPIDJSON_ASSERT(false); return 0; }

◆ PutEnd()

size_t FileWriteStream::PutEnd ( char * )
inline

Definition at line 79 of file filewritestream.h.

79{ RAPIDJSON_ASSERT(false); return 0; }

◆ PutN()

void FileWriteStream::PutN ( char c,
size_t n )
inline

Definition at line 47 of file filewritestream.h.

47 {
48 size_t avail = static_cast<size_t>(bufferEnd_ - current_);
49 while (n > avail) {
50 std::memset(current_, c, avail);
51 current_ += avail;
52 Flush();
53 n -= avail;
54 avail = static_cast<size_t>(bufferEnd_ - current_);
55 }
56
57 if (n > 0) {
58 std::memset(current_, c, n);
59 current_ += n;
60 }
61 }
Here is the call graph for this function:

◆ Take()

char FileWriteStream::Take ( )
inline

Definition at line 76 of file filewritestream.h.

76{ RAPIDJSON_ASSERT(false); return 0; }

◆ Tell()

size_t FileWriteStream::Tell ( ) const
inline

Definition at line 77 of file filewritestream.h.

77{ RAPIDJSON_ASSERT(false); return 0; }

The documentation for this class was generated from the following file: