TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FileReadStream Class Reference

File byte stream for input using fread(). More...

#include <filereadstream.h>

Public Types

typedef char Ch
 Character type (byte). More...
 

Public Member Functions

 FileReadStream (std::FILE *fp, char *buffer, size_t bufferSize)
 Constructor. More...
 
Ch Peek () const
 
Ch Take ()
 
size_t Tell () const
 
void Put (Ch)
 
void Flush ()
 
ChPutBegin ()
 
size_t PutEnd (Ch *)
 
const ChPeek4 () const
 

Private Member Functions

void Read ()
 

Private Attributes

std::FILE * fp_
 
Chbuffer_
 
size_t bufferSize_
 
ChbufferLast_
 
Chcurrent_
 
size_t readCount_
 
size_t count_
 Number of characters read. More...
 
bool eof_
 

Detailed Description

File byte stream for input using fread().

Note
implements Stream concept

Member Typedef Documentation

typedef char FileReadStream::Ch

Character type (byte).

Constructor & Destructor Documentation

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

Constructor.

Parameters
fpFile pointer opened for read.
bufferuser-supplied buffer.
bufferSizesize of buffer in bytes. Must >=4 bytes.
37  : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
38  RAPIDJSON_ASSERT(fp_ != 0);
40  Read();
41  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
const size_t bufferSize
Definition: RASession.h:31
size_t count_
Number of characters read.
Definition: filereadstream.h:82
Ch * buffer_
Definition: filereadstream.h:77
bool eof_
Definition: filereadstream.h:83
Ch * bufferLast_
Definition: filereadstream.h:79
size_t bufferSize_
Definition: filereadstream.h:78
std::FILE * fp_
Definition: filereadstream.h:76
void Read()
Definition: filereadstream.h:59
size_t readCount_
Definition: filereadstream.h:81
Ch * current_
Definition: filereadstream.h:80

+ Here is the call graph for this function:

Member Function Documentation

void FileReadStream::Flush ( )
inline
49 { RAPIDJSON_ASSERT(false); }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
Ch FileReadStream::Peek ( ) const
inline
43 { return *current_; }
Ch * current_
Definition: filereadstream.h:80
const Ch* FileReadStream::Peek4 ( ) const
inline
54  {
55  return (current_ + 4 <= bufferLast_) ? current_ : 0;
56  }
Ch * bufferLast_
Definition: filereadstream.h:79
Ch * current_
Definition: filereadstream.h:80
void FileReadStream::Put ( Ch  )
inline
48 { RAPIDJSON_ASSERT(false); }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
Ch* FileReadStream::PutBegin ( )
inline
50 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
size_t FileReadStream::PutEnd ( Ch )
inline
51 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344
void FileReadStream::Read ( )
inlineprivate
59  {
60  if (current_ < bufferLast_)
61  ++current_;
62  else if (!eof_) {
63  count_ += readCount_;
64  readCount_ = fread(buffer_, 1, bufferSize_, fp_);
66  current_ = buffer_;
67 
68  if (readCount_ < bufferSize_) {
69  buffer_[readCount_] = '\0';
70  ++bufferLast_;
71  eof_ = true;
72  }
73  }
74  }
size_t count_
Number of characters read.
Definition: filereadstream.h:82
Ch * buffer_
Definition: filereadstream.h:77
bool eof_
Definition: filereadstream.h:83
Ch * bufferLast_
Definition: filereadstream.h:79
size_t bufferSize_
Definition: filereadstream.h:78
std::FILE * fp_
Definition: filereadstream.h:76
size_t readCount_
Definition: filereadstream.h:81
Ch * current_
Definition: filereadstream.h:80

+ Here is the caller graph for this function:

Ch FileReadStream::Take ( )
inline
44 { Ch c = *current_; Read(); return c; }
char Ch
Character type (byte).
Definition: filereadstream.h:29
void Read()
Definition: filereadstream.h:59
Ch * current_
Definition: filereadstream.h:80

+ Here is the call graph for this function:

size_t FileReadStream::Tell ( ) const
inline
45 { return count_ + static_cast<size_t>(current_ - buffer_); }
size_t count_
Number of characters read.
Definition: filereadstream.h:82
Ch * buffer_
Definition: filereadstream.h:77
Ch * current_
Definition: filereadstream.h:80

Member Data Documentation

Ch* FileReadStream::buffer_
private
Ch* FileReadStream::bufferLast_
private
size_t FileReadStream::bufferSize_
private
size_t FileReadStream::count_
private

Number of characters read.

Ch* FileReadStream::current_
private
bool FileReadStream::eof_
private
std::FILE* FileReadStream::fp_
private
size_t FileReadStream::readCount_
private

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