All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
genericwritestream.h
1 #ifndef RAPIDJSON_GENERICWRITESTREAM_H_
2 #define RAPIDJSON_GENERICWRITESTREAM_H_
3 
4 #include "rapidjson.h"
5 #include <iostream>
6 
7 namespace rapidjson {
8 
9 //! Wrapper of std::ostream for output.
11 public:
12  typedef char Ch; //!< Character type. Only support char.
13 
14  //! Constructor
15  /*!
16  \param os Output stream.
17  */
18  GenericWriteStream(std::ostream& os) : os_(os) {
19  }
20 
21  void Put(char c) {
22  os_.put(c);
23  }
24 
25  void PutN(char c, size_t n) {
26  for (size_t i = 0; i < n; ++i) {
27  Put(c);
28  }
29  }
30 
31  void Flush() {
32  os_.flush();
33  }
34 
35  size_t Tell() const {
36  return (int)os_.tellp();
37  }
38 
39  // Not implemented
40  char Peek() const { RAPIDJSON_ASSERT(false); }
41  char Take() { RAPIDJSON_ASSERT(false); }
42  char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
43  size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
44 
45 private:
46  std::ostream& os_;
47 };
48 
49 template<>
50 inline void PutN(GenericWriteStream& stream, char c, size_t n) {
51  stream.PutN(c, n);
52 }
53 
54 } // namespace rapidjson
55 
56 #endif // RAPIDJSON_GENERICWRITESTREAM_H_