1 /***************************************************************************
2 inpipestream.hxx - C++ streambuffer wrapper
4 begin : Thu Dec 27 2001
5 copyright : (C) 2001 by Intra2net AG
6 email : intranator@intra2net.com
7 ***************************************************************************/
16 #include "exception.hxx"
18 // ATTENTION: A lot of mysterious STL bugs occured
19 // with a "real" buffer (buffer larger than 1 byte and up to 100 bytes)
20 // -> Keep it slow and working!
22 class inpipebuf : public std::streambuf
29 inpipebuf(const std::string& command)
31 pipe = popen (command.c_str(), "r");
33 throw EXCEPTION (pipestream_error, "can't open program or permission denied");
36 setg (&buffer, &buffer, &buffer);
48 virtual int_type underflow()
51 return traits_type::to_int_type(*gptr());
53 buffer = fgetc (pipe);
60 setg (&buffer, &buffer, &buffer+sizeof(char));
62 return traits_type::to_int_type(*gptr());
66 class inpipestream : public std::istream
71 inpipestream(const std::string& command)
72 : buf(command), std::istream(&buf)
76 class outpipebuf : public std::streambuf
82 outpipebuf(const std::string& command)
84 pipe = popen (command.c_str(), "w");
86 throw EXCEPTION (pipestream_error, "can't open program or permission denied");
98 virtual int_type overflow(int_type c)
102 if (fputc(c,pipe)==EOF)
108 virtual std::streamsize xsputn(const char* s, std::streamsize num)
110 return fwrite(s,num,1,pipe);
114 class outpipestream : public std::ostream
119 outpipestream(const std::string& command)
120 : buf(command), std::ostream(&buf)