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, |
3951
|
77 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose, |
3544
|
78 std::ios::openmode arg_md = std::ios::in, |
2317
|
79 oct_mach_info::float_format flt_fmt = |
|
80 oct_mach_info::native); |
2081
|
81 |
3340
|
82 static octave_stream |
3544
|
83 create (const std::string& n, FILE *f = 0, |
3951
|
84 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose, |
3544
|
85 std::ios::openmode arg_md = std::ios::in, |
3340
|
86 oct_mach_info::float_format flt_fmt = oct_mach_info::native); |
2081
|
87 |
|
88 // Return non-zero if EOF has been reached on this stream. |
|
89 |
|
90 bool eof (void) const { return is ? is->eof () : true; } |
|
91 |
3523
|
92 std::istream *input_stream (void) { return is; } |
2081
|
93 |
3523
|
94 std::ostream *output_stream (void) { return 0; } |
2081
|
95 |
|
96 // XXX FIXME XXX -- should not have to cast away const here. |
3652
|
97 c_file_ptr_buf *rdbuf (void) const |
|
98 { return is ? (const_cast<i_c_file_ptr_stream *> (is))->rdbuf () : 0; } |
2081
|
99 |
|
100 bool bad (void) const { return is ? is->bad () : true; } |
|
101 |
|
102 void clear (void) |
|
103 { |
|
104 if (is) |
|
105 is->clear (); |
|
106 } |
|
107 |
3652
|
108 void do_close (void); |
|
109 |
2081
|
110 protected: |
|
111 |
3611
|
112 i_c_file_ptr_stream *is; |
2081
|
113 |
3340
|
114 ~octave_istdiostream (void); |
|
115 |
2081
|
116 private: |
|
117 |
|
118 // No copying! |
|
119 |
|
120 octave_istdiostream (const octave_istdiostream&); |
|
121 |
|
122 octave_istdiostream& operator = (const octave_istdiostream&); |
|
123 }; |
|
124 |
|
125 class |
|
126 octave_ostdiostream : public octave_base_stdiostream |
|
127 { |
|
128 public: |
|
129 |
3523
|
130 octave_ostdiostream (const std::string& n, FILE *f = 0, |
3951
|
131 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose, |
3544
|
132 std::ios::openmode arg_md = std::ios::out, |
2317
|
133 oct_mach_info::float_format flt_fmt = |
|
134 oct_mach_info::native); |
2081
|
135 |
3340
|
136 static octave_stream |
3544
|
137 create (const std::string& n, FILE *f = 0, |
3951
|
138 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose, |
3544
|
139 std::ios::openmode arg_md = std::ios::out, |
3340
|
140 oct_mach_info::float_format flt_fmt = oct_mach_info::native); |
2081
|
141 |
|
142 // Return non-zero if EOF has been reached on this stream. |
|
143 |
|
144 bool eof (void) const { return os ? os->eof () : true; } |
|
145 |
3523
|
146 std::istream *input_stream (void) { return 0; } |
2081
|
147 |
3523
|
148 std::ostream *output_stream (void) { return os; } |
2081
|
149 |
|
150 // XXX FIXME XXX -- should not have to cast away const here. |
3611
|
151 c_file_ptr_buf *rdbuf (void) const |
|
152 { return os ? (const_cast<o_c_file_ptr_stream *> (os))->rdbuf () : 0; } |
2081
|
153 |
|
154 bool bad (void) const { return os ? os->bad () : true; } |
|
155 |
|
156 void clear (void) |
|
157 { |
|
158 if (os) |
|
159 os->clear (); |
|
160 } |
|
161 |
3652
|
162 void do_close (void); |
|
163 |
2081
|
164 protected: |
|
165 |
3611
|
166 o_c_file_ptr_stream *os; |
2081
|
167 |
3340
|
168 ~octave_ostdiostream (void); |
|
169 |
2081
|
170 private: |
|
171 |
|
172 // No copying! |
|
173 |
|
174 octave_ostdiostream (const octave_ostdiostream&); |
|
175 |
|
176 octave_ostdiostream& operator = (const octave_ostdiostream&); |
|
177 }; |
|
178 |
|
179 #endif |
|
180 |
|
181 /* |
|
182 ;;; Local Variables: *** |
|
183 ;;; mode: C++ *** |
|
184 ;;; End: *** |
|
185 */ |