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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
|
22 */ |
|
23 |
383
|
24 #if !defined (octave_procstream_h) |
|
25 #define octave_procstream_h 1 |
1
|
26 |
3503
|
27 #include <iostream> |
4051
|
28 #include <string> |
2095
|
29 |
|
30 #ifdef HAVE_SYS_TYPES_H |
|
31 #include <sys/types.h> |
|
32 #endif |
|
33 |
|
34 #include "oct-procbuf.h" |
1
|
35 |
|
36 class |
3544
|
37 procstreambase : virtual public std::ios |
1
|
38 { |
1380
|
39 public: |
1965
|
40 |
|
41 procstreambase (void) { pb_init (); } |
|
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) |
|
50 { open (name.c_str (), mode); } |
|
51 |
1965
|
52 void open (const char *name, int mode); |
1380
|
53 |
1965
|
54 int is_open (void) const { return pb.is_open (); } |
1
|
55 |
483
|
56 int close (void); |
1380
|
57 |
2095
|
58 pid_t pid (void) { return pb.pid (); } |
|
59 |
1380
|
60 private: |
1965
|
61 |
2095
|
62 octave_procbuf pb; |
1965
|
63 |
|
64 void pb_init (void) { init (&pb); } |
|
65 |
|
66 procstreambase (const procstreambase&); |
|
67 |
|
68 procstreambase& operator = (const procstreambase&); |
1
|
69 }; |
|
70 |
1965
|
71 class |
3775
|
72 iprocstream : public std::istream, public procstreambase |
|
73 // iprocstream : public procstreambase, public std::istream |
1965
|
74 { |
|
75 public: |
|
76 |
3775
|
77 iprocstream (void) : std::istream (0), procstreambase () { } |
1965
|
78 |
4051
|
79 iprocstream (const std::string& name, int mode = std::ios::in) |
|
80 : std::istream (0), procstreambase (name, mode) { } |
|
81 |
3544
|
82 iprocstream (const char *name, int mode = std::ios::in) |
3775
|
83 : std::istream (0), procstreambase (name, mode) { } |
1965
|
84 |
|
85 ~iprocstream (void) { } |
|
86 |
4051
|
87 void open (const std::string& name, int mode = std::ios::in) |
|
88 { procstreambase::open (name, mode); } |
|
89 |
3544
|
90 void open (const char *name, int mode = std::ios::in) |
3189
|
91 { procstreambase::open (name, mode); } |
1965
|
92 |
|
93 private: |
|
94 |
|
95 iprocstream (const iprocstream&); |
|
96 |
|
97 iprocstream& operator = (const iprocstream&); |
|
98 }; |
1448
|
99 |
1
|
100 class |
3775
|
101 oprocstream : public std::ostream, public procstreambase |
|
102 // oprocstream : public procstreambase, public std::ostream |
1
|
103 { |
1380
|
104 public: |
1965
|
105 |
3775
|
106 oprocstream (void) : std::ostream (0), procstreambase () { } |
1
|
107 |
4051
|
108 oprocstream (const std::string& name, int mode = std::ios::out) |
|
109 : std::ostream (0), procstreambase(name, mode) { } |
|
110 |
3544
|
111 oprocstream (const char *name, int mode = std::ios::out) |
3775
|
112 : std::ostream (0), procstreambase(name, mode) { } |
1
|
113 |
1965
|
114 ~oprocstream (void) { } |
1380
|
115 |
4051
|
116 void open (const std::string& name, int mode = std::ios::out) |
|
117 { procstreambase::open (name, mode); } |
|
118 |
3544
|
119 void open (const char *name, int mode = std::ios::out) |
3652
|
120 { procstreambase::open (name, mode); } |
1380
|
121 |
|
122 private: |
1965
|
123 |
|
124 oprocstream (const oprocstream&); |
|
125 |
|
126 oprocstream& operator = (const oprocstream&); |
1
|
127 }; |
|
128 |
1965
|
129 class |
3775
|
130 procstream : public std::iostream, public procstreambase |
|
131 // procstream : public procstreambase, public std::iostream |
1965
|
132 { |
|
133 public: |
|
134 |
3775
|
135 procstream (void) : std::iostream (0), procstreambase () { } |
1965
|
136 |
4051
|
137 procstream (const std::string& name, int mode) |
|
138 : std::iostream (0), procstreambase (name, mode) { } |
|
139 |
1965
|
140 procstream (const char *name, int mode) |
3775
|
141 : std::iostream (0), procstreambase (name, mode) { } |
1965
|
142 |
|
143 ~procstream (void) { } |
|
144 |
4051
|
145 void open (const std::string& name, int mode) |
|
146 { procstreambase::open (name, mode); } |
|
147 |
1965
|
148 void open (const char *name, int mode) |
3652
|
149 { procstreambase::open (name, mode); } |
1965
|
150 |
|
151 private: |
|
152 |
|
153 procstream (const procstream&); |
|
154 |
|
155 procstream& operator = (const procstream&); |
|
156 }; |
1448
|
157 |
1
|
158 #endif |
|
159 |
|
160 /* |
|
161 ;;; Local Variables: *** |
|
162 ;;; mode: C++ *** |
|
163 ;;; End: *** |
|
164 */ |