procstream.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1993-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_procstream_h)
00024 #define octave_procstream_h 1
00025 
00026 #include <iosfwd>
00027 #include <string>
00028 
00029 #include <sys/types.h>
00030 
00031 #include "oct-procbuf.h"
00032 
00033 class
00034 OCTINTERP_API
00035 procstreambase : virtual public std::ios
00036 {
00037 public:
00038 
00039   procstreambase (void) : pb () { pb_init (); }
00040 
00041   procstreambase (const std::string& name, int mode);
00042 
00043   procstreambase (const char *name, int mode);
00044 
00045   ~procstreambase (void) { close (); }
00046 
00047   void open (const std::string& name, int mode)
00048     { open (name.c_str (), mode); }
00049 
00050   void open (const char *name, int mode);
00051 
00052   int is_open (void) const { return pb.is_open (); }
00053 
00054   int close (void);
00055 
00056   pid_t pid (void) const { return pb.pid (); }
00057 
00058   int file_number (void) const { return pb.file_number (); }
00059 
00060 private:
00061 
00062   octave_procbuf pb;
00063 
00064   void pb_init (void) { init (&pb); }
00065 
00066   procstreambase (const procstreambase&);
00067 
00068   procstreambase& operator = (const procstreambase&);
00069 };
00070 
00071 class
00072 OCTINTERP_API
00073 iprocstream : public std::istream, public procstreambase
00074 // iprocstream : public procstreambase, public std::istream
00075 {
00076 public:
00077 
00078   iprocstream (void) : std::istream (0), procstreambase () { }
00079 
00080   iprocstream (const std::string& name, int mode = std::ios::in)
00081     : std::istream (0), procstreambase (name, mode) { }
00082 
00083   iprocstream (const char *name, int mode = std::ios::in)
00084     : std::istream (0), procstreambase (name, mode) { }
00085 
00086   ~iprocstream (void) { }
00087 
00088   void open (const std::string& name, int mode = std::ios::in)
00089     { procstreambase::open (name, mode); }
00090 
00091   void open (const char *name, int mode = std::ios::in)
00092     { procstreambase::open (name, mode); }
00093 
00094 private:
00095 
00096   iprocstream (const iprocstream&);
00097 
00098   iprocstream& operator = (const iprocstream&);
00099 };
00100 
00101 class
00102 OCTINTERP_API
00103 oprocstream : public std::ostream, public procstreambase
00104 // oprocstream : public procstreambase, public std::ostream
00105 {
00106 public:
00107 
00108   oprocstream (void) : std::ostream (0), procstreambase () { }
00109 
00110   oprocstream (const std::string& name, int mode = std::ios::out)
00111     : std::ostream (0), procstreambase(name, mode) { }
00112 
00113   oprocstream (const char *name, int mode = std::ios::out)
00114     : std::ostream (0), procstreambase(name, mode) { }
00115 
00116   ~oprocstream (void) { }
00117 
00118   void open (const std::string& name, int mode = std::ios::out)
00119     { procstreambase::open (name, mode); }
00120 
00121   void open (const char *name, int mode = std::ios::out)
00122     { procstreambase::open (name, mode); }
00123 
00124 private:
00125 
00126   oprocstream (const oprocstream&);
00127 
00128   oprocstream& operator = (const oprocstream&);
00129 };
00130 
00131 class
00132 OCTINTERP_API
00133 procstream : public std::iostream, public procstreambase
00134 // procstream : public procstreambase, public std::iostream
00135 {
00136 public:
00137 
00138   procstream (void) : std::iostream (0), procstreambase () { }
00139 
00140   procstream (const std::string& name, int mode)
00141     : std::iostream (0), procstreambase (name, mode) { }
00142 
00143   procstream (const char *name, int mode)
00144     : std::iostream (0), procstreambase (name, mode) { }
00145 
00146   ~procstream (void) { }
00147 
00148   void open (const std::string& name, int mode)
00149     { procstreambase::open (name, mode); }
00150 
00151   void open (const char *name, int mode)
00152     { procstreambase::open (name, mode); }
00153 
00154 private:
00155 
00156   procstream (const procstream&);
00157 
00158   procstream& operator = (const procstream&);
00159 };
00160 
00161 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines