1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
383
|
23 #if !defined (octave_procstream_h) |
|
24 #define octave_procstream_h 1 |
1
|
25 |
3503
|
26 #include <iostream> |
4051
|
27 #include <string> |
2095
|
28 |
|
29 #ifdef HAVE_SYS_TYPES_H |
|
30 #include <sys/types.h> |
|
31 #endif |
|
32 |
|
33 #include "oct-procbuf.h" |
1
|
34 |
|
35 class |
3544
|
36 procstreambase : virtual public std::ios |
1
|
37 { |
1380
|
38 public: |
1965
|
39 |
|
40 procstreambase (void) { pb_init (); } |
|
41 |
4051
|
42 procstreambase (const std::string& name, int mode); |
|
43 |
1965
|
44 procstreambase (const char *name, int mode); |
1380
|
45 |
1965
|
46 ~procstreambase (void) { close (); } |
1
|
47 |
4051
|
48 void open (const std::string& name, int mode) |
|
49 { open (name.c_str (), mode); } |
|
50 |
1965
|
51 void open (const char *name, int mode); |
1380
|
52 |
1965
|
53 int is_open (void) const { return pb.is_open (); } |
1
|
54 |
483
|
55 int close (void); |
1380
|
56 |
2095
|
57 pid_t pid (void) { return pb.pid (); } |
|
58 |
1380
|
59 private: |
1965
|
60 |
2095
|
61 octave_procbuf pb; |
1965
|
62 |
|
63 void pb_init (void) { init (&pb); } |
|
64 |
|
65 procstreambase (const procstreambase&); |
|
66 |
|
67 procstreambase& operator = (const procstreambase&); |
1
|
68 }; |
|
69 |
1965
|
70 class |
3775
|
71 iprocstream : public std::istream, public procstreambase |
|
72 // iprocstream : public procstreambase, public std::istream |
1965
|
73 { |
|
74 public: |
|
75 |
3775
|
76 iprocstream (void) : std::istream (0), procstreambase () { } |
1965
|
77 |
4051
|
78 iprocstream (const std::string& name, int mode = std::ios::in) |
|
79 : std::istream (0), procstreambase (name, mode) { } |
|
80 |
3544
|
81 iprocstream (const char *name, int mode = std::ios::in) |
3775
|
82 : std::istream (0), procstreambase (name, mode) { } |
1965
|
83 |
|
84 ~iprocstream (void) { } |
|
85 |
4051
|
86 void open (const std::string& name, int mode = std::ios::in) |
|
87 { procstreambase::open (name, mode); } |
|
88 |
3544
|
89 void open (const char *name, int mode = std::ios::in) |
3189
|
90 { procstreambase::open (name, mode); } |
1965
|
91 |
|
92 private: |
|
93 |
|
94 iprocstream (const iprocstream&); |
|
95 |
|
96 iprocstream& operator = (const iprocstream&); |
|
97 }; |
1448
|
98 |
1
|
99 class |
3775
|
100 oprocstream : public std::ostream, public procstreambase |
|
101 // oprocstream : public procstreambase, public std::ostream |
1
|
102 { |
1380
|
103 public: |
1965
|
104 |
3775
|
105 oprocstream (void) : std::ostream (0), procstreambase () { } |
1
|
106 |
4051
|
107 oprocstream (const std::string& name, int mode = std::ios::out) |
|
108 : std::ostream (0), procstreambase(name, mode) { } |
|
109 |
3544
|
110 oprocstream (const char *name, int mode = std::ios::out) |
3775
|
111 : std::ostream (0), procstreambase(name, mode) { } |
1
|
112 |
1965
|
113 ~oprocstream (void) { } |
1380
|
114 |
4051
|
115 void open (const std::string& name, int mode = std::ios::out) |
|
116 { procstreambase::open (name, mode); } |
|
117 |
3544
|
118 void open (const char *name, int mode = std::ios::out) |
3652
|
119 { procstreambase::open (name, mode); } |
1380
|
120 |
|
121 private: |
1965
|
122 |
|
123 oprocstream (const oprocstream&); |
|
124 |
|
125 oprocstream& operator = (const oprocstream&); |
1
|
126 }; |
|
127 |
1965
|
128 class |
3775
|
129 procstream : public std::iostream, public procstreambase |
|
130 // procstream : public procstreambase, public std::iostream |
1965
|
131 { |
|
132 public: |
|
133 |
3775
|
134 procstream (void) : std::iostream (0), procstreambase () { } |
1965
|
135 |
4051
|
136 procstream (const std::string& name, int mode) |
|
137 : std::iostream (0), procstreambase (name, mode) { } |
|
138 |
1965
|
139 procstream (const char *name, int mode) |
3775
|
140 : std::iostream (0), procstreambase (name, mode) { } |
1965
|
141 |
|
142 ~procstream (void) { } |
|
143 |
4051
|
144 void open (const std::string& name, int mode) |
|
145 { procstreambase::open (name, mode); } |
|
146 |
1965
|
147 void open (const char *name, int mode) |
3652
|
148 { procstreambase::open (name, mode); } |
1965
|
149 |
|
150 private: |
|
151 |
|
152 procstream (const procstream&); |
|
153 |
|
154 procstream& operator = (const procstream&); |
|
155 }; |
1448
|
156 |
1
|
157 #endif |
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; End: *** |
|
163 */ |