GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-strstrm.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any 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, see
19 <http://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  // Position a stream at OFFSET relative to ORIGIN.
44 
45  int seek (off_t, int);
46 
47  // Return current stream position.
48 
49  virtual off_t tell (void);
50 
51  // The name of the file.
52 
53  std::string name (void) const { return ""; }
54 
55  virtual std::streambuf *rdbuf (void) = 0;
56 
57  virtual bool bad (void) const = 0;
58 
59  virtual void clear (void) = 0;
60 
61 protected:
62 
64 
65 private:
66 
67  // No copying!
68 
70 
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.c_str ()) { }
90 
91  static octave_stream
92  create (const char *data, std::ios::openmode arg_md = std::ios::out,
95 
96  static octave_stream
97  create (const std::string& data, std::ios::openmode arg_md = std::ios::out,
100 
101  // Return nonzero if EOF has been reached on this stream.
102 
103  bool eof (void) const { return is.eof (); }
104 
105  std::istream *input_stream (void) { return &is; }
106 
107  std::ostream *output_stream (void) { return 0; }
108 
109  off_t tell (void) { return is.tellg (); }
110 
111  std::streambuf *rdbuf (void) { return is ? is.rdbuf () : 0; }
112 
113  bool bad (void) const { return is.bad (); }
114 
115  void clear (void) { is.clear (); }
116 
117 protected:
118 
120 
121 private:
122 
123  std::istringstream is;
124 
125  // No copying!
126 
128 
130 };
131 
132 class
134 {
135 public:
136 
137  octave_ostrstream (std::ios::openmode arg_md = std::ios::out,
140  : octave_base_strstream (arg_md, ff), os () { }
141 
142  static octave_stream
143  create (std::ios::openmode arg_md = std::ios::out,
146 
147  // Return nonzero if EOF has been reached on this stream.
148 
149  bool eof (void) const { return os.eof (); }
150 
151  std::istream *input_stream (void) { return 0; }
152 
153  std::ostream *output_stream (void) { return &os; }
154 
155  std::string str (void) { return os.str (); }
156 
157  std::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 
163 protected:
164 
166 
167 private:
168 
169  std::ostringstream os;
170 
171  // No copying!
172 
174 
176 };
177 
178 #endif
std::streambuf * rdbuf(void)
Definition: oct-strstrm.h:157
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:137
std::string str(void)
Definition: oct-strstrm.h:155
int seek(off_t offset, int origin)
Definition: oct-stream.cc:6061
void clear(void)
Definition: oct-strstrm.h:161
~octave_istrstream(void)
Definition: oct-strstrm.h:119
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:111
bool eof(void) const
Definition: oct-strstrm.h:103
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
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
off_t tell(void)
Definition: oct-strstrm.h:109
bool bad(void) const
Definition: oct-strstrm.h:113
std::istringstream is
Definition: oct-strstrm.h:123
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:151
off_t tell(void)
Definition: oct-stream.cc:6178
std::string name(void) const
Definition: oct-strstrm.h:53
static float_format native_float_format(void)
Definition: mach-info.cc:162
std::ostream * output_stream(void)
Definition: oct-strstrm.h:107
void clear(void)
Definition: oct-strstrm.h:115
octave_stream & operator=(const octave_stream &)
Definition: oct-stream.cc:5922
std::ostream * output_stream(void)
Definition: oct-strstrm.h:153
bool eof(void) const
Definition: oct-strstrm.h:149
bool bad(void) const
Definition: oct-strstrm.h:159
std::ostringstream os
Definition: oct-strstrm.h:169
~octave_ostrstream(void)
Definition: oct-strstrm.h:165
write the output to stdout if nargout is
Definition: load-save.cc:1576
static void clear(octave::dynamic_library &oct_file)
Definition: dynamic-ld.cc:230
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:854
std::istream * input_stream(void)
Definition: oct-strstrm.h:105