2081
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
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 <stdiostream.h> |
|
27 |
|
28 #include "oct-stream.h" |
|
29 |
|
30 class |
|
31 octave_base_stdiostream : public octave_base_stream |
|
32 { |
|
33 public: |
|
34 |
|
35 octave_base_stdiostream (const string& n, FILE *f, |
|
36 ios::openmode arg_md = ios::in|ios::out, |
2317
|
37 oct_mach_info::float_format flt_fmt = |
|
38 oct_mach_info::native) |
|
39 : octave_base_stream (arg_md, flt_fmt), nm (n), fp (f) { } |
2081
|
40 |
|
41 ~octave_base_stdiostream (void); |
|
42 |
|
43 // Position a stream at OFFSET relative to ORIGIN. |
|
44 |
|
45 int seek (streampos offset, ios::seek_dir origin); |
|
46 |
|
47 // Return current stream position. |
|
48 |
|
49 long tell (void) const; |
|
50 |
|
51 // The name of the file. |
|
52 |
|
53 string name (void) { return nm; } |
|
54 |
|
55 virtual stdiobuf *rdbuf (void) const = 0; |
|
56 |
|
57 virtual bool bad (void) const = 0; |
|
58 |
|
59 virtual void clear (void) = 0; |
|
60 |
|
61 protected: |
|
62 |
|
63 string nm; |
|
64 |
|
65 FILE *fp; |
|
66 |
|
67 // No copying! |
|
68 |
|
69 octave_base_stdiostream (const octave_base_stdiostream&); |
|
70 |
|
71 octave_base_stdiostream& operator = (const octave_base_stdiostream&); |
|
72 }; |
|
73 |
|
74 class |
|
75 octave_istdiostream : public octave_base_stdiostream |
|
76 { |
|
77 public: |
|
78 |
|
79 octave_istdiostream (const string& n, FILE *f = 0, |
|
80 ios::openmode arg_md = ios::in, |
2317
|
81 oct_mach_info::float_format flt_fmt = |
|
82 oct_mach_info::native); |
2081
|
83 |
|
84 ~octave_istdiostream (void); |
|
85 |
|
86 // Return non-zero if EOF has been reached on this stream. |
|
87 |
|
88 bool eof (void) const { return is ? is->eof () : true; } |
|
89 |
|
90 istream *input_stream (void) { return is; } |
|
91 |
|
92 ostream *output_stream (void) { return 0; } |
|
93 |
|
94 // XXX FIXME XXX -- should not have to cast away const here. |
|
95 stdiobuf *rdbuf (void) const |
|
96 { return is ? ((istdiostream *) is)->rdbuf () : 0; } |
|
97 |
|
98 bool bad (void) const { return is ? is->bad () : true; } |
|
99 |
|
100 void clear (void) |
|
101 { |
|
102 if (is) |
|
103 is->clear (); |
|
104 } |
|
105 |
|
106 protected: |
|
107 |
|
108 istdiostream *is; |
|
109 |
|
110 private: |
|
111 |
|
112 // No copying! |
|
113 |
|
114 octave_istdiostream (const octave_istdiostream&); |
|
115 |
|
116 octave_istdiostream& operator = (const octave_istdiostream&); |
|
117 }; |
|
118 |
|
119 class |
|
120 octave_ostdiostream : public octave_base_stdiostream |
|
121 { |
|
122 public: |
|
123 |
|
124 octave_ostdiostream (const string& n, FILE *f = 0, |
|
125 ios::openmode arg_md = ios::out, |
2317
|
126 oct_mach_info::float_format flt_fmt = |
|
127 oct_mach_info::native); |
2081
|
128 |
|
129 ~octave_ostdiostream (void); |
|
130 |
|
131 // Return non-zero if EOF has been reached on this stream. |
|
132 |
|
133 bool eof (void) const { return os ? os->eof () : true; } |
|
134 |
|
135 istream *input_stream (void) { return 0; } |
|
136 |
|
137 ostream *output_stream (void) { return os; } |
|
138 |
|
139 // XXX FIXME XXX -- should not have to cast away const here. |
|
140 stdiobuf *rdbuf (void) const |
|
141 { return os ? ((ostdiostream *) os)->rdbuf () : 0; } |
|
142 |
|
143 bool bad (void) const { return os ? os->bad () : true; } |
|
144 |
|
145 void clear (void) |
|
146 { |
|
147 if (os) |
|
148 os->clear (); |
|
149 } |
|
150 |
|
151 protected: |
|
152 |
|
153 ostdiostream *os; |
|
154 |
|
155 private: |
|
156 |
|
157 // No copying! |
|
158 |
|
159 octave_ostdiostream (const octave_ostdiostream&); |
|
160 |
|
161 octave_ostdiostream& operator = (const octave_ostdiostream&); |
|
162 }; |
|
163 |
|
164 #endif |
|
165 |
|
166 /* |
|
167 ;;; Local Variables: *** |
|
168 ;;; mode: C++ *** |
|
169 ;;; End: *** |
|
170 */ |