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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_octave_strstream_h) |
|
24 #define octave_octave_strstream_h 1 |
|
25 |
3503
|
26 #include <strstream> |
2445
|
27 #include <string> |
|
28 |
2081
|
29 #include "oct-stream.h" |
|
30 |
|
31 class |
|
32 octave_base_strstream : public octave_base_stream |
|
33 { |
|
34 public: |
|
35 |
|
36 octave_base_strstream (ios::openmode arg_md = ios::out, |
2317
|
37 oct_mach_info::float_format flt_fmt = |
|
38 oct_mach_info::native) |
|
39 : octave_base_stream (arg_md, flt_fmt) { } |
2081
|
40 |
|
41 // Position a stream at OFFSET relative to ORIGIN. |
|
42 |
2610
|
43 int seek (streamoff offset, ios::seek_dir origin); |
2081
|
44 |
|
45 // Return current stream position. |
|
46 |
|
47 long tell (void) const; |
|
48 |
|
49 // The name of the file. |
|
50 |
3340
|
51 string name (void) const { return string (); } |
2081
|
52 |
|
53 virtual streambuf *rdbuf (void) = 0; |
|
54 |
|
55 virtual bool bad (void) const = 0; |
|
56 |
|
57 virtual void clear (void) = 0; |
|
58 |
3340
|
59 protected: |
|
60 |
|
61 ~octave_base_strstream (void) { } |
|
62 |
2081
|
63 private: |
|
64 |
|
65 // No copying! |
|
66 |
|
67 octave_base_strstream (const octave_base_strstream&); |
|
68 |
|
69 octave_base_strstream& operator = (const octave_base_strstream&); |
|
70 }; |
|
71 |
|
72 class |
|
73 octave_istrstream : public octave_base_strstream |
|
74 { |
|
75 public: |
|
76 |
|
77 octave_istrstream (const char *data, |
|
78 ios::openmode arg_md = ios::out, |
2317
|
79 oct_mach_info::float_format flt_fmt = |
|
80 oct_mach_info::native) |
|
81 : octave_base_strstream (arg_md, flt_fmt), is (data) { } |
2081
|
82 |
|
83 octave_istrstream (const string& data, |
|
84 ios::openmode arg_md = ios::out, |
2317
|
85 oct_mach_info::float_format flt_fmt = |
|
86 oct_mach_info::native) |
|
87 : octave_base_strstream (arg_md, flt_fmt), is (data.c_str ()) { } |
2081
|
88 |
3340
|
89 static octave_stream |
|
90 create (const char *data, ios::openmode arg_md = ios::out, |
|
91 oct_mach_info::float_format flt_fmt = oct_mach_info::native); |
|
92 |
|
93 static octave_stream |
|
94 create (const string& data, ios::openmode arg_md = ios::out, |
|
95 oct_mach_info::float_format flt_fmt = oct_mach_info::native); |
2081
|
96 |
|
97 // Return non-zero if EOF has been reached on this stream. |
|
98 |
|
99 bool eof (void) const { return is.eof (); } |
|
100 |
|
101 istream *input_stream (void) { return &is; } |
|
102 |
|
103 ostream *output_stream (void) { return 0; } |
|
104 |
|
105 streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; } |
|
106 |
|
107 bool bad (void) const { return is.bad (); } |
|
108 |
|
109 void clear (void) { is.clear (); } |
|
110 |
3340
|
111 protected: |
|
112 |
|
113 ~octave_istrstream (void) { } |
|
114 |
2081
|
115 private: |
|
116 |
|
117 istrstream is; |
|
118 |
|
119 // No copying! |
|
120 |
|
121 octave_istrstream (const octave_istrstream&); |
|
122 |
|
123 octave_istrstream& operator = (const octave_istrstream&); |
|
124 }; |
|
125 |
|
126 class |
|
127 octave_ostrstream : public octave_base_strstream |
|
128 { |
|
129 public: |
|
130 |
|
131 octave_ostrstream (ios::openmode arg_md = ios::out, |
2317
|
132 oct_mach_info::float_format flt_fmt = |
|
133 oct_mach_info::native) |
|
134 : octave_base_strstream (arg_md, flt_fmt) { } |
2081
|
135 |
3340
|
136 static octave_stream |
|
137 create (ios::openmode arg_md = ios::out, |
|
138 oct_mach_info::float_format flt_fmt = oct_mach_info::native); |
2081
|
139 |
|
140 // Return non-zero if EOF has been reached on this stream. |
|
141 |
|
142 bool eof (void) const { return os.eof (); } |
|
143 |
|
144 istream *input_stream (void) { return 0; } |
|
145 |
|
146 ostream *output_stream (void) { return &os; } |
|
147 |
3340
|
148 string str (void) |
2081
|
149 { |
|
150 os << ends; |
3340
|
151 char *tmp = os.str (); |
|
152 string retval = tmp; |
|
153 delete [] tmp; |
|
154 return retval; |
2081
|
155 } |
|
156 |
|
157 streambuf *rdbuf (void) { return os ? os.rdbuf () : 0; } |
|
158 |
|
159 bool bad (void) const { return os.bad (); } |
|
160 |
|
161 void clear (void) { os.clear (); } |
|
162 |
3340
|
163 protected: |
|
164 |
|
165 ~octave_ostrstream (void) { } |
|
166 |
2081
|
167 private: |
|
168 |
|
169 ostrstream os; |
|
170 |
|
171 // No copying! |
|
172 |
|
173 octave_ostrstream (const octave_ostrstream&); |
|
174 |
|
175 octave_ostrstream& operator = (const octave_ostrstream&); |
|
176 }; |
|
177 |
|
178 #endif |
|
179 |
|
180 /* |
|
181 ;;; Local Variables: *** |
|
182 ;;; mode: C++ *** |
|
183 ;;; End: *** |
|
184 */ |