IN2OSM  1.0.1
BasicIStreamWrapper< StreamType >

Wrapper of std::basic_istream into RapidJSON's Stream concept. More...

#include <istreamwrapper.h>

Collaboration diagram for BasicIStreamWrapper< StreamType >:
Collaboration graph

Public Types

typedef StreamType::char_type Ch
 

Public Member Functions

 BasicIStreamWrapper (StreamType &stream)
 Constructor. More...
 
 BasicIStreamWrapper (StreamType &stream, 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

 BasicIStreamWrapper ()
 
 BasicIStreamWrapper (const BasicIStreamWrapper &)
 
BasicIStreamWrapperoperator= (const BasicIStreamWrapper &)
 
void Read ()
 

Private Attributes

StreamType & stream_
 
Ch peekBuffer_ [4]
 
Chbuffer_
 
size_t bufferSize_
 
ChbufferLast_
 
Chcurrent_
 
size_t readCount_
 
size_t count_
 Number of characters read. More...
 
bool eof_
 

Detailed Description

template<typename StreamType>
class BasicIStreamWrapper< StreamType >

Wrapper of std::basic_istream into RapidJSON's Stream concept.

The classes can be wrapped including but not limited to:

  • std::istringstream
  • std::stringstream
  • std::wistringstream
  • std::wstringstream
  • std::ifstream
  • std::fstream
  • std::wifstream
  • std::wfstream
Template Parameters
StreamTypeClass derived from std::basic_istream.

Definition at line 48 of file istreamwrapper.h.

Member Typedef Documentation

◆ Ch

typedef StreamType::char_type Ch

Definition at line 50 of file istreamwrapper.h.

Constructor & Destructor Documentation

◆ BasicIStreamWrapper() [1/4]

BasicIStreamWrapper ( StreamType &  stream)
inline

Constructor.

Parameters
streamstream opened for read.

Definition at line 56 of file istreamwrapper.h.

Here is the call graph for this function:

◆ BasicIStreamWrapper() [2/4]

BasicIStreamWrapper ( StreamType &  stream,
char *  buffer,
size_t  bufferSize 
)
inline

Constructor.

Parameters
streamstream opened for read.
bufferuser-supplied buffer.
bufferSizesize of buffer in bytes. Must >=4 bytes.

Definition at line 66 of file istreamwrapper.h.

66  : stream_(stream), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
67  RAPIDJSON_ASSERT(bufferSize >= 4);
68  Read();
69  }
StreamType & stream_
size_t count_
Number of characters read.
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

◆ BasicIStreamWrapper() [3/4]

BasicIStreamWrapper ( )
private
Here is the caller graph for this function:

◆ BasicIStreamWrapper() [4/4]

BasicIStreamWrapper ( const BasicIStreamWrapper< StreamType > &  )
private

Member Function Documentation

◆ Flush()

void Flush ( )
inline

Definition at line 77 of file istreamwrapper.h.

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

◆ operator=()

BasicIStreamWrapper& operator= ( const BasicIStreamWrapper< StreamType > &  )
private
Here is the caller graph for this function:

◆ Peek()

Ch Peek ( ) const
inline

Definition at line 71 of file istreamwrapper.h.

71 { return *current_; }

◆ Peek4()

const Ch* Peek4 ( ) const
inline

Definition at line 82 of file istreamwrapper.h.

82  {
83  return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0;
84  }
Here is the call graph for this function:

◆ Put()

void Put ( Ch  )
inline

Definition at line 76 of file istreamwrapper.h.

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

◆ PutBegin()

Ch* PutBegin ( )
inline

Definition at line 78 of file istreamwrapper.h.

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

◆ PutEnd()

size_t PutEnd ( Ch )
inline

Definition at line 79 of file istreamwrapper.h.

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

◆ Read()

void Read ( )
inlineprivate

Definition at line 91 of file istreamwrapper.h.

91  {
92  if (current_ < bufferLast_)
93  ++current_;
94  else if (!eof_) {
95  count_ += readCount_;
98  current_ = buffer_;
99 
100  if (!stream_.read(buffer_, static_cast<std::streamsize>(bufferSize_))) {
101  readCount_ = static_cast<size_t>(stream_.gcount());
102  *(bufferLast_ = buffer_ + readCount_) = '\0';
103  eof_ = true;
104  }
105  }
106  }
StreamType & stream_
size_t count_
Number of characters read.
Here is the caller graph for this function:

◆ Take()

Ch Take ( )
inline

Definition at line 72 of file istreamwrapper.h.

72 { Ch c = *current_; Read(); return c; }
StreamType::char_type Ch
Here is the call graph for this function:

◆ Tell()

size_t Tell ( ) const
inline

Definition at line 73 of file istreamwrapper.h.

73 { 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 109 of file istreamwrapper.h.

◆ bufferLast_

Ch* bufferLast_
private

Definition at line 111 of file istreamwrapper.h.

◆ bufferSize_

size_t bufferSize_
private

Definition at line 110 of file istreamwrapper.h.

◆ count_

size_t count_
private

Number of characters read.

Definition at line 114 of file istreamwrapper.h.

◆ current_

Ch* current_
private

Definition at line 112 of file istreamwrapper.h.

◆ eof_

bool eof_
private

Definition at line 115 of file istreamwrapper.h.

◆ peekBuffer_

Ch peekBuffer_[4]
private

Definition at line 109 of file istreamwrapper.h.

◆ readCount_

size_t readCount_
private

Definition at line 113 of file istreamwrapper.h.

◆ stream_

StreamType& stream_
private

Definition at line 108 of file istreamwrapper.h.


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