GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
procstream.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2025 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
40class OCTINTERP_API procstreambase : virtual public std::ios
41{
42public:
43
44 procstreambase () : m_pb () { pb_init (); }
45
46 procstreambase (const std::string& name, int mode);
47
48 procstreambase (const char *name, int mode);
49
50 OCTAVE_DISABLE_COPY_MOVE (procstreambase)
51
52 ~procstreambase () { 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 () const { return m_pb.is_open (); }
62
63 int close ();
64
65 pid_t pid () const { return m_pb.pid (); }
66
67 int file_number () const { return m_pb.file_number (); }
68
69private:
70
71 procbuf m_pb;
72
73 void pb_init ()
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};
80
81class OCTINTERP_API iprocstream : public std::istream, public procstreambase
82{
83public:
84
85 iprocstream () : std::istream (nullptr), procstreambase () { }
86
87 iprocstream (const std::string& name, int mode = std::ios::in)
88 : std::istream (nullptr), procstreambase (name, mode)
89 { }
90
91 iprocstream (const char *name, int mode = std::ios::in)
92 : std::istream (nullptr), procstreambase (name, mode)
93 { }
94
95 OCTAVE_DISABLE_COPY_MOVE (iprocstream)
96
97 ~iprocstream () = default;
98
99 void open (const std::string& name, int mode = std::ios::in)
100 {
101 procstreambase::open (name, mode);
102 }
103
104 void open (const char *name, int mode = std::ios::in)
105 {
106 procstreambase::open (name, mode);
107 }
108};
109
110class OCTINTERP_API oprocstream : public std::ostream, public procstreambase
111{
112public:
113
114 oprocstream () : std::ostream (nullptr), procstreambase () { }
115
116 oprocstream (const std::string& name, int mode = std::ios::out)
117 : std::ostream (nullptr), procstreambase (name, mode) { }
118
119 oprocstream (const char *name, int mode = std::ios::out)
120 : std::ostream (nullptr), procstreambase (name, mode) { }
121
122 OCTAVE_DISABLE_COPY_MOVE (oprocstream)
123
124 ~oprocstream () = default;
125
126 void open (const std::string& name, int mode = std::ios::out)
127 {
128 procstreambase::open (name, mode);
129 }
130
131 void open (const char *name, int mode = std::ios::out)
132 {
133 procstreambase::open (name, mode);
134 }
135};
136
137class OCTINTERP_API procstream : public std::iostream, public procstreambase
138{
139public:
140
141 procstream () : std::iostream (nullptr), procstreambase () { }
142
143 procstream (const std::string& name, int mode)
144 : std::iostream (nullptr), procstreambase (name, mode)
145 { }
146
147 procstream (const char *name, int mode)
148 : std::iostream (nullptr), procstreambase (name, mode)
149 { }
150
151 OCTAVE_DISABLE_COPY_MOVE (procstream)
152
153 ~procstream () = default;
154
155 void open (const std::string& name, int mode)
156 {
157 procstreambase::open (name, mode);
158 }
159
160 void open (const char *name, int mode)
161 {
162 procstreambase::open (name, mode);
163 }
164};
165
166OCTAVE_END_NAMESPACE(octave)
167
168#endif
void open(const std::string &name, int mode=std::ios::in)
Definition procstream.h:99
~iprocstream()=default
iprocstream(const std::string &name, int mode=std::ios::in)
Definition procstream.h:87
iprocstream(const char *name, int mode=std::ios::in)
Definition procstream.h:91
void open(const char *name, int mode=std::ios::in)
Definition procstream.h:104
oprocstream(const std::string &name, int mode=std::ios::out)
Definition procstream.h:116
oprocstream(const char *name, int mode=std::ios::out)
Definition procstream.h:119
void open(const char *name, int mode=std::ios::out)
Definition procstream.h:131
void open(const std::string &name, int mode=std::ios::out)
Definition procstream.h:126
~oprocstream()=default
procstream(const char *name, int mode)
Definition procstream.h:147
procstream(const std::string &name, int mode)
Definition procstream.h:143
~procstream()=default
void open(const char *name, int mode)
Definition procstream.h:160
void open(const std::string &name, int mode)
Definition procstream.h:155
void open(const std::string &name, int mode)
Definition procstream.h:54
int is_open() const
Definition procstream.h:61
int file_number() const
Definition procstream.h:67
pid_t pid() const
Definition procstream.h:65
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn