00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_octave_stdiostream_h)
00024 #define octave_octave_stdiostream_h 1
00025
00026 #include "oct-stream.h"
00027 #include "c-file-ptr-stream.h"
00028
00029 template <typename BUF_T, typename STREAM_T, typename FILE_T>
00030 class
00031 octave_tstdiostream : public octave_base_stream
00032 {
00033 public:
00034
00035 octave_tstdiostream (const std::string& n, FILE_T f = 0, int fid = 0,
00036 std::ios::openmode m = std::ios::in|std::ios::out,
00037 oct_mach_info::float_format ff
00038 = oct_mach_info::native_float_format (),
00039 typename BUF_T::close_fcn cf = BUF_T::file_close)
00040 : octave_base_stream (m, ff), nm (n), md (m),
00041 s (f ? new STREAM_T (f, cf) : 0), fnum (fid)
00042 { }
00043
00044
00045
00046 int seek (long offset, int origin)
00047 { return s ? s->seek (offset, origin) : -1; }
00048
00049
00050
00051 long tell (void) { return s ? s->tell () : -1; }
00052
00053
00054
00055 bool eof (void) const { return s ? s->eof () : true; }
00056
00057
00058
00059 std::string name (void) const { return nm; }
00060
00061 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; }
00062
00063 std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; }
00064
00065
00066 BUF_T *rdbuf (void) const
00067 { return s ? (const_cast<STREAM_T *> (s))->rdbuf () : 0; }
00068
00069 int file_number (void) const { return fnum; }
00070
00071 bool bad (void) const { return s ? s->bad () : true; }
00072
00073 void clear (void) { if (s) s->clear (); }
00074
00075 void do_close (void) { if (s) s->stream_close (); }
00076
00077 protected:
00078
00079 std::string nm;
00080
00081 std::ios::openmode md;
00082
00083 STREAM_T *s;
00084
00085
00086 int fnum;
00087
00088 ~octave_tstdiostream (void) { delete s; }
00089
00090 private:
00091
00092
00093
00094 octave_tstdiostream (const octave_tstdiostream&);
00095
00096 octave_tstdiostream& operator = (const octave_tstdiostream&);
00097 };
00098
00099 class
00100 octave_stdiostream
00101 : public octave_tstdiostream<c_file_ptr_buf, io_c_file_ptr_stream, FILE *>
00102 {
00103 public:
00104
00105 octave_stdiostream (const std::string& n, FILE *f = 0,
00106 std::ios::openmode m = std::ios::in|std::ios::out,
00107 oct_mach_info::float_format ff
00108 = oct_mach_info::native_float_format (),
00109 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::file_close)
00110 : octave_tstdiostream<c_file_ptr_buf, io_c_file_ptr_stream, FILE *> (n, f, f ? fileno (f) : -1, m, ff, cf) { }
00111
00112 static octave_stream
00113 create (const std::string& n, FILE *f = 0,
00114 std::ios::openmode m = std::ios::in|std::ios::out,
00115 oct_mach_info::float_format ff
00116 = oct_mach_info::native_float_format (),
00117 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::file_close)
00118 {
00119 return octave_stream (new octave_stdiostream (n, f, m, ff, cf));
00120 }
00121
00122 protected:
00123
00124 ~octave_stdiostream (void) { }
00125
00126 private:
00127
00128
00129
00130 octave_stdiostream (const octave_stdiostream&);
00131
00132 octave_stdiostream& operator = (const octave_stdiostream&);
00133 };
00134
00135 #ifdef HAVE_ZLIB
00136
00137 class
00138 octave_zstdiostream
00139 : public octave_tstdiostream<c_zfile_ptr_buf, io_c_zfile_ptr_stream, gzFile>
00140 {
00141 public:
00142
00143 octave_zstdiostream (const std::string& n, gzFile f = 0, int fid = 0,
00144 std::ios::openmode m = std::ios::in|std::ios::out,
00145 oct_mach_info::float_format ff
00146 = oct_mach_info::native_float_format (),
00147 c_zfile_ptr_buf::close_fcn cf = c_zfile_ptr_buf::file_close)
00148 : octave_tstdiostream<c_zfile_ptr_buf, io_c_zfile_ptr_stream, gzFile> (n, f, fid, m, ff, cf) { }
00149
00150 static octave_stream
00151 create (const std::string& n, gzFile f = 0, int fid = 0,
00152 std::ios::openmode m = std::ios::in|std::ios::out,
00153 oct_mach_info::float_format ff
00154 = oct_mach_info::native_float_format (),
00155 c_zfile_ptr_buf::close_fcn cf = c_zfile_ptr_buf::file_close)
00156 {
00157 return octave_stream (new octave_zstdiostream (n, f, fid, m, ff, cf));
00158 }
00159
00160 protected:
00161
00162 ~octave_zstdiostream (void) { }
00163
00164 private:
00165
00166
00167
00168 octave_zstdiostream (const octave_zstdiostream&);
00169
00170 octave_zstdiostream& operator = (const octave_zstdiostream&);
00171 };
00172
00173 #endif
00174
00175 #endif