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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2081
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2081
|
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 |
5325
|
29 template <typename BUF_T, typename STREAM_T, typename FILE_T> |
2081
|
30 class |
5325
|
31 octave_tstdiostream : public octave_base_stream |
2081
|
32 { |
|
33 public: |
|
34 |
5325
|
35 octave_tstdiostream (const std::string& n, FILE_T f = 0, |
|
36 std::ios::openmode m = std::ios::in|std::ios::out, |
|
37 oct_mach_info::float_format ff |
|
38 = oct_mach_info::native_float_format (), |
|
39 typename BUF_T::close_fcn cf = BUF_T::fclose) |
|
40 : octave_base_stream (m, ff), nm (n), md (m), |
5370
|
41 s (f ? new STREAM_T (f, cf) : 0) |
5325
|
42 { } |
4327
|
43 |
|
44 static octave_stream |
5325
|
45 create (const std::string& n, FILE_T f = 0, |
4587
|
46 std::ios::openmode m = std::ios::in|std::ios::out, |
5015
|
47 oct_mach_info::float_format ff |
|
48 = oct_mach_info::native_float_format (), |
5325
|
49 typename BUF_T::close_fcn cf = BUF_T::fclose) |
4327
|
50 { |
5325
|
51 return octave_stream (new octave_tstdiostream (n, f, m, ff, cf)); |
4327
|
52 } |
2081
|
53 |
|
54 // Position a stream at OFFSET relative to ORIGIN. |
|
55 |
5325
|
56 int seek (long offset, int origin) |
|
57 { return s ? s->seek (offset, origin) : -1; } |
2081
|
58 |
|
59 // Return current stream position. |
|
60 |
5325
|
61 long tell (void) { return s ? s->tell () : -1; } |
2081
|
62 |
4327
|
63 // Return non-zero if EOF has been reached on this stream. |
|
64 |
|
65 bool eof (void) const { return s ? s->eof () : true; } |
|
66 |
2081
|
67 // The name of the file. |
|
68 |
3523
|
69 std::string name (void) const { return nm; } |
2081
|
70 |
4327
|
71 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; } |
2081
|
72 |
4361
|
73 std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; } |
4326
|
74 |
5775
|
75 // FIXME -- should not have to cast away const here. |
5325
|
76 BUF_T *rdbuf (void) const |
|
77 { return s ? (const_cast<STREAM_T *> (s))->rdbuf () : 0; } |
4326
|
78 |
|
79 bool bad (void) const { return s ? s->bad () : true; } |
|
80 |
4327
|
81 void clear (void) { if (s) s->clear (); } |
4326
|
82 |
4327
|
83 void do_close (void) { if (s) s->close (); } |
4326
|
84 |
|
85 protected: |
|
86 |
4327
|
87 std::string nm; |
|
88 |
|
89 std::ios::openmode md; |
|
90 |
5325
|
91 STREAM_T *s; |
4326
|
92 |
5325
|
93 ~octave_tstdiostream (void) { delete s; } |
4326
|
94 |
|
95 private: |
|
96 |
|
97 // No copying! |
|
98 |
5325
|
99 octave_tstdiostream (const octave_tstdiostream&); |
|
100 |
|
101 octave_tstdiostream& operator = (const octave_tstdiostream&); |
|
102 }; |
4326
|
103 |
5325
|
104 typedef octave_tstdiostream<c_file_ptr_buf, io_c_file_ptr_stream, FILE *> octave_stdiostream; |
|
105 |
|
106 #ifdef HAVE_ZLIB |
|
107 |
|
108 typedef octave_tstdiostream<c_zfile_ptr_buf, io_c_zfile_ptr_stream, gzFile> octave_zstdiostream; |
|
109 |
|
110 #endif |
4326
|
111 |
2081
|
112 #endif |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; End: *** |
|
118 */ |