GNU Octave  8.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-2023 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 (void) : m_pb () { pb_init (); }
47 
48  procstreambase (const std::string& name, int mode);
49 
50  procstreambase (const char *name, int mode);
51 
52  ~procstreambase (void) { close (); }
53 
54  void open (const std::string& name, int mode)
55  {
56  open (name.c_str (), mode);
57  }
58 
59  void open (const char *name, int mode);
60 
61  int is_open (void) const { return m_pb.is_open (); }
62 
63  int close (void);
64 
65  pid_t pid (void) const { return m_pb.pid (); }
66 
67  int file_number (void) const { return m_pb.file_number (); }
68 
69 private:
70 
72 
73  void pb_init (void)
74  {
75  // Explicit initialization of the std::ios object is needed.
76  // FIXME: is there a better way to organize these classes?
77  init (&m_pb);
78  }
79 
81 
82  procstreambase& operator = (const procstreambase&);
83 };
84 
85 class
86 OCTINTERP_API
87 iprocstream : public std::istream, public procstreambase
88 {
89 public:
90 
91  iprocstream (void) : std::istream (nullptr), procstreambase () { }
92 
93  iprocstream (const std::string& name, int mode = std::ios::in)
94  : std::istream (nullptr), procstreambase (name, mode)
95  { }
96 
97  iprocstream (const char *name, int mode = std::ios::in)
98  : std::istream (nullptr), procstreambase (name, mode)
99  { }
100 
101  ~iprocstream (void) = 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 private:
114 
116 
117  iprocstream& operator = (const iprocstream&);
118 };
119 
120 class
121 OCTINTERP_API
122 oprocstream : public std::ostream, public procstreambase
123 {
124 public:
125 
126  oprocstream (void) : std::ostream (nullptr), procstreambase () { }
127 
128  oprocstream (const std::string& name, int mode = std::ios::out)
129  : std::ostream (nullptr), procstreambase (name, mode) { }
130 
131  oprocstream (const char *name, int mode = std::ios::out)
132  : std::ostream (nullptr), procstreambase (name, mode) { }
133 
134  ~oprocstream (void) = default;
135 
136  void open (const std::string& name, int mode = std::ios::out)
137  {
138  procstreambase::open (name, mode);
139  }
140 
141  void open (const char *name, int mode = std::ios::out)
142  {
143  procstreambase::open (name, mode);
144  }
145 
146 private:
147 
149 
150  oprocstream& operator = (const oprocstream&);
151 };
152 
153 class
154 OCTINTERP_API
155 procstream : public std::iostream, public procstreambase
156 {
157 public:
158 
159  procstream (void) : std::iostream (nullptr), procstreambase () { }
160 
161  procstream (const std::string& name, int mode)
162  : std::iostream (nullptr), procstreambase (name, mode)
163  { }
164 
165  procstream (const char *name, int mode)
166  : std::iostream (nullptr), procstreambase (name, mode)
167  { }
168 
169  ~procstream (void) = default;
170 
171  void open (const std::string& name, int mode)
172  {
173  procstreambase::open (name, mode);
174  }
175 
176  void open (const char *name, int mode)
177  {
178  procstreambase::open (name, mode);
179  }
180 
181 private:
182 
184 
185  procstream& operator = (const procstream&);
186 };
187 
189 
190 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
191 
192 OCTAVE_DEPRECATED (7, "use 'octave::procstreambase' instead")
194 
195 OCTAVE_DEPRECATED (7, "use 'octave::iprocstream' instead")
197 
198 OCTAVE_DEPRECATED (7, "use 'octave::oprocstream' instead")
200 
201 OCTAVE_DEPRECATED (7, "use 'octave::procstream' instead")
202 typedef octave::procstream procstream;
203 
204 #endif
205 
206 #endif
OCTAVE_END_NAMESPACE(octave)
void open(const std::string &name, int mode=std::ios::in)
Definition: procstream.h:103
iprocstream(const iprocstream &)
iprocstream(const std::string &name, int mode=std::ios::in)
Definition: procstream.h:93
iprocstream(void)
Definition: procstream.h:91
iprocstream(const char *name, int mode=std::ios::in)
Definition: procstream.h:97
void open(const char *name, int mode=std::ios::in)
Definition: procstream.h:108
~iprocstream(void)=default
oprocstream(const std::string &name, int mode=std::ios::out)
Definition: procstream.h:128
oprocstream(const char *name, int mode=std::ios::out)
Definition: procstream.h:131
void open(const char *name, int mode=std::ios::out)
Definition: procstream.h:141
~oprocstream(void)=default
void open(const std::string &name, int mode=std::ios::out)
Definition: procstream.h:136
oprocstream(void)
Definition: procstream.h:126
oprocstream(const oprocstream &)
procstream(const procstream &)
procstream(const char *name, int mode)
Definition: procstream.h:165
procstream(const std::string &name, int mode)
Definition: procstream.h:161
~procstream(void)=default
void open(const char *name, int mode)
Definition: procstream.h:176
void open(const std::string &name, int mode)
Definition: procstream.h:171
procstream(void)
Definition: procstream.h:159
void open(const std::string &name, int mode)
Definition: procstream.h:54
int file_number(void) const
Definition: procstream.h:67
void pb_init(void)
Definition: procstream.h:73
procbuf m_pb
Definition: procstream.h:71
~procstreambase(void)
Definition: procstream.h:52
pid_t pid(void) const
Definition: procstream.h:65
int is_open(void) const
Definition: procstream.h:61
procstreambase(const procstreambase &)
procstreambase(void)
Definition: procstream.h:46
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn