GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
procstream.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <iomanip>
31 
32 #include "procstream.h"
33 
34 procstreambase::procstreambase (const std::string& command, int mode)
35 {
36  pb_init ();
37 
38  if (! m_pb.open (command.c_str (), mode))
39  std::ios::setstate (std::ios::badbit);
40 }
41 
42 procstreambase::procstreambase (const char *command, int mode)
43 {
44  pb_init ();
45 
46  if (! m_pb.open (command, mode))
47  std::ios::setstate (std::ios::badbit);
48 }
49 
50 void
51 procstreambase::open (const char *command, int mode)
52 {
53  clear ();
54 
55  if (! m_pb.open (command, mode))
56  std::ios::setstate (std::ios::badbit);
57 }
58 
59 int
61 {
62  int status = 0;
63 
64  if (is_open ())
65  {
66  if (! m_pb.close ())
67  std::ios::setstate (std::ios::failbit);
68 
69  status = m_pb.wait_status ();
70  }
71 
72  return status;
73 }
octave_procbuf * close(void)
Definition: oct-procbuf.cc:183
octave_procbuf * open(const char *command, int mode)
Definition: oct-procbuf.cc:77
int wait_status(void) const
Definition: oct-procbuf.h:63
void open(const std::string &name, int mode)
Definition: procstream.h:52
void pb_init(void)
Definition: procstream.h:71
int close(void)
Definition: procstream.cc:60
int is_open(void) const
Definition: procstream.h:59
octave_procbuf m_pb
Definition: procstream.h:69
procstreambase(void)
Definition: procstream.h:44