GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
procstream.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2024 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 (octave_procstream_h)
27 #define octave_procstream_h 1
28 
29 #include "octave-config.h"
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include <sys/types.h>
35 
36 #include "oct-procbuf.h"
37 
39 
40 class
41 OCTINTERP_API
42 procstreambase : virtual public std::ios
43 {
44 public:
45 
46  procstreambase () : m_pb () { pb_init (); }
47 
48  procstreambase (const std::string& name, int mode);
49 
50  procstreambase (const char *name, int mode);
51 
52  OCTAVE_DISABLE_COPY_MOVE (procstreambase)
53 
54  ~procstreambase () { close (); }
55 
56  void open (const std::string& name, int mode)
57  {
58  open (name.c_str (), mode);
59  }
60 
61  void open (const char *name, int mode);
62 
63  int is_open () const { return m_pb.is_open (); }
64 
65  int close ();
66 
67  pid_t pid () const { return m_pb.pid (); }
68 
69  int file_number () const { return m_pb.file_number (); }
70 
71 private:
72 
73  procbuf m_pb;
74 
75  void pb_init ()
76  {
77  // Explicit initialization of the std::ios object is needed.
78  // FIXME: is there a better way to organize these classes?
79  init (&m_pb);
80  }
81 };
82 
83 class
84 OCTINTERP_API
85 iprocstream : public std::istream, public procstreambase
86 {
87 public:
88 
89  iprocstream () : std::istream (nullptr), procstreambase () { }
90 
91  iprocstream (const std::string& name, int mode = std::ios::in)
92  : std::istream (nullptr), procstreambase (name, mode)
93  { }
94 
95  iprocstream (const char *name, int mode = std::ios::in)
96  : std::istream (nullptr), procstreambase (name, mode)
97  { }
98 
99  OCTAVE_DISABLE_COPY_MOVE (iprocstream)
100 
101  ~iprocstream () = default;
102 
103  void open (const std::string& name, int mode = std::ios::in)
104  {
105  procstreambase::open (name, mode);
106  }
107 
108  void open (const char *name, int mode = std::ios::in)
109  {
110  procstreambase::open (name, mode);
111  }
112 };
113 
114 class
115 OCTINTERP_API
116 oprocstream : public std::ostream, public procstreambase
117 {
118 public:
119 
120  oprocstream () : std::ostream (nullptr), procstreambase () { }
121 
122  oprocstream (const std::string& name, int mode = std::ios::out)
123  : std::ostream (nullptr), procstreambase (name, mode) { }
124 
125  oprocstream (const char *name, int mode = std::ios::out)
126  : std::ostream (nullptr), procstreambase (name, mode) { }
127 
128  OCTAVE_DISABLE_COPY_MOVE (oprocstream)
129 
130  ~oprocstream () = default;
131 
132  void open (const std::string& name, int mode = std::ios::out)
133  {
134  procstreambase::open (name, mode);
135  }
136 
137  void open (const char *name, int mode = std::ios::out)
138  {
139  procstreambase::open (name, mode);
140  }
141 };
142 
143 class
144 OCTINTERP_API
145 procstream : public std::iostream, public procstreambase
146 {
147 public:
148 
149  procstream () : std::iostream (nullptr), procstreambase () { }
150 
151  procstream (const std::string& name, int mode)
152  : std::iostream (nullptr), procstreambase (name, mode)
153  { }
154 
155  procstream (const char *name, int mode)
156  : std::iostream (nullptr), procstreambase (name, mode)
157  { }
158 
159  OCTAVE_DISABLE_COPY_MOVE (procstream)
160 
161  ~procstream () = default;
162 
163  void open (const std::string& name, int mode)
164  {
165  procstreambase::open (name, mode);
166  }
167 
168  void open (const char *name, int mode)
169  {
170  procstreambase::open (name, mode);
171  }
172 };
173 
174 OCTAVE_END_NAMESPACE(octave)
175 
176 #endif
void open(const std::string &name, int mode=std::ios::in)
Definition: procstream.h:103
~iprocstream()=default
iprocstream(const std::string &name, int mode=std::ios::in)
Definition: procstream.h:91
iprocstream(const char *name, int mode=std::ios::in)
Definition: procstream.h:95
void open(const char *name, int mode=std::ios::in)
Definition: procstream.h:108
oprocstream(const std::string &name, int mode=std::ios::out)
Definition: procstream.h:122
oprocstream(const char *name, int mode=std::ios::out)
Definition: procstream.h:125
void open(const char *name, int mode=std::ios::out)
Definition: procstream.h:137
void open(const std::string &name, int mode=std::ios::out)
Definition: procstream.h:132
~oprocstream()=default
procstream(const char *name, int mode)
Definition: procstream.h:155
procstream(const std::string &name, int mode)
Definition: procstream.h:151
~procstream()=default
void open(const char *name, int mode)
Definition: procstream.h:168
void open(const std::string &name, int mode)
Definition: procstream.h:163
void open(const std::string &name, int mode)
Definition: procstream.h:56
int is_open() const
Definition: procstream.h:63
int file_number() const
Definition: procstream.h:69
pid_t pid() const
Definition: procstream.h:67
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn