Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

rpstream.h

Go to the documentation of this file.
00001 /* $Id: rpstream.h,v 1.7 2002/10/22 01:30:27 redi Exp $
00002 PStreams - POSIX Process I/O for C++
00003 Copyright (C) 2001,2002 Jonathan Wakely
00004 
00005 This file is part of PStreams.
00006 
00007 PStreams is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU Lesser General Public License as
00009 published by the Free Software Foundation; either version 2.1 of
00010 the License, or (at your option) any later version.
00011 
00012 PStreams is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU Lesser General Public License for more details.
00016 
00017 You should have received a copy of the GNU Lesser General Public License
00018 along with PStreams; if not, write to the Free Software Foundation, Inc.,
00019 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00030 #ifndef REDI_RPSTREAM_H
00031 #define REDI_RPSTREAM_H
00032 
00033 #include "pstream.h"
00034 
00035 // Check the PStreams version.
00036 // #if PSTREAMS_VERSION < 0x0022
00037 // #error This version of rpstream.h is incompatible with your pstream.h
00038 // #error Please use pstream.h v0.34 or higher.
00039 // #endif
00040 
00041 
00042 // All PStreams classes are declared in namespace redi.
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   // TODO document RPSTREAMS better
00092 
00093   /*
00094    * member definitions for basic_rpstream
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_);  // calls shared std::basic_ios virtual base class
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 } // namespace redi
00217 
00218 #endif  // REDI_RPSTREAM_H
00219 

Generated on Mon Jul 5 10:39:10 2004 for PStreams by doxygen 1.3.2