00001 #ifndef __fdstream_h__ 00002 #define __fdstream_h__ 00003 00004 #include <iostream> 00005 #ifdef HAVE_STREAMBUF 00006 #include <streambuf> 00007 #endif 00008 #include <cstdio> 00009 00010 class fdoutbuf : public std::streambuf 00011 { 00012 public: 00013 fdoutbuf(); 00014 fdoutbuf(int a_fd); 00015 void attach(int a_fd); 00016 virtual int overflow(int a_c); 00017 virtual std::streamsize xsputn(const char* a_s, std::streamsize a_num); 00018 00019 protected: 00020 int m_fd; 00021 }; 00022 00023 class ofdstream : public std::ostream 00024 { 00025 public: 00026 ofdstream(); 00027 ofdstream(int a_fd); 00028 void attach(int a_fd); 00029 int fd(void); 00030 00031 protected: 00032 fdoutbuf m_buf; 00033 int m_fd; 00034 }; 00035 00036 class fdinbuf : public std::streambuf 00037 { 00038 public: 00039 fdinbuf(); 00040 fdinbuf(int a_fd); 00041 void attach(int a_fd); 00042 virtual int underflow(void); 00043 00044 protected: 00045 int m_fd; 00046 static const int m_buffer_size = 10; 00047 char m_buffer[m_buffer_size]; 00048 }; 00049 00050 class ifdstream : public std::istream 00051 { 00052 public: 00053 ifdstream(); 00054 ifdstream(int a_fd); 00055 void attach(int a_fd); 00056 int fd(void); 00057 00058 protected: 00059 fdinbuf m_buf; 00060 int m_fd; 00061 }; 00062 00063 #endif