7 #ifndef _MIMETIC_MIMESTREAMBUF_H_
8 #define _MIMETIC_MIMESTREAMBUF_H_
11 #include <mimetic/libconfig.h>
12 #include <mimetic/strutils.h>
18 struct read_streambuf:
public std::streambuf
21 typedef unsigned int size_type;
23 : m_iBuf(new char_type[bufsz])
25 setg(m_iBuf, m_iBuf + bufsz, m_iBuf + bufsz);
27 virtual ~read_streambuf()
38 return traits_type::to_int_type(*gptr());
40 if((bread = read(eback(), bufsz)) == 0)
41 return traits_type::eof();
43 setg(eback(), eback(), eback() + bread);
45 return traits_type::to_int_type(*gptr());
48 virtual int_type read(
char*,
int) = 0;
50 read_streambuf(
const read_streambuf&);
51 read_streambuf& operator=(
const read_streambuf&);
56 template<
typename InputIt>
57 struct inputit_streambuf:
public read_streambuf
59 inputit_streambuf(InputIt beg, InputIt end)
60 : m_beg(beg), m_end(end)
64 int_type read(
char* buf,
int bufsz)
68 for(c = 0; m_beg != m_end && c < bufsz; ++m_beg, ++buf, ++c)
76 struct transform_streambuf:
public std::streambuf
78 typedef unsigned int size_type;
80 : m_oBuf(new char_type[512])
82 setp(m_oBuf, m_oBuf + 512);
84 virtual ~transform_streambuf()
92 int overflow(
int meta = EOF)
105 int toSend = pptr() - pbase();
108 write(pbase(), pbase() + toSend);
109 setp(m_oBuf, epptr());
113 virtual void write(
const char_type* beg,
const char_type* end)=0;
115 transform_streambuf(
const transform_streambuf&);
116 transform_streambuf& operator=(
const transform_streambuf&);
124 struct count_streambuf:
public transform_streambuf
130 void write(
const char_type* beg,
const char_type* end)
132 int toSend = end - beg;
151 template<
typename OutputIt>
152 struct passthrough_streambuf:
public transform_streambuf
154 typedef unsigned int size_type;
155 passthrough_streambuf(
const OutputIt& out)
156 : m_out(out), m_count(0)
159 void write(
const char_type* beg,
const char_type* end)
161 int toSend = end - beg;
165 copy(beg, end, m_out);
179 struct crlftolf_streambuf:
public transform_streambuf
181 typedef unsigned int size_type;
182 crlftolf_streambuf(std::streambuf* osbuf)
186 void write(
const char_type* beg,
const char_type* end)
188 enum { cr = 0xD, lf = 0xA };
191 for(; beg != end; ++beg)
213 std::streambuf* m_osbuf;