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_strstream_h)
00025 #define octave_octave_strstream_h 1
00026
00027 #include <string>
00028 #include <sstream>
00029
00030 #include "oct-stream.h"
00031
00032 class
00033 octave_base_strstream : public octave_base_stream
00034 {
00035 public:
00036
00037 octave_base_strstream (std::ios::openmode m = std::ios::out,
00038 oct_mach_info::float_format ff
00039 = oct_mach_info::native_float_format ())
00040 : octave_base_stream (m, ff) { }
00041
00042
00043
00044 int seek (long, int);
00045
00046
00047
00048 long tell (void);
00049
00050
00051
00052 std::string name (void) const { return std::string (); }
00053
00054 virtual std::streambuf *rdbuf (void) = 0;
00055
00056 virtual bool bad (void) const = 0;
00057
00058 virtual void clear (void) = 0;
00059
00060 protected:
00061
00062 ~octave_base_strstream (void) { }
00063
00064 private:
00065
00066
00067
00068 octave_base_strstream (const octave_base_strstream&);
00069
00070 octave_base_strstream& operator = (const octave_base_strstream&);
00071 };
00072
00073 class
00074 octave_istrstream : public octave_base_strstream
00075 {
00076 public:
00077
00078 octave_istrstream (const char *data,
00079 std::ios::openmode arg_md = std::ios::out,
00080 oct_mach_info::float_format ff
00081 = oct_mach_info::native_float_format ())
00082 : octave_base_strstream (arg_md, ff), is (data) { }
00083
00084 octave_istrstream (const std::string& data,
00085 std::ios::openmode arg_md = std::ios::out,
00086 oct_mach_info::float_format ff
00087 = oct_mach_info::native_float_format ())
00088 : octave_base_strstream (arg_md, ff), is (data.c_str ()) { }
00089
00090 static octave_stream
00091 create (const char *data, std::ios::openmode arg_md = std::ios::out,
00092 oct_mach_info::float_format ff
00093 = oct_mach_info::native_float_format ());
00094
00095 static octave_stream
00096 create (const std::string& data, std::ios::openmode arg_md = std::ios::out,
00097 oct_mach_info::float_format ff
00098 = oct_mach_info::native_float_format ());
00099
00100
00101
00102 bool eof (void) const { return is.eof (); }
00103
00104 std::istream *input_stream (void) { return &is; }
00105
00106 std::ostream *output_stream (void) { return 0; }
00107
00108 std::streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; }
00109
00110 bool bad (void) const { return is.bad (); }
00111
00112 void clear (void) { is.clear (); }
00113
00114 protected:
00115
00116 ~octave_istrstream (void) { }
00117
00118 private:
00119
00120 std::istringstream is;
00121
00122
00123
00124 octave_istrstream (const octave_istrstream&);
00125
00126 octave_istrstream& operator = (const octave_istrstream&);
00127 };
00128
00129 class
00130 octave_ostrstream : public octave_base_strstream
00131 {
00132 public:
00133
00134 octave_ostrstream (std::ios::openmode arg_md = std::ios::out,
00135 oct_mach_info::float_format ff
00136 = oct_mach_info::native_float_format ())
00137 : octave_base_strstream (arg_md, ff) { }
00138
00139 static octave_stream
00140 create (std::ios::openmode arg_md = std::ios::out,
00141 oct_mach_info::float_format ff
00142 = oct_mach_info::native_float_format ());
00143
00144
00145
00146 bool eof (void) const { return os.eof (); }
00147
00148 std::istream *input_stream (void) { return 0; }
00149
00150 std::ostream *output_stream (void) { return &os; }
00151
00152 std::string str (void) { return os.str (); }
00153
00154 std::streambuf *rdbuf (void) { return os ? os.rdbuf () : 0; }
00155
00156 bool bad (void) const { return os.bad (); }
00157
00158 void clear (void) { os.clear (); }
00159
00160 protected:
00161
00162 ~octave_ostrstream (void) { }
00163
00164 private:
00165
00166 std::ostringstream os;
00167
00168
00169
00170 octave_ostrstream (const octave_ostrstream&);
00171
00172 octave_ostrstream& operator = (const octave_ostrstream&);
00173 };
00174
00175 #endif
00176
00177
00178
00179
00180
00181