Mercurial > octave
annotate libinterp/corefcn/procstream.h @ 27176:0112951951a9
missing edit for previous change
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 12 Jun 2019 10:51:58 -0500 |
parents | 613a31410ad0 |
children | b442ec6dda5c |
rev | line source |
---|---|
1 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
3 Copyright (C) 1993-2019 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
1 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
1 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
1 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20088
diff
changeset
|
23 #if ! defined (octave_procstream_h) |
383 | 24 #define octave_procstream_h 1 |
1 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
27 |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
28 #include <iosfwd> |
4051 | 29 #include <string> |
2095 | 30 |
31 #include <sys/types.h> | |
32 | |
33 #include "oct-procbuf.h" | |
1 | 34 |
35 class | |
6109 | 36 OCTINTERP_API |
3544 | 37 procstreambase : virtual public std::ios |
1 | 38 { |
1380 | 39 public: |
1965 | 40 |
27175
613a31410ad0
backout changeset 196dfb42f3e9
John W. Eaton <jwe@octave.org>
parents:
27172
diff
changeset
|
41 procstreambase (void) : m_pb () { pb_init (); } |
1965 | 42 |
4051 | 43 procstreambase (const std::string& name, int mode); |
44 | |
1965 | 45 procstreambase (const char *name, int mode); |
1380 | 46 |
1965 | 47 ~procstreambase (void) { close (); } |
1 | 48 |
4051 | 49 void open (const std::string& name, int mode) |
27172 | 50 { |
51 open (name.c_str (), mode); | |
52 } | |
4051 | 53 |
1965 | 54 void open (const char *name, int mode); |
1380 | 55 |
27172 | 56 int is_open (void) const { return m_pb.is_open (); } |
1 | 57 |
483 | 58 int close (void); |
1380 | 59 |
27172 | 60 pid_t pid (void) const { return m_pb.pid (); } |
6316 | 61 |
27172 | 62 int file_number (void) const { return m_pb.file_number (); } |
2095 | 63 |
1380 | 64 private: |
1965 | 65 |
27172 | 66 octave_procbuf m_pb; |
1965 | 67 |
27175
613a31410ad0
backout changeset 196dfb42f3e9
John W. Eaton <jwe@octave.org>
parents:
27172
diff
changeset
|
68 void pb_init (void) |
613a31410ad0
backout changeset 196dfb42f3e9
John W. Eaton <jwe@octave.org>
parents:
27172
diff
changeset
|
69 { |
613a31410ad0
backout changeset 196dfb42f3e9
John W. Eaton <jwe@octave.org>
parents:
27172
diff
changeset
|
70 // Explicit initialization of the std::ios object is needed. |
613a31410ad0
backout changeset 196dfb42f3e9
John W. Eaton <jwe@octave.org>
parents:
27172
diff
changeset
|
71 // FIXME: is there a better way to organize these classes? |
27176
0112951951a9
missing edit for previous change
John W. Eaton <jwe@octave.org>
parents:
27175
diff
changeset
|
72 init (&m_pb); |
27175
613a31410ad0
backout changeset 196dfb42f3e9
John W. Eaton <jwe@octave.org>
parents:
27172
diff
changeset
|
73 } |
613a31410ad0
backout changeset 196dfb42f3e9
John W. Eaton <jwe@octave.org>
parents:
27172
diff
changeset
|
74 |
1965 | 75 procstreambase (const procstreambase&); |
76 | |
77 procstreambase& operator = (const procstreambase&); | |
1 | 78 }; |
79 | |
1965 | 80 class |
6109 | 81 OCTINTERP_API |
3775 | 82 iprocstream : public std::istream, public procstreambase |
1965 | 83 { |
84 public: | |
85 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
86 iprocstream (void) : std::istream (nullptr), procstreambase () { } |
1965 | 87 |
4051 | 88 iprocstream (const std::string& name, int mode = std::ios::in) |
27172 | 89 : std::istream (nullptr), procstreambase (name, mode) |
90 { } | |
4051 | 91 |
3544 | 92 iprocstream (const char *name, int mode = std::ios::in) |
27172 | 93 : std::istream (nullptr), procstreambase (name, mode) |
94 { } | |
1965 | 95 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
96 ~iprocstream (void) = default; |
1965 | 97 |
4051 | 98 void open (const std::string& name, int mode = std::ios::in) |
27172 | 99 { |
100 procstreambase::open (name, mode); | |
101 } | |
4051 | 102 |
3544 | 103 void open (const char *name, int mode = std::ios::in) |
27172 | 104 { |
105 procstreambase::open (name, mode); | |
106 } | |
1965 | 107 |
108 private: | |
109 | |
110 iprocstream (const iprocstream&); | |
111 | |
112 iprocstream& operator = (const iprocstream&); | |
113 }; | |
1448 | 114 |
1 | 115 class |
6109 | 116 OCTINTERP_API |
3775 | 117 oprocstream : public std::ostream, public procstreambase |
1 | 118 { |
1380 | 119 public: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
120 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
121 oprocstream (void) : std::ostream (nullptr), procstreambase () { } |
1 | 122 |
4051 | 123 oprocstream (const std::string& name, int mode = std::ios::out) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
124 : std::ostream (nullptr), procstreambase (name, mode) { } |
4051 | 125 |
3544 | 126 oprocstream (const char *name, int mode = std::ios::out) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
127 : std::ostream (nullptr), procstreambase (name, mode) { } |
1 | 128 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
129 ~oprocstream (void) = default; |
1380 | 130 |
4051 | 131 void open (const std::string& name, int mode = std::ios::out) |
27172 | 132 { |
133 procstreambase::open (name, mode); | |
134 } | |
4051 | 135 |
3544 | 136 void open (const char *name, int mode = std::ios::out) |
27172 | 137 { |
138 procstreambase::open (name, mode); | |
139 } | |
1380 | 140 |
141 private: | |
1965 | 142 |
143 oprocstream (const oprocstream&); | |
144 | |
145 oprocstream& operator = (const oprocstream&); | |
1 | 146 }; |
147 | |
1965 | 148 class |
6109 | 149 OCTINTERP_API |
3775 | 150 procstream : public std::iostream, public procstreambase |
1965 | 151 { |
152 public: | |
153 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
154 procstream (void) : std::iostream (nullptr), procstreambase () { } |
1965 | 155 |
4051 | 156 procstream (const std::string& name, int mode) |
27172 | 157 : std::iostream (nullptr), procstreambase (name, mode) |
158 { } | |
4051 | 159 |
1965 | 160 procstream (const char *name, int mode) |
27172 | 161 : std::iostream (nullptr), procstreambase (name, mode) |
162 { } | |
1965 | 163 |
22868
87e3163f6c87
use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
164 ~procstream (void) = default; |
1965 | 165 |
4051 | 166 void open (const std::string& name, int mode) |
27172 | 167 { |
168 procstreambase::open (name, mode); | |
169 } | |
4051 | 170 |
1965 | 171 void open (const char *name, int mode) |
27172 | 172 { |
173 procstreambase::open (name, mode); | |
174 } | |
1965 | 175 |
176 private: | |
177 | |
178 procstream (const procstream&); | |
179 | |
180 procstream& operator = (const procstream&); | |
181 }; | |
1448 | 182 |
1 | 183 #endif |