GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_oct_strstrm_h)
27 #define octave_oct_strstrm_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 #include <sstream>
33 
34 #include "oct-stream.h"
35 
36 class
38 {
39 public:
40 
41  octave_base_strstream (std::ios::openmode m = std::ios::out,
44  const std::string& encoding = "utf-8")
45  : octave::base_stream (m, ff, encoding) { }
46 
47  // No copying!
48 
50 
51  octave_base_strstream& operator = (const octave_base_strstream&) = delete;
52 
53 protected:
54 
55  ~octave_base_strstream (void) = default;
56 
57 public:
58 
59  // Position a stream at OFFSET relative to ORIGIN.
60 
61  int seek (off_t, int);
62 
63  // Return current stream position.
64 
65  virtual off_t tell (void);
66 
67  // The name of the file.
68 
69  std::string name (void) const { return ""; }
70 
71  virtual std::streambuf * rdbuf (void) = 0;
72 
73  virtual bool bad (void) const = 0;
74 
75  virtual void clear (void) = 0;
76 };
77 
78 class
80 {
81 public:
82 
83  octave_istrstream (const char *data,
84  std::ios::openmode arg_md = std::ios::out,
87  const std::string& encoding = "utf-8")
88  : octave_base_strstream (arg_md, ff, encoding), m_istream (data) { }
89 
90  octave_istrstream (const std::string& data,
91  std::ios::openmode arg_md = std::ios::out,
94  const std::string& encoding = "utf-8")
95  : octave_base_strstream (arg_md, ff, encoding), m_istream (data) { }
96 
97  // No copying!
98 
100 
101  octave_istrstream& operator = (const octave_istrstream&) = delete;
102 
103 protected:
104 
105  ~octave_istrstream (void) = default;
106 
107 public:
108 
109 
110  static octave::stream
111  create (const char *data, std::ios::openmode arg_md = std::ios::out,
114  const std::string& encoding = "utf-8");
115 
116  static octave::stream
117  create (const std::string& data, std::ios::openmode arg_md = std::ios::out,
120  const std::string& encoding = "utf-8");
121 
122  // Return nonzero if EOF has been reached on this stream.
123 
124  bool eof (void) const { return m_istream.eof (); }
125 
126  std::istream * input_stream (void) { return &m_istream; }
127 
128  std::ostream * output_stream (void) { return nullptr; }
129 
130  off_t tell (void) { return m_istream.tellg (); }
131 
132  std::streambuf * rdbuf (void)
133  {
134  return m_istream ? m_istream.rdbuf () : nullptr;
135  }
136 
137  bool bad (void) const { return m_istream.bad (); }
138 
139  void clear (void) { m_istream.clear (); }
140 
141 private:
142 
143  std::istringstream m_istream;
144 };
145 
146 class
148 {
149 public:
150 
151  octave_ostrstream (std::ios::openmode arg_md = std::ios::out,
154  const std::string& encoding = "utf-8")
155  : octave_base_strstream (arg_md, ff, encoding), m_ostream () { }
156 
157  // No copying!
158 
160 
161  octave_ostrstream& operator = (const octave_ostrstream&) = delete;
162 
163 protected:
164 
165  ~octave_ostrstream (void) = default;
166 
167 public:
168 
169  static octave::stream
170  create (std::ios::openmode arg_md = std::ios::out,
173  const std::string& encoding = "utf-8");
174 
175  // Return nonzero if EOF has been reached on this stream.
176 
177  bool eof (void) const { return m_ostream.eof (); }
178 
179  std::istream * input_stream (void) { return nullptr; }
180 
181  std::ostream * output_stream (void) { return &m_ostream; }
182 
183  std::string str (void) { return m_ostream.str (); }
184 
185  std::streambuf * rdbuf (void)
186  {
187  return m_ostream ? m_ostream.rdbuf () : nullptr;
188  }
189 
190  bool bad (void) const { return m_ostream.bad (); }
191 
192  void clear (void) { m_ostream.clear (); }
193 
194 private:
195 
196  std::ostringstream m_ostream;
197 };
198 
199 #endif
~octave_base_strstream(void)=default
virtual bool bad(void) const =0
virtual std::streambuf * rdbuf(void)=0
virtual void clear(void)=0
octave_base_strstream(std::ios::openmode m=std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), const std::string &encoding="utf-8")
Definition: oct-strstrm.h:41
octave_base_strstream(const octave_base_strstream &)=delete
std::string name(void) const
Definition: oct-strstrm.h:69
void clear(void)
Definition: oct-strstrm.h:139
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(), const std::string &encoding="utf-8")
Definition: oct-strstrm.h:83
bool eof(void) const
Definition: oct-strstrm.h:124
std::ostream * output_stream(void)
Definition: oct-strstrm.h:128
off_t tell(void)
Definition: oct-strstrm.h:130
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(), const std::string &encoding="utf-8")
Definition: oct-strstrm.h:90
std::streambuf * rdbuf(void)
Definition: oct-strstrm.h:132
bool bad(void) const
Definition: oct-strstrm.h:137
octave_istrstream(const octave_istrstream &)=delete
~octave_istrstream(void)=default
std::istringstream m_istream
Definition: oct-strstrm.h:143
std::istream * input_stream(void)
Definition: oct-strstrm.h:126
std::ostringstream m_ostream
Definition: oct-strstrm.h:196
std::string str(void)
Definition: oct-strstrm.h:183
~octave_ostrstream(void)=default
octave_ostrstream(const octave_ostrstream &)=delete
octave_ostrstream(std::ios::openmode arg_md=std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), const std::string &encoding="utf-8")
Definition: oct-strstrm.h:151
std::streambuf * rdbuf(void)
Definition: oct-strstrm.h:185
std::istream * input_stream(void)
Definition: oct-strstrm.h:179
void clear(void)
Definition: oct-strstrm.h:192
std::ostream * output_stream(void)
Definition: oct-strstrm.h:181
bool eof(void) const
Definition: oct-strstrm.h:177
bool bad(void) const
Definition: oct-strstrm.h:190
T octave_idx_type m
Definition: mx-inlines.cc:773
float_format native_float_format(void)
Definition: mach-info.cc:65