00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_octave_stdiostream_h)
00025 #define octave_octave_stdiostream_h 1
00026
00027 #include "oct-stream.h"
00028 #include "c-file-ptr-stream.h"
00029
00030 template <typename BUF_T, typename STREAM_T, typename FILE_T>
00031 class
00032 octave_tstdiostream : public octave_base_stream
00033 {
00034 public:
00035
00036 octave_tstdiostream (const std::string& n, FILE_T f = 0,
00037 std::ios::openmode m = std::ios::in|std::ios::out,
00038 oct_mach_info::float_format ff
00039 = oct_mach_info::native_float_format (),
00040 typename BUF_T::close_fcn cf = BUF_T::fclose)
00041 : octave_base_stream (m, ff), nm (n), md (m),
00042 s (f ? new STREAM_T (f, cf) : 0)
00043 { }
00044
00045 static octave_stream
00046 create (const std::string& n, FILE_T f = 0,
00047 std::ios::openmode m = std::ios::in|std::ios::out,
00048 oct_mach_info::float_format ff
00049 = oct_mach_info::native_float_format (),
00050 typename BUF_T::close_fcn cf = BUF_T::fclose)
00051 {
00052 return octave_stream (new octave_tstdiostream (n, f, m, ff, cf));
00053 }
00054
00055
00056
00057 int seek (long offset, int origin)
00058 { return s ? s->seek (offset, origin) : -1; }
00059
00060
00061
00062 long tell (void) { return s ? s->tell () : -1; }
00063
00064
00065
00066 bool eof (void) const { return s ? s->eof () : true; }
00067
00068
00069
00070 std::string name (void) const { return nm; }
00071
00072 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; }
00073
00074 std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; }
00075
00076
00077 BUF_T *rdbuf (void) const
00078 { return s ? (const_cast<STREAM_T *> (s))->rdbuf () : 0; }
00079
00080 bool bad (void) const { return s ? s->bad () : true; }
00081
00082 void clear (void) { if (s) s->clear (); }
00083
00084 void do_close (void) { if (s) s->close (); }
00085
00086 protected:
00087
00088 std::string nm;
00089
00090 std::ios::openmode md;
00091
00092 STREAM_T *s;
00093
00094 ~octave_tstdiostream (void) { delete s; }
00095
00096 private:
00097
00098
00099
00100 octave_tstdiostream (const octave_tstdiostream&);
00101
00102 octave_tstdiostream& operator = (const octave_tstdiostream&);
00103 };
00104
00105 typedef octave_tstdiostream<c_file_ptr_buf, io_c_file_ptr_stream, FILE *> octave_stdiostream;
00106
00107 #ifdef HAVE_ZLIB
00108
00109 typedef octave_tstdiostream<c_zfile_ptr_buf, io_c_zfile_ptr_stream, gzFile> octave_zstdiostream;
00110
00111 #endif
00112
00113 #endif
00114
00115
00116
00117
00118
00119