procstream.cc

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 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <iostream>
00028 
00029 #include "procstream.h"
00030 
00031 procstreambase::procstreambase (const std::string& command, int mode)
00032 {
00033   pb_init ();
00034 
00035   if (! pb.open (command.c_str (), mode))
00036     std::ios::setstate (std::ios::badbit);
00037 }
00038 
00039 procstreambase::procstreambase (const char *command, int mode)
00040 {
00041   pb_init ();
00042 
00043   if (! pb.open (command, mode))
00044     std::ios::setstate (std::ios::badbit);
00045 }
00046 
00047 void
00048 procstreambase::open (const char *command, int mode)
00049 {
00050   clear ();
00051 
00052   if (! pb.open (command, mode))
00053     std::ios::setstate (std::ios::badbit);
00054 }
00055 
00056 int
00057 procstreambase::close (void)
00058 {
00059   int status = 0;
00060 
00061   if (is_open ())
00062     {
00063       if (! pb.close ())
00064         std::ios::setstate (std::ios::failbit);
00065 
00066       status = pb.wait_status ();
00067     }
00068 
00069   return status;
00070 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines