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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2081
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_octave_stdiostream_h) |
|
25 #define octave_octave_stdiostream_h 1 |
|
26 |
|
27 #include "oct-stream.h" |
3630
|
28 #include "c-file-ptr-stream.h" |
2081
|
29 |
|
30 class |
4327
|
31 octave_stdiostream : public octave_base_stream |
2081
|
32 { |
|
33 public: |
|
34 |
4327
|
35 octave_stdiostream (const std::string& n, FILE *f = 0, |
4587
|
36 std::ios::openmode m = std::ios::in|std::ios::out, |
5015
|
37 oct_mach_info::float_format ff |
|
38 = oct_mach_info::native_float_format (), |
4327
|
39 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose) |
4587
|
40 : octave_base_stream (m, ff), nm (n), md (m), s(0) |
4327
|
41 { |
|
42 if (f) |
|
43 s = new io_c_file_ptr_stream (f, cf); |
|
44 } |
|
45 |
|
46 static octave_stream |
|
47 create (const std::string& n, FILE *f = 0, |
4587
|
48 std::ios::openmode m = std::ios::in|std::ios::out, |
5015
|
49 oct_mach_info::float_format ff |
|
50 = oct_mach_info::native_float_format (), |
4327
|
51 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose) |
|
52 { |
4587
|
53 return octave_stream (new octave_stdiostream (n, f, m, ff, cf)); |
4327
|
54 } |
2081
|
55 |
|
56 // Position a stream at OFFSET relative to ORIGIN. |
|
57 |
4797
|
58 int seek (long offset, int origin); |
2081
|
59 |
|
60 // Return current stream position. |
|
61 |
4797
|
62 long tell (void); |
2081
|
63 |
4327
|
64 // Return non-zero if EOF has been reached on this stream. |
|
65 |
|
66 bool eof (void) const { return s ? s->eof () : true; } |
|
67 |
2081
|
68 // The name of the file. |
|
69 |
3523
|
70 std::string name (void) const { return nm; } |
2081
|
71 |
4327
|
72 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; } |
2081
|
73 |
4361
|
74 std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; } |
4326
|
75 |
|
76 // XXX FIXME XXX -- should not have to cast away const here. |
|
77 c_file_ptr_buf *rdbuf (void) const |
|
78 { return s ? (const_cast<io_c_file_ptr_stream *> (s))->rdbuf () : 0; } |
|
79 |
|
80 bool bad (void) const { return s ? s->bad () : true; } |
|
81 |
4327
|
82 void clear (void) { if (s) s->clear (); } |
4326
|
83 |
4327
|
84 void do_close (void) { if (s) s->close (); } |
4326
|
85 |
|
86 protected: |
|
87 |
4327
|
88 std::string nm; |
|
89 |
|
90 std::ios::openmode md; |
|
91 |
4326
|
92 io_c_file_ptr_stream *s; |
|
93 |
4327
|
94 ~octave_stdiostream (void) { delete s; } |
4326
|
95 |
|
96 private: |
|
97 |
|
98 // No copying! |
|
99 |
4327
|
100 octave_stdiostream (const octave_stdiostream&); |
4326
|
101 |
4327
|
102 octave_stdiostream& operator = (const octave_stdiostream&); |
4326
|
103 }; |
|
104 |
2081
|
105 #endif |
|
106 |
|
107 /* |
|
108 ;;; Local Variables: *** |
|
109 ;;; mode: C++ *** |
|
110 ;;; End: *** |
|
111 */ |