Electroneum
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
 

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

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

Definition at line 50 of file istreamwrapper.h.

Constructor & Destructor Documentation

◆ BasicIStreamWrapper()

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

Definition at line 51 of file istreamwrapper.h.

51 : stream_(stream), count_(), peekBuffer_() {}

Member Function Documentation

◆ Flush()

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:411

◆ Peek()

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  }
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:468
StreamType::char_type Ch

◆ Peek4()

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:411
StreamType::char_type Ch

◆ Put()

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:411

◆ PutBegin()

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:411

◆ PutEnd()

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:411

◆ Take()

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  }
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition: rapidjson.h:468
StreamType::char_type Ch

◆ Tell()

template<typename StreamType>
size_t BasicIStreamWrapper< StreamType >::Tell ( ) const
inline

Definition at line 69 of file istreamwrapper.h.

69 { return count_; }

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