Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 

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 *)
 

Private Member Functions

 FileWriteStream (const FileWriteStream &)
 
FileWriteStreamoperator= (const FileWriteStream &)
 

Private Attributes

std::FILE * fp_
 
char * buffer_
 
char * bufferEnd_
 
char * current_
 

Detailed Description

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

Note
implements Stream concept

Definition at line 32 of file filewritestream.h.

Member Typedef Documentation

typedef char FileWriteStream::Ch

Character type. Only support char.

Definition at line 34 of file filewritestream.h.

Constructor & Destructor Documentation

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
std::FILE * fp_
FileWriteStream::FileWriteStream ( const FileWriteStream )
private

Member Function Documentation

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  }
static QCString result
std::FILE * fp_
FileWriteStream& FileWriteStream::operator= ( const FileWriteStream )
private
char FileWriteStream::Peek ( ) const
inline

Definition at line 75 of file filewritestream.h.

75 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
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  }
char* FileWriteStream::PutBegin ( )
inline

Definition at line 78 of file filewritestream.h.

78 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
size_t FileWriteStream::PutEnd ( char *  )
inline

Definition at line 79 of file filewritestream.h.

79 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
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  }
std::void_t< T > n
char FileWriteStream::Take ( )
inline

Definition at line 76 of file filewritestream.h.

76 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
size_t FileWriteStream::Tell ( ) const
inline

Definition at line 77 of file filewritestream.h.

77 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406

Member Data Documentation

char* FileWriteStream::buffer_
private

Definition at line 87 of file filewritestream.h.

char* FileWriteStream::bufferEnd_
private

Definition at line 88 of file filewritestream.h.

char* FileWriteStream::current_
private

Definition at line 89 of file filewritestream.h.

std::FILE* FileWriteStream::fp_
private

Definition at line 86 of file filewritestream.h.


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