Mercurial > octave
comparison src/oct-stdstrm.h @ 5325:ecbe4aa87e51
[project @ 2005-04-29 20:48:35 by jwe]
author | jwe |
---|---|
date | Fri, 29 Apr 2005 20:48:36 +0000 |
parents | 4c8a2e4e0717 |
children | f07a9653b844 |
comparison
equal
deleted
inserted
replaced
5324:d2d11284528e | 5325:ecbe4aa87e51 |
---|---|
25 #define octave_octave_stdiostream_h 1 | 25 #define octave_octave_stdiostream_h 1 |
26 | 26 |
27 #include "oct-stream.h" | 27 #include "oct-stream.h" |
28 #include "c-file-ptr-stream.h" | 28 #include "c-file-ptr-stream.h" |
29 | 29 |
30 template <typename BUF_T, typename STREAM_T, typename FILE_T> | |
30 class | 31 class |
31 octave_stdiostream : public octave_base_stream | 32 octave_tstdiostream : public octave_base_stream |
32 { | 33 { |
33 public: | 34 public: |
34 | 35 |
35 octave_stdiostream (const std::string& n, FILE *f = 0, | 36 octave_tstdiostream (const std::string& n, FILE_T f = 0, |
36 std::ios::openmode m = std::ios::in|std::ios::out, | 37 std::ios::openmode m = std::ios::in|std::ios::out, |
37 oct_mach_info::float_format ff | 38 oct_mach_info::float_format ff |
38 = oct_mach_info::native_float_format (), | 39 = oct_mach_info::native_float_format (), |
39 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose) | 40 typename BUF_T::close_fcn cf = BUF_T::fclose) |
40 : octave_base_stream (m, ff), nm (n), md (m), s(0) | 41 : octave_base_stream (m, ff), nm (n), md (m), |
41 { | 42 s(f ? new STREAM_T (f, cf) : 0) |
42 if (f) | 43 { } |
43 s = new io_c_file_ptr_stream (f, cf); | |
44 } | |
45 | 44 |
46 static octave_stream | 45 static octave_stream |
47 create (const std::string& n, FILE *f = 0, | 46 create (const std::string& n, FILE_T f = 0, |
48 std::ios::openmode m = std::ios::in|std::ios::out, | 47 std::ios::openmode m = std::ios::in|std::ios::out, |
49 oct_mach_info::float_format ff | 48 oct_mach_info::float_format ff |
50 = oct_mach_info::native_float_format (), | 49 = oct_mach_info::native_float_format (), |
51 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose) | 50 typename BUF_T::close_fcn cf = BUF_T::fclose) |
52 { | 51 { |
53 return octave_stream (new octave_stdiostream (n, f, m, ff, cf)); | 52 return octave_stream (new octave_tstdiostream (n, f, m, ff, cf)); |
54 } | 53 } |
55 | 54 |
56 // Position a stream at OFFSET relative to ORIGIN. | 55 // Position a stream at OFFSET relative to ORIGIN. |
57 | 56 |
58 int seek (long offset, int origin); | 57 int seek (long offset, int origin) |
58 { return s ? s->seek (offset, origin) : -1; } | |
59 | 59 |
60 // Return current stream position. | 60 // Return current stream position. |
61 | 61 |
62 long tell (void); | 62 long tell (void) { return s ? s->tell () : -1; } |
63 | 63 |
64 // Return non-zero if EOF has been reached on this stream. | 64 // Return non-zero if EOF has been reached on this stream. |
65 | 65 |
66 bool eof (void) const { return s ? s->eof () : true; } | 66 bool eof (void) const { return s ? s->eof () : true; } |
67 | 67 |
72 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; } | 72 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; } |
73 | 73 |
74 std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; } | 74 std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; } |
75 | 75 |
76 // XXX FIXME XXX -- should not have to cast away const here. | 76 // XXX FIXME XXX -- should not have to cast away const here. |
77 c_file_ptr_buf *rdbuf (void) const | 77 BUF_T *rdbuf (void) const |
78 { return s ? (const_cast<io_c_file_ptr_stream *> (s))->rdbuf () : 0; } | 78 { return s ? (const_cast<STREAM_T *> (s))->rdbuf () : 0; } |
79 | 79 |
80 bool bad (void) const { return s ? s->bad () : true; } | 80 bool bad (void) const { return s ? s->bad () : true; } |
81 | 81 |
82 void clear (void) { if (s) s->clear (); } | 82 void clear (void) { if (s) s->clear (); } |
83 | 83 |
87 | 87 |
88 std::string nm; | 88 std::string nm; |
89 | 89 |
90 std::ios::openmode md; | 90 std::ios::openmode md; |
91 | 91 |
92 io_c_file_ptr_stream *s; | 92 STREAM_T *s; |
93 | 93 |
94 ~octave_stdiostream (void) { delete s; } | 94 ~octave_tstdiostream (void) { delete s; } |
95 | 95 |
96 private: | 96 private: |
97 | 97 |
98 // No copying! | 98 // No copying! |
99 | 99 |
100 octave_stdiostream (const octave_stdiostream&); | 100 octave_tstdiostream (const octave_tstdiostream&); |
101 | 101 |
102 octave_stdiostream& operator = (const octave_stdiostream&); | 102 octave_tstdiostream& operator = (const octave_tstdiostream&); |
103 }; | 103 }; |
104 | |
105 typedef octave_tstdiostream<c_file_ptr_buf, io_c_file_ptr_stream, FILE *> octave_stdiostream; | |
106 | |
107 #ifdef HAVE_ZLIB | |
108 | |
109 typedef octave_tstdiostream<c_zfile_ptr_buf, io_c_zfile_ptr_stream, gzFile> octave_zstdiostream; | |
110 | |
111 #endif | |
104 | 112 |
105 #endif | 113 #endif |
106 | 114 |
107 /* | 115 /* |
108 ;;; Local Variables: *** | 116 ;;; Local Variables: *** |