Index: include/rapidjson/genericreadstream.h =================================================================== --- include/rapidjson/genericreadstream.h (revision 0) +++ include/rapidjson/genericreadstream.h (working copy) @@ -0,0 +1,44 @@ +#ifndef RAPIDJSON_GENERICREADSTREAM_H_ +#define RAPIDJSON_GENERICREADSTREAM_H_ + +#include "rapidjson.h" +#include + +namespace rapidjson { + +//! Wrapper of std::istream for input. +class GenericReadStream { +public: + typedef char Ch; //!< Character type (byte). + + //! Constructor. + /*! + \param is Input stream. + */ + GenericReadStream(std::istream& is) : is_(is) { + } + + Ch Peek() const { + return static_cast(is_.peek()); + } + + Ch Take() { + return static_cast(is_.get()); + } + + size_t Tell() const { + return (int)is_.tellg(); + } + + // Not implemented + void Put(Ch c) { RAPIDJSON_ASSERT(false); } + void Flush() { RAPIDJSON_ASSERT(false); } + Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } + + std::istream& is_; +}; + +} // namespace rapidjson + +#endif // RAPIDJSON_GENERICREADSTREAM_H_ Index: include/rapidjson/genericwritestream.h =================================================================== --- include/rapidjson/genericwritestream.h (revision 0) +++ include/rapidjson/genericwritestream.h (working copy) @@ -0,0 +1,56 @@ +#ifndef RAPIDJSON_GENERICWRITESTREAM_H_ +#define RAPIDJSON_GENERICWRITESTREAM_H_ + +#include "rapidjson.h" +#include + +namespace rapidjson { + +//! Wrapper of std::ostream for output. +class GenericWriteStream { +public: + typedef char Ch; //!< Character type. Only support char. + + //! Constructor + /*! + \param os Output stream. + */ + GenericWriteStream(std::ostream& os) : os_(os) { + } + + void Put(char c) { + os_.put(c); + } + + void PutN(char c, size_t n) { + for (size_t i = 0; i < n; ++i) { + Put(c); + } + } + + void Flush() { + os_.flush(); + } + + size_t Tell() const { + return (int)os_.tellp(); + } + + // Not implemented + char Peek() const { RAPIDJSON_ASSERT(false); } + char Take() { RAPIDJSON_ASSERT(false); } + char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } + size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } + +private: + std::ostream& os_; +}; + +template<> +inline void PutN(GenericWriteStream& stream, char c, size_t n) { + stream.PutN(c, n); +} + +} // namespace rapidjson + +#endif // RAPIDJSON_GENERICWRITESTREAM_H_