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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2081
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_octave_strstream_h) |
|
25 #define octave_octave_strstream_h 1 |
|
26 |
2445
|
27 #include <string> |
|
28 |
4051
|
29 #include "lo-sstream.h" |
|
30 |
2081
|
31 #include "oct-stream.h" |
|
32 |
|
33 class |
|
34 octave_base_strstream : public octave_base_stream |
|
35 { |
|
36 public: |
|
37 |
4587
|
38 octave_base_strstream (std::ios::openmode m = std::ios::out, |
5015
|
39 oct_mach_info::float_format ff |
|
40 = oct_mach_info::native_float_format ()) |
4587
|
41 : octave_base_stream (m, ff) { } |
2081
|
42 |
|
43 // Position a stream at OFFSET relative to ORIGIN. |
|
44 |
4933
|
45 int seek (long, int); |
2081
|
46 |
|
47 // Return current stream position. |
|
48 |
4797
|
49 long tell (void); |
2081
|
50 |
|
51 // The name of the file. |
|
52 |
3523
|
53 std::string name (void) const { return std::string (); } |
2081
|
54 |
3523
|
55 virtual std::streambuf *rdbuf (void) = 0; |
2081
|
56 |
|
57 virtual bool bad (void) const = 0; |
|
58 |
|
59 virtual void clear (void) = 0; |
|
60 |
3340
|
61 protected: |
|
62 |
|
63 ~octave_base_strstream (void) { } |
|
64 |
2081
|
65 private: |
|
66 |
|
67 // No copying! |
|
68 |
|
69 octave_base_strstream (const octave_base_strstream&); |
|
70 |
|
71 octave_base_strstream& operator = (const octave_base_strstream&); |
|
72 }; |
|
73 |
|
74 class |
|
75 octave_istrstream : public octave_base_strstream |
|
76 { |
|
77 public: |
|
78 |
|
79 octave_istrstream (const char *data, |
3538
|
80 std::ios::openmode arg_md = std::ios::out, |
5015
|
81 oct_mach_info::float_format ff |
|
82 = oct_mach_info::native_float_format ()) |
4587
|
83 : octave_base_strstream (arg_md, ff), is (data) { } |
2081
|
84 |
3523
|
85 octave_istrstream (const std::string& data, |
3538
|
86 std::ios::openmode arg_md = std::ios::out, |
5015
|
87 oct_mach_info::float_format ff |
|
88 = oct_mach_info::native_float_format ()) |
4587
|
89 : octave_base_strstream (arg_md, ff), is (data.c_str ()) { } |
2081
|
90 |
3340
|
91 static octave_stream |
3538
|
92 create (const char *data, std::ios::openmode arg_md = std::ios::out, |
5015
|
93 oct_mach_info::float_format ff |
|
94 = oct_mach_info::native_float_format ()); |
3340
|
95 |
|
96 static octave_stream |
3538
|
97 create (const std::string& data, std::ios::openmode arg_md = std::ios::out, |
5015
|
98 oct_mach_info::float_format ff |
|
99 = oct_mach_info::native_float_format ()); |
2081
|
100 |
|
101 // Return non-zero if EOF has been reached on this stream. |
|
102 |
|
103 bool eof (void) const { return is.eof (); } |
|
104 |
3523
|
105 std::istream *input_stream (void) { return &is; } |
2081
|
106 |
3523
|
107 std::ostream *output_stream (void) { return 0; } |
2081
|
108 |
3523
|
109 std::streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; } |
2081
|
110 |
|
111 bool bad (void) const { return is.bad (); } |
|
112 |
|
113 void clear (void) { is.clear (); } |
|
114 |
3340
|
115 protected: |
|
116 |
|
117 ~octave_istrstream (void) { } |
|
118 |
2081
|
119 private: |
|
120 |
4051
|
121 ISSTREAM is; |
2081
|
122 |
|
123 // No copying! |
|
124 |
|
125 octave_istrstream (const octave_istrstream&); |
|
126 |
|
127 octave_istrstream& operator = (const octave_istrstream&); |
|
128 }; |
|
129 |
|
130 class |
|
131 octave_ostrstream : public octave_base_strstream |
|
132 { |
|
133 public: |
|
134 |
3538
|
135 octave_ostrstream (std::ios::openmode arg_md = std::ios::out, |
5015
|
136 oct_mach_info::float_format ff |
|
137 = oct_mach_info::native_float_format ()) |
4587
|
138 : octave_base_strstream (arg_md, ff) { } |
2081
|
139 |
3340
|
140 static octave_stream |
3538
|
141 create (std::ios::openmode arg_md = std::ios::out, |
5015
|
142 oct_mach_info::float_format ff |
|
143 = oct_mach_info::native_float_format ()); |
2081
|
144 |
|
145 // Return non-zero if EOF has been reached on this stream. |
|
146 |
|
147 bool eof (void) const { return os.eof (); } |
|
148 |
3523
|
149 std::istream *input_stream (void) { return 0; } |
2081
|
150 |
3523
|
151 std::ostream *output_stream (void) { return &os; } |
2081
|
152 |
3523
|
153 std::string str (void) |
2081
|
154 { |
4051
|
155 os << OSSTREAM_ENDS; |
|
156 std::string retval = OSSTREAM_STR (os); |
|
157 OSSTREAM_FREEZE (os); |
3340
|
158 return retval; |
2081
|
159 } |
|
160 |
3523
|
161 std::streambuf *rdbuf (void) { return os ? os.rdbuf () : 0; } |
2081
|
162 |
|
163 bool bad (void) const { return os.bad (); } |
|
164 |
|
165 void clear (void) { os.clear (); } |
|
166 |
3340
|
167 protected: |
|
168 |
|
169 ~octave_ostrstream (void) { } |
|
170 |
2081
|
171 private: |
|
172 |
4051
|
173 OSSTREAM os; |
2081
|
174 |
|
175 // No copying! |
|
176 |
|
177 octave_ostrstream (const octave_ostrstream&); |
|
178 |
|
179 octave_ostrstream& operator = (const octave_ostrstream&); |
|
180 }; |
|
181 |
|
182 #endif |
|
183 |
|
184 /* |
|
185 ;;; Local Variables: *** |
|
186 ;;; mode: C++ *** |
|
187 ;;; End: *** |
|
188 */ |