Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
BasicIStreamWrapper< StreamType > Class Template Reference

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

#include <istreamwrapper.h>

Public Types

typedef StreamType::char_type Ch
 

Public Member Functions

 BasicIStreamWrapper (StreamType &stream)
 
Ch Peek () const
 
Ch Take ()
 
size_t Tell () const
 
ChPutBegin ()
 
void Put (Ch)
 
void Flush ()
 
size_t PutEnd (Ch *)
 
const ChPeek4 () const
 

Private Member Functions

 BasicIStreamWrapper (const BasicIStreamWrapper &)
 
BasicIStreamWrapperoperator= (const BasicIStreamWrapper &)
 

Private Attributes

StreamType & stream_
 
size_t count_
 Number of characters read. Note: More...
 
Ch peekBuffer_ [4]
 

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:

Template Parameters
StreamTypeClass derived from std::basic_istream.

Definition at line 48 of file istreamwrapper.h.

Member Typedef Documentation

template<typename StreamType >
typedef StreamType::char_type BasicIStreamWrapper< StreamType >::Ch

Definition at line 50 of file istreamwrapper.h.

Constructor & Destructor Documentation

template<typename StreamType >
BasicIStreamWrapper< StreamType >::BasicIStreamWrapper ( StreamType &  stream)
inline

Definition at line 51 of file istreamwrapper.h.

51 : stream_(stream), count_(), peekBuffer_() {}
size_t count_
Number of characters read. Note:
StreamType & stream_
template<typename StreamType >
BasicIStreamWrapper< StreamType >::BasicIStreamWrapper ( const BasicIStreamWrapper< StreamType > &  )
private

Member Function Documentation

template<typename StreamType >
void BasicIStreamWrapper< StreamType >::Flush ( )
inline

Definition at line 73 of file istreamwrapper.h.

73 { RAPIDJSON_ASSERT(false); }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
template<typename StreamType >
BasicIStreamWrapper& BasicIStreamWrapper< StreamType >::operator= ( const BasicIStreamWrapper< StreamType > &  )
private
template<typename StreamType >
Ch BasicIStreamWrapper< StreamType >::Peek ( ) const
inline

Definition at line 53 of file istreamwrapper.h.

53  {
54  typename StreamType::int_type c = stream_.peek();
55  return RAPIDJSON_LIKELY(c != StreamType::traits_type::eof()) ? static_cast<Ch>(c) : static_cast<Ch>('\0');
56  }
StreamType & stream_
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:463
StreamType::char_type Ch
template<typename StreamType >
const Ch* BasicIStreamWrapper< StreamType >::Peek4 ( ) const
inline

Definition at line 77 of file istreamwrapper.h.

77  {
78  RAPIDJSON_ASSERT(sizeof(Ch) == 1); // Only usable for byte stream.
79  int i;
80  bool hasError = false;
81  for (i = 0; i < 4; ++i) {
82  typename StreamType::int_type c = stream_.get();
83  if (c == StreamType::traits_type::eof()) {
84  hasError = true;
85  stream_.clear();
86  break;
87  }
88  peekBuffer_[i] = static_cast<Ch>(c);
89  }
90  for (--i; i >= 0; --i)
91  stream_.putback(peekBuffer_[i]);
92  return !hasError ? peekBuffer_ : 0;
93  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
StreamType & stream_
StreamType::char_type Ch
template<typename StreamType >
void BasicIStreamWrapper< StreamType >::Put ( Ch  )
inline

Definition at line 72 of file istreamwrapper.h.

72 { RAPIDJSON_ASSERT(false); }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
template<typename StreamType >
Ch* BasicIStreamWrapper< StreamType >::PutBegin ( )
inline

Definition at line 71 of file istreamwrapper.h.

71 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
template<typename StreamType >
size_t BasicIStreamWrapper< StreamType >::PutEnd ( Ch )
inline

Definition at line 74 of file istreamwrapper.h.

74 { RAPIDJSON_ASSERT(false); return 0; }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
template<typename StreamType >
Ch BasicIStreamWrapper< StreamType >::Take ( )
inline

Definition at line 58 of file istreamwrapper.h.

58  {
59  typename StreamType::int_type c = stream_.get();
60  if (RAPIDJSON_LIKELY(c != StreamType::traits_type::eof())) {
61  count_++;
62  return static_cast<Ch>(c);
63  }
64  else
65  return '\0';
66  }
size_t count_
Number of characters read. Note:
StreamType & stream_
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:463
StreamType::char_type Ch
template<typename StreamType >
size_t BasicIStreamWrapper< StreamType >::Tell ( ) const
inline

Definition at line 69 of file istreamwrapper.h.

69 { return count_; }
size_t count_
Number of characters read. Note:

Member Data Documentation

template<typename StreamType >
size_t BasicIStreamWrapper< StreamType >::count_
private

Number of characters read. Note:

Definition at line 100 of file istreamwrapper.h.

template<typename StreamType >
Ch BasicIStreamWrapper< StreamType >::peekBuffer_[4]
mutableprivate

Definition at line 101 of file istreamwrapper.h.

template<typename StreamType >
StreamType& BasicIStreamWrapper< StreamType >::stream_
private

Definition at line 99 of file istreamwrapper.h.


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