GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-strstrm.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_oct_strstrm_h)
24 #define octave_oct_strstrm_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 #include <sstream>
30 
31 #include "oct-stream.h"
32 
33 class
35 {
36 public:
37 
38  octave_base_strstream (std::ios::openmode m = std::ios::out,
41  : octave::base_stream (m, ff) { }
42 
43  // No copying!
44 
46 
47  octave_base_strstream& operator = (const octave_base_strstream&) = delete;
48 
49 protected:
50 
51  ~octave_base_strstream (void) = default;
52 
53 public:
54 
55  // Position a stream at OFFSET relative to ORIGIN.
56 
57  int seek (off_t, int);
58 
59  // Return current stream position.
60 
61  virtual off_t tell (void);
62 
63  // The name of the file.
64 
65  std::string name (void) const { return ""; }
66 
67  virtual std::streambuf * rdbuf (void) = 0;
68 
69  virtual bool bad (void) const = 0;
70 
71  virtual void clear (void) = 0;
72 };
73 
74 class
76 {
77 public:
78 
79  octave_istrstream (const char *data,
80  std::ios::openmode arg_md = std::ios::out,
83  : octave_base_strstream (arg_md, ff), is (data) { }
84 
86  std::ios::openmode arg_md = std::ios::out,
89  : octave_base_strstream (arg_md, ff), is (data) { }
90 
91  // No copying!
92 
93  octave_istrstream (const octave_istrstream&) = delete;
94 
95  octave_istrstream& operator = (const octave_istrstream&) = delete;
96 
97 protected:
98 
99  ~octave_istrstream (void) = default;
100 
101 public:
102 
103 
104  static octave::stream
105  create (const char *data, std::ios::openmode arg_md = std::ios::out,
108 
109  static octave::stream
110  create (const std::string& data, std::ios::openmode arg_md = std::ios::out,
113 
114  // Return nonzero if EOF has been reached on this stream.
115 
116  bool eof (void) const { return is.eof (); }
117 
118  std::istream * input_stream (void) { return &is; }
119 
120  std::ostream * output_stream (void) { return nullptr; }
121 
122  off_t tell (void) { return is.tellg (); }
123 
124  std::streambuf * rdbuf (void) { return is ? is.rdbuf () : nullptr; }
125 
126  bool bad (void) const { return is.bad (); }
127 
128  void clear (void) { is.clear (); }
129 
130 private:
131 
132  std::istringstream is;
133 };
134 
135 class
137 {
138 public:
139 
140  octave_ostrstream (std::ios::openmode arg_md = std::ios::out,
143  : octave_base_strstream (arg_md, ff), os () { }
144 
145  // No copying!
146 
147  octave_ostrstream (const octave_ostrstream&) = delete;
148 
149  octave_ostrstream& operator = (const octave_ostrstream&) = delete;
150 
151 protected:
152 
153  ~octave_ostrstream (void) = default;
154 
155 public:
156 
157  static octave::stream
158  create (std::ios::openmode arg_md = std::ios::out,
161 
162  // Return nonzero if EOF has been reached on this stream.
163 
164  bool eof (void) const { return os.eof (); }
165 
166  std::istream * input_stream (void) { return nullptr; }
167 
168  std::ostream * output_stream (void) { return &os; }
169 
170  std::string str (void) { return os.str (); }
171 
172  std::streambuf * rdbuf (void) { return os ? os.rdbuf () : nullptr; }
173 
174  bool bad (void) const { return os.bad (); }
175 
176  void clear (void) { os.clear (); }
177 
178 private:
179 
180  std::ostringstream os;
181 };
182 
183 #endif
std::streambuf * rdbuf(void)
Definition: oct-strstrm.h:172
bool eof(void) const
Definition: oct-strstrm.h:164
bool bad(void) const
Definition: oct-strstrm.h:174
octave_ostrstream(std::ios::openmode arg_md=std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format())
Definition: oct-strstrm.h:140
std::string str(void)
Definition: oct-strstrm.h:170
void clear(void)
Definition: oct-strstrm.h:176
octave_istrstream(const char *data, std::ios::openmode arg_md=std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format())
Definition: oct-strstrm.h:79
std::streambuf * rdbuf(void)
Definition: oct-strstrm.h:124
octave_base_strstream(std::ios::openmode m=std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format())
Definition: oct-strstrm.h:38
off_t tell(void)
Definition: oct-strstrm.h:122
float_format native_float_format(void)
Definition: mach-info.cc:62
bool eof(void) const
Definition: oct-strstrm.h:116
std::istringstream is
Definition: oct-strstrm.h:132
octave_istrstream(const std::string &data, std::ios::openmode arg_md=std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format())
Definition: oct-strstrm.h:85
std::istream * input_stream(void)
Definition: oct-strstrm.h:166
std::ostream * output_stream(void)
Definition: oct-strstrm.h:120
void clear(void)
Definition: oct-strstrm.h:128
std::string name(void) const
Definition: oct-strstrm.h:65
std::ostream * output_stream(void)
Definition: oct-strstrm.h:168
std::ostringstream os
Definition: oct-strstrm.h:180
write the output to stdout if nargout is
Definition: load-save.cc:1612
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
octave::stream os
Definition: file-io.cc:627
bool eof(void) const
Definition: oct-stream.cc:7194
bool bad(void) const
Definition: oct-strstrm.h:126
std::istream * input_stream(void)
Definition: oct-strstrm.h:118