IN2OSM  1.0.1
FileReadStream

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

#include <filereadstream.h>

Collaboration diagram for FileReadStream:
Collaboration graph

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

Definition at line 34 of file filereadstream.h.

Member Typedef Documentation

◆ Ch

typedef char Ch

Character type (byte).

Definition at line 36 of file filereadstream.h.

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.

Definition at line 44 of file filereadstream.h.

44  : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
45  RAPIDJSON_ASSERT(fp_ != 0);
46  RAPIDJSON_ASSERT(bufferSize >= 4);
47  Read();
48  }
size_t count_
Number of characters read.
std::FILE * fp_
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

Member Function Documentation

◆ Flush()

void Flush ( )
inline

Definition at line 56 of file filereadstream.h.

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

◆ Peek()

Ch Peek ( ) const
inline

Definition at line 50 of file filereadstream.h.

50 { return *current_; }

◆ Peek4()

const Ch* Peek4 ( ) const
inline

Definition at line 61 of file filereadstream.h.

61  {
62  return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0;
63  }

◆ Put()

void Put ( Ch  )
inline

Definition at line 55 of file filereadstream.h.

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

◆ PutBegin()

Ch* PutBegin ( )
inline

Definition at line 57 of file filereadstream.h.

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

◆ PutEnd()

size_t PutEnd ( Ch )
inline

Definition at line 58 of file filereadstream.h.

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

◆ Read()

void Read ( )
inlineprivate

Definition at line 66 of file filereadstream.h.

66  {
67  if (current_ < bufferLast_)
68  ++current_;
69  else if (!eof_) {
70  count_ += readCount_;
71  readCount_ = std::fread(buffer_, 1, bufferSize_, fp_);
73  current_ = buffer_;
74 
75  if (readCount_ < bufferSize_) {
76  buffer_[readCount_] = '\0';
77  ++bufferLast_;
78  eof_ = true;
79  }
80  }
81  }
size_t count_
Number of characters read.
std::FILE * fp_
Here is the caller graph for this function:

◆ Take()

Ch Take ( )
inline

Definition at line 51 of file filereadstream.h.

51 { Ch c = *current_; Read(); return c; }
char Ch
Character type (byte).
Here is the call graph for this function:

◆ Tell()

size_t Tell ( ) const
inline

Definition at line 52 of file filereadstream.h.

52 { return count_ + static_cast<size_t>(current_ - buffer_); }
size_t count_
Number of characters read.

Member Data Documentation

◆ buffer_

Ch* buffer_
private

Definition at line 84 of file filereadstream.h.

◆ bufferLast_

Ch* bufferLast_
private

Definition at line 86 of file filereadstream.h.

◆ bufferSize_

size_t bufferSize_
private

Definition at line 85 of file filereadstream.h.

◆ count_

size_t count_
private

Number of characters read.

Definition at line 89 of file filereadstream.h.

◆ current_

Ch* current_
private

Definition at line 87 of file filereadstream.h.

◆ eof_

bool eof_
private

Definition at line 90 of file filereadstream.h.

◆ fp_

std::FILE* fp_
private

Definition at line 83 of file filereadstream.h.

◆ readCount_

size_t readCount_
private

Definition at line 88 of file filereadstream.h.


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