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 |
2445
|
26 #include <string> |
|
27 |
4051
|
28 #include "lo-sstream.h" |
|
29 |
2081
|
30 #include "oct-stream.h" |
|
31 |
|
32 class |
|
33 octave_base_strstream : public octave_base_stream |
|
34 { |
|
35 public: |
|
36 |
3538
|
37 octave_base_strstream (std::ios::openmode arg_md = std::ios::out, |
2317
|
38 oct_mach_info::float_format flt_fmt = |
4574
|
39 oct_mach_info::flt_fmt_native) |
2317
|
40 : octave_base_stream (arg_md, flt_fmt) { } |
2081
|
41 |
|
42 // Position a stream at OFFSET relative to ORIGIN. |
|
43 |
3775
|
44 int seek (std::streamoff offset, std::ios::seekdir origin); |
2081
|
45 |
|
46 // Return current stream position. |
|
47 |
|
48 long tell (void) const; |
|
49 |
|
50 // The name of the file. |
|
51 |
3523
|
52 std::string name (void) const { return std::string (); } |
2081
|
53 |
3523
|
54 virtual std::streambuf *rdbuf (void) = 0; |
2081
|
55 |
|
56 virtual bool bad (void) const = 0; |
|
57 |
|
58 virtual void clear (void) = 0; |
|
59 |
3340
|
60 protected: |
|
61 |
|
62 ~octave_base_strstream (void) { } |
|
63 |
2081
|
64 private: |
|
65 |
|
66 // No copying! |
|
67 |
|
68 octave_base_strstream (const octave_base_strstream&); |
|
69 |
|
70 octave_base_strstream& operator = (const octave_base_strstream&); |
|
71 }; |
|
72 |
|
73 class |
|
74 octave_istrstream : public octave_base_strstream |
|
75 { |
|
76 public: |
|
77 |
|
78 octave_istrstream (const char *data, |
3538
|
79 std::ios::openmode arg_md = std::ios::out, |
2317
|
80 oct_mach_info::float_format flt_fmt = |
4574
|
81 oct_mach_info::flt_fmt_native) |
2317
|
82 : octave_base_strstream (arg_md, flt_fmt), is (data) { } |
2081
|
83 |
3523
|
84 octave_istrstream (const std::string& data, |
3538
|
85 std::ios::openmode arg_md = std::ios::out, |
2317
|
86 oct_mach_info::float_format flt_fmt = |
4574
|
87 oct_mach_info::flt_fmt_native) |
2317
|
88 : octave_base_strstream (arg_md, flt_fmt), is (data.c_str ()) { } |
2081
|
89 |
3340
|
90 static octave_stream |
3538
|
91 create (const char *data, std::ios::openmode arg_md = std::ios::out, |
4574
|
92 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_native); |
3340
|
93 |
|
94 static octave_stream |
3538
|
95 create (const std::string& data, std::ios::openmode arg_md = std::ios::out, |
4574
|
96 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_native); |
2081
|
97 |
|
98 // Return non-zero if EOF has been reached on this stream. |
|
99 |
|
100 bool eof (void) const { return is.eof (); } |
|
101 |
3523
|
102 std::istream *input_stream (void) { return &is; } |
2081
|
103 |
3523
|
104 std::ostream *output_stream (void) { return 0; } |
2081
|
105 |
3523
|
106 std::streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; } |
2081
|
107 |
|
108 bool bad (void) const { return is.bad (); } |
|
109 |
|
110 void clear (void) { is.clear (); } |
|
111 |
3340
|
112 protected: |
|
113 |
|
114 ~octave_istrstream (void) { } |
|
115 |
2081
|
116 private: |
|
117 |
4051
|
118 ISSTREAM is; |
2081
|
119 |
|
120 // No copying! |
|
121 |
|
122 octave_istrstream (const octave_istrstream&); |
|
123 |
|
124 octave_istrstream& operator = (const octave_istrstream&); |
|
125 }; |
|
126 |
|
127 class |
|
128 octave_ostrstream : public octave_base_strstream |
|
129 { |
|
130 public: |
|
131 |
3538
|
132 octave_ostrstream (std::ios::openmode arg_md = std::ios::out, |
2317
|
133 oct_mach_info::float_format flt_fmt = |
4574
|
134 oct_mach_info::flt_fmt_native) |
2317
|
135 : octave_base_strstream (arg_md, flt_fmt) { } |
2081
|
136 |
3340
|
137 static octave_stream |
3538
|
138 create (std::ios::openmode arg_md = std::ios::out, |
4574
|
139 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_native); |
2081
|
140 |
|
141 // Return non-zero if EOF has been reached on this stream. |
|
142 |
|
143 bool eof (void) const { return os.eof (); } |
|
144 |
3523
|
145 std::istream *input_stream (void) { return 0; } |
2081
|
146 |
3523
|
147 std::ostream *output_stream (void) { return &os; } |
2081
|
148 |
3523
|
149 std::string str (void) |
2081
|
150 { |
4051
|
151 os << OSSTREAM_ENDS; |
|
152 std::string retval = OSSTREAM_STR (os); |
|
153 OSSTREAM_FREEZE (os); |
3340
|
154 return retval; |
2081
|
155 } |
|
156 |
3523
|
157 std::streambuf *rdbuf (void) { return os ? os.rdbuf () : 0; } |
2081
|
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 |
4051
|
169 OSSTREAM os; |
2081
|
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 */ |