00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030 #ifndef REDI_RPSTREAM_H
00031 #define REDI_RPSTREAM_H
00032
00033 #include "pstream.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 namespace redi
00044 {
00046 template <typename CharT, typename Traits = std::char_traits<CharT> >
00047 class basic_rpstream
00048 : public std::basic_ostream<CharT, Traits>
00049 , private std::basic_istream<CharT, Traits>
00050 , private pstream_common<CharT, Traits>
00051 {
00052 typedef std::basic_ostream<CharT, Traits> ostream_type;
00053 typedef std::basic_istream<CharT, Traits> istream_type;
00054 typedef pstream_common<CharT, Traits> pbase_type;
00055 typedef typename pbase_type::pmode pmode;
00056
00057 public:
00059 basic_rpstream();
00060
00062 basic_rpstream(const std::string& command, pmode mode = std::ios_base::in|std::ios_base::out);
00063
00065 basic_rpstream(const std::string& file, const std::vector<std::string>& argv, pmode mode = std::ios_base::in|std::ios_base::out);
00066
00068 ~basic_rpstream() { }
00069
00071 void
00072 open(const std::string& command, pmode mode = std::ios_base::in|std::ios_base::out);
00073
00075 void
00076 open(const std::string& file, const std::vector<std::string>& argv, pmode mode = std::ios_base::in|std::ios_base::out);
00077
00079 istream_type&
00080 out();
00081
00083 istream_type&
00084 err();
00085 };
00086
00088 typedef basic_rpstream<char> rpstream;
00089
00090
00091
00092
00093
00094
00095
00096
00119 template <typename C, typename T>
00120 basic_rpstream<C,T>::basic_rpstream()
00121 : ostream_type(NULL)
00122 , istream_type(NULL)
00123 , pbase_type()
00124 {
00125 this->init(&buf_);
00126 }
00127
00136 template <typename C, typename T>
00137 basic_rpstream<C,T>::basic_rpstream(const std::string& command, pmode mode)
00138 : ostream_type(NULL)
00139 , istream_type(NULL)
00140 , pbase_type(command, mode)
00141 {
00142 this->init(&buf_);
00143 }
00144
00154 template <typename C, typename T>
00155 inline
00156 basic_rpstream<C,T>::basic_rpstream(const std::string& file, const std::vector<std::string>& argv, pmode mode)
00157 : ostream_type(NULL)
00158 , istream_type(NULL)
00159 , pbase_type(file, argv, mode)
00160 {
00161 this->init(&buf_);
00162 }
00163
00171 template <typename C, typename T>
00172 inline void
00173 basic_rpstream<C,T>::open(const std::string& command, pmode mode)
00174 {
00175 pbase_type::open(command, mode);
00176 }
00177
00187 template <typename C, typename T>
00188 inline void
00189 basic_rpstream<C,T>::open(const std::string& file, const std::vector<std::string>& argv, pmode mode)
00190 {
00191 pbase_type::open(file, argv, mode);
00192 }
00193
00197 template <typename C, typename T>
00198 inline typename basic_rpstream<C,T>::istream_type&
00199 basic_rpstream<C,T>::out()
00200 {
00201 buf_.read_err(false);
00202 return *this;
00203 }
00204
00208 template <typename C, typename T>
00209 inline typename basic_rpstream<C,T>::istream_type&
00210 basic_rpstream<C,T>::err()
00211 {
00212 buf_.read_err(true);
00213 return *this;
00214 }
00215
00216 }
00217
00218 #endif // REDI_RPSTREAM_H
00219