comparison src/oct-stdstrm.h @ 4327:c29c382a5b4b

[project @ 2003-02-16 03:24:26 by jwe]
author jwe
date Sun, 16 Feb 2003 03:24:26 +0000
parents 1cae4472c624
children 34014c0fb2ce
comparison
equal deleted inserted replaced
4326:1cae4472c624 4327:c29c382a5b4b
25 25
26 #include "oct-stream.h" 26 #include "oct-stream.h"
27 #include "c-file-ptr-stream.h" 27 #include "c-file-ptr-stream.h"
28 28
29 class 29 class
30 octave_base_stdiostream : public octave_base_stream 30 octave_stdiostream : public octave_base_stream
31 { 31 {
32 public: 32 public:
33 33
34 octave_base_stdiostream 34 octave_stdiostream (const std::string& n, FILE *f = 0,
35 (const std::string& n, 35 std::ios::openmode arg_md = std::ios::in|std::ios::out,
36 std::ios::openmode arg_md = std::ios::in|std::ios::out, 36 oct_mach_info::float_format flt_fmt = oct_mach_info::native,
37 oct_mach_info::float_format flt_fmt = oct_mach_info::native) 37 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose)
38 : octave_base_stream (arg_md, flt_fmt), nm (n) { } 38 : octave_base_stream (arg_md, flt_fmt), nm (n), md (arg_md), s(0)
39 {
40 if (f)
41 s = new io_c_file_ptr_stream (f, cf);
42 }
43
44 static octave_stream
45 create (const std::string& n, FILE *f = 0,
46 std::ios::openmode arg_md = std::ios::in|std::ios::out,
47 oct_mach_info::float_format flt_fmt = oct_mach_info::native,
48 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose)
49 {
50 return octave_stream (new octave_stdiostream (n, f, arg_md, flt_fmt, cf));
51 }
39 52
40 // Position a stream at OFFSET relative to ORIGIN. 53 // Position a stream at OFFSET relative to ORIGIN.
41 54
42 int seek (std::streamoff offset, std::ios::seekdir origin); 55 int seek (std::streamoff offset, std::ios::seekdir origin);
43 56
44 // Return current stream position. 57 // Return current stream position.
45 58
46 long tell (void) const; 59 long tell (void) const;
47 60
61 // Return non-zero if EOF has been reached on this stream.
62
63 bool eof (void) const { return s ? s->eof () : true; }
64
48 // The name of the file. 65 // The name of the file.
49 66
50 std::string name (void) const { return nm; } 67 std::string name (void) const { return nm; }
51 68
52 virtual c_file_ptr_buf *rdbuf (void) const = 0; 69 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; }
53 70
54 virtual bool bad (void) const = 0; 71 std::ostream *output_stream (void) { return (md & std::ios::in) ? s : 0; }
55
56 virtual void clear (void) = 0;
57
58 protected:
59
60 std::string nm;
61
62 ~octave_base_stdiostream (void) { }
63
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
76 octave_istdiostream (const std::string& n, FILE *f = 0,
77 std::ios::openmode arg_md = std::ios::in,
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);
80
81 static octave_stream
82 create (const std::string& n, FILE *f = 0,
83 std::ios::openmode arg_md = std::ios::in,
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);
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
91 std::istream *input_stream (void) { return is; }
92
93 std::ostream *output_stream (void) { return 0; }
94
95 // XXX FIXME XXX -- should not have to cast away const here.
96 c_file_ptr_buf *rdbuf (void) const
97 { return is ? (const_cast<i_c_file_ptr_stream *> (is))->rdbuf () : 0; }
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
107 void do_close (void);
108
109 protected:
110
111 i_c_file_ptr_stream *is;
112
113 ~octave_istdiostream (void);
114
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
129 octave_ostdiostream (const std::string& n, FILE *f = 0,
130 std::ios::openmode arg_md = std::ios::out,
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);
133
134 static octave_stream
135 create (const std::string& n, FILE *f = 0,
136 std::ios::openmode arg_md = std::ios::out,
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);
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
144 std::istream *input_stream (void) { return 0; }
145
146 std::ostream *output_stream (void) { return os; }
147
148 // XXX FIXME XXX -- should not have to cast away const here.
149 c_file_ptr_buf *rdbuf (void) const
150 { return os ? (const_cast<o_c_file_ptr_stream *> (os))->rdbuf () : 0; }
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
160 void do_close (void);
161
162 protected:
163
164 o_c_file_ptr_stream *os;
165
166 ~octave_ostdiostream (void);
167
168 private:
169
170 // No copying!
171
172 octave_ostdiostream (const octave_ostdiostream&);
173
174 octave_ostdiostream& operator = (const octave_ostdiostream&);
175 };
176
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 72
201 // XXX FIXME XXX -- should not have to cast away const here. 73 // XXX FIXME XXX -- should not have to cast away const here.
202 c_file_ptr_buf *rdbuf (void) const 74 c_file_ptr_buf *rdbuf (void) const
203 { return s ? (const_cast<io_c_file_ptr_stream *> (s))->rdbuf () : 0; } 75 { return s ? (const_cast<io_c_file_ptr_stream *> (s))->rdbuf () : 0; }
204 76
205 bool bad (void) const { return s ? s->bad () : true; } 77 bool bad (void) const { return s ? s->bad () : true; }
206 78
207 void clear (void) 79 void clear (void) { if (s) s->clear (); }
208 {
209 if (s)
210 s->clear ();
211 }
212 80
213 void do_close (void); 81 void do_close (void) { if (s) s->close (); }
214 82
215 protected: 83 protected:
216 84
85 std::string nm;
86
87 std::ios::openmode md;
88
217 io_c_file_ptr_stream *s; 89 io_c_file_ptr_stream *s;
218 90
219 ~octave_iostdiostream (void); 91 ~octave_stdiostream (void) { delete s; }
220 92
221 private: 93 private:
222 94
223 // No copying! 95 // No copying!
224 96
225 octave_iostdiostream (const octave_iostdiostream&); 97 octave_stdiostream (const octave_stdiostream&);
226 98
227 octave_iostdiostream& operator = (const octave_iostdiostream&); 99 octave_stdiostream& operator = (const octave_stdiostream&);
228 }; 100 };
229 101
230 #endif 102 #endif
231 103
232 /* 104 /*