2081
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2081
|
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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_octave_stdiostream_h) |
|
24 #define octave_octave_stdiostream_h 1 |
|
25 |
|
26 #include "oct-stream.h" |
3630
|
27 #include "c-file-ptr-stream.h" |
2081
|
28 |
|
29 class |
|
30 octave_base_stdiostream : public octave_base_stream |
|
31 { |
|
32 public: |
|
33 |
3544
|
34 octave_base_stdiostream |
3716
|
35 (const std::string& n, |
3544
|
36 std::ios::openmode arg_md = std::ios::in|std::ios::out, |
|
37 oct_mach_info::float_format flt_fmt = oct_mach_info::native) |
3716
|
38 : octave_base_stream (arg_md, flt_fmt), nm (n) { } |
2081
|
39 |
|
40 // Position a stream at OFFSET relative to ORIGIN. |
|
41 |
3775
|
42 int seek (std::streamoff offset, std::ios::seekdir origin); |
2081
|
43 |
|
44 // Return current stream position. |
|
45 |
|
46 long tell (void) const; |
|
47 |
|
48 // The name of the file. |
|
49 |
3523
|
50 std::string name (void) const { return nm; } |
2081
|
51 |
3611
|
52 virtual c_file_ptr_buf *rdbuf (void) const = 0; |
2081
|
53 |
|
54 virtual bool bad (void) const = 0; |
|
55 |
|
56 virtual void clear (void) = 0; |
|
57 |
|
58 protected: |
|
59 |
3523
|
60 std::string nm; |
2081
|
61 |
3716
|
62 ~octave_base_stdiostream (void) { } |
3340
|
63 |
2081
|
64 // No copying! |
|
65 |
|
66 octave_base_stdiostream (const octave_base_stdiostream&); |
|
67 |
|
68 octave_base_stdiostream& operator = (const octave_base_stdiostream&); |
|
69 }; |
|
70 |
|
71 class |
|
72 octave_istdiostream : public octave_base_stdiostream |
|
73 { |
|
74 public: |
|
75 |
3523
|
76 octave_istdiostream (const std::string& n, FILE *f = 0, |
3544
|
77 std::ios::openmode arg_md = std::ios::in, |
4326
|
78 oct_mach_info::float_format flt_fmt = oct_mach_info::native, |
|
79 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose); |
2081
|
80 |
3340
|
81 static octave_stream |
3544
|
82 create (const std::string& n, FILE *f = 0, |
|
83 std::ios::openmode arg_md = std::ios::in, |
4326
|
84 oct_mach_info::float_format flt_fmt = oct_mach_info::native, |
|
85 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose); |
2081
|
86 |
|
87 // Return non-zero if EOF has been reached on this stream. |
|
88 |
|
89 bool eof (void) const { return is ? is->eof () : true; } |
|
90 |
3523
|
91 std::istream *input_stream (void) { return is; } |
2081
|
92 |
3523
|
93 std::ostream *output_stream (void) { return 0; } |
2081
|
94 |
|
95 // XXX FIXME XXX -- should not have to cast away const here. |
3652
|
96 c_file_ptr_buf *rdbuf (void) const |
|
97 { return is ? (const_cast<i_c_file_ptr_stream *> (is))->rdbuf () : 0; } |
2081
|
98 |
|
99 bool bad (void) const { return is ? is->bad () : true; } |
|
100 |
|
101 void clear (void) |
|
102 { |
|
103 if (is) |
|
104 is->clear (); |
|
105 } |
|
106 |
3652
|
107 void do_close (void); |
|
108 |
2081
|
109 protected: |
|
110 |
3611
|
111 i_c_file_ptr_stream *is; |
2081
|
112 |
3340
|
113 ~octave_istdiostream (void); |
|
114 |
2081
|
115 private: |
|
116 |
|
117 // No copying! |
|
118 |
|
119 octave_istdiostream (const octave_istdiostream&); |
|
120 |
|
121 octave_istdiostream& operator = (const octave_istdiostream&); |
|
122 }; |
|
123 |
|
124 class |
|
125 octave_ostdiostream : public octave_base_stdiostream |
|
126 { |
|
127 public: |
|
128 |
3523
|
129 octave_ostdiostream (const std::string& n, FILE *f = 0, |
3544
|
130 std::ios::openmode arg_md = std::ios::out, |
4326
|
131 oct_mach_info::float_format flt_fmt = oct_mach_info::native, |
|
132 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose); |
2081
|
133 |
3340
|
134 static octave_stream |
3544
|
135 create (const std::string& n, FILE *f = 0, |
|
136 std::ios::openmode arg_md = std::ios::out, |
4326
|
137 oct_mach_info::float_format flt_fmt = oct_mach_info::native, |
|
138 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose); |
2081
|
139 |
|
140 // Return non-zero if EOF has been reached on this stream. |
|
141 |
|
142 bool eof (void) const { return os ? os->eof () : true; } |
|
143 |
3523
|
144 std::istream *input_stream (void) { return 0; } |
2081
|
145 |
3523
|
146 std::ostream *output_stream (void) { return os; } |
2081
|
147 |
|
148 // XXX FIXME XXX -- should not have to cast away const here. |
3611
|
149 c_file_ptr_buf *rdbuf (void) const |
|
150 { return os ? (const_cast<o_c_file_ptr_stream *> (os))->rdbuf () : 0; } |
2081
|
151 |
|
152 bool bad (void) const { return os ? os->bad () : true; } |
|
153 |
|
154 void clear (void) |
|
155 { |
|
156 if (os) |
|
157 os->clear (); |
|
158 } |
|
159 |
3652
|
160 void do_close (void); |
|
161 |
2081
|
162 protected: |
|
163 |
3611
|
164 o_c_file_ptr_stream *os; |
2081
|
165 |
3340
|
166 ~octave_ostdiostream (void); |
|
167 |
2081
|
168 private: |
|
169 |
|
170 // No copying! |
|
171 |
|
172 octave_ostdiostream (const octave_ostdiostream&); |
|
173 |
|
174 octave_ostdiostream& operator = (const octave_ostdiostream&); |
|
175 }; |
|
176 |
4326
|
177 class |
|
178 octave_iostdiostream : public octave_base_stdiostream |
|
179 { |
|
180 public: |
|
181 |
|
182 octave_iostdiostream (const std::string& n, FILE *f = 0, |
|
183 std::ios::openmode arg_md = std::ios::in, |
|
184 oct_mach_info::float_format flt_fmt = oct_mach_info::native, |
|
185 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose); |
|
186 |
|
187 static octave_stream |
|
188 create (const std::string& n, FILE *f = 0, |
|
189 std::ios::openmode arg_md = std::ios::in|std::ios::out, |
|
190 oct_mach_info::float_format flt_fmt = oct_mach_info::native, |
|
191 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose); |
|
192 |
|
193 // Return non-zero if EOF has been reached on this stream. |
|
194 |
|
195 bool eof (void) const { return s ? s->eof () : true; } |
|
196 |
|
197 std::istream *input_stream (void) { return s; } |
|
198 |
|
199 std::ostream *output_stream (void) { return s; } |
|
200 |
|
201 // XXX FIXME XXX -- should not have to cast away const here. |
|
202 c_file_ptr_buf *rdbuf (void) const |
|
203 { return s ? (const_cast<io_c_file_ptr_stream *> (s))->rdbuf () : 0; } |
|
204 |
|
205 bool bad (void) const { return s ? s->bad () : true; } |
|
206 |
|
207 void clear (void) |
|
208 { |
|
209 if (s) |
|
210 s->clear (); |
|
211 } |
|
212 |
|
213 void do_close (void); |
|
214 |
|
215 protected: |
|
216 |
|
217 io_c_file_ptr_stream *s; |
|
218 |
|
219 ~octave_iostdiostream (void); |
|
220 |
|
221 private: |
|
222 |
|
223 // No copying! |
|
224 |
|
225 octave_iostdiostream (const octave_iostdiostream&); |
|
226 |
|
227 octave_iostdiostream& operator = (const octave_iostdiostream&); |
|
228 }; |
|
229 |
2081
|
230 #endif |
|
231 |
|
232 /* |
|
233 ;;; Local Variables: *** |
|
234 ;;; mode: C++ *** |
|
235 ;;; End: *** |
|
236 */ |