72 base_stream (std::ios::openmode arg_md = std::ios::in | std::ios::out,
73 mach_info::float_format ff = mach_info::native_float_format (),
74 const std::string& encoding =
"utf-8")
75 : m_mode (arg_md), m_flt_fmt (ff), m_encoding (encoding),
76 m_conv_ostream (nullptr), m_fail (false), m_open_state (true),
89 virtual
int seek (off_t offset,
int origin) = 0;
93 virtual off_t tell () = 0;
97 virtual
bool eof () const = 0;
101 virtual std::
string name () const = 0;
107 virtual std::
istream * input_stream () {
return nullptr; }
120 if (! m_encoding.compare (
"utf-8"))
121 return output_stream ();
124 return m_conv_ostream.get ();
127 std::ostream *os = output_stream ();
133 = std::unique_ptr<std::wbuffer_convert<convfacet_u8, char>>
134 (
new std::wbuffer_convert<convfacet_u8, char>
135 (os->rdbuf (),
new convfacet_u8 (m_encoding)));
136 m_conv_ostream = std::unique_ptr<std::ostream>
137 (
new std::ostream (m_converter.get ()));
140 return (m_conv_ostream ? m_conv_ostream.get () : output_stream ());
145 bool is_open ()
const {
return m_open_state; }
153 m_open_state =
false;
162 if (name () ==
"stdin")
164 else if (name () ==
"stdout")
166 else if (name () ==
"stderr")
172 bool ok ()
const {
return ! m_fail; }
176 std::string
error (
bool clear,
int& err_num);
180 int mode ()
const {
return m_mode; }
184 std::string
encoding ()
const {
return m_encoding; }
188 OCTINTERP_API
void error (
const std::string& msg);
189 OCTINTERP_API
void error (
const std::string& who,
const std::string& msg);
193 OCTINTERP_API
void clear ();
197 OCTINTERP_API
void clearerr ();
206 mach_info::float_format m_flt_fmt;
209 std::string m_encoding;
212 typedef string::deletable_facet<string::codecvt_u8> convfacet_u8;
214 std::unique_ptr<std::wbuffer_convert<convfacet_u8, char>> m_converter;
219 std::unique_ptr<std::ostream> m_conv_ostream;
228 std::string m_errmsg;
233 OCTINTERP_API std::string
235 const std::string& who );
237 OCTINTERP_API std::string
239 const std::string& who );
240 OCTINTERP_API std::string
242 const std::string& who );
244 skipl (off_t count,
bool& err,
const std::string& who );
257 const std::string& who );
260 oscanf (
const std::string& fmt,
const std::string& who );
270 OCTINTERP_API
int flush ();
273 do_numeric_printf_conv (std::ostream& os,
const printf_format_elt *elt,
274 int nsa,
int sa_1,
int sa_2,
276 const std::string& who);
278 OCTINTERP_API
void field_width_error (
const std::string& who)
const;
282 const std::string& who );
286 const std::string& who );
289 puts (
const std::string& s,
const std::string& who );
295 invalid_operation (
const std::string& who,
const char *rw);
311 OCTINTERP_API
int flush ();
313 OCTINTERP_API std::string
315 const std::string& who );
317 OCTINTERP_API std::string
319 const std::string& who );
321 OCTINTERP_API std::string
323 const std::string& who );
325 OCTINTERP_API std::string
327 const std::string& who );
330 skipl (off_t count,
bool& err,
const std::string& who );
334 const std::string& who );
336 OCTINTERP_API
int seek (off_t offset,
int origin);
341 OCTINTERP_API off_t tell ();
343 OCTINTERP_API
int rewind ();
345 OCTINTERP_API
bool is_open ()
const;
347 OCTINTERP_API
void close ();
361 OCTINTERP_API
bool write_bytes (
const void *data, std::size_t n_elts);
363 OCTINTERP_API
bool skip_bytes (std::size_t n_elts);
365 template <
typename T>
380 oscanf (
const std::string& fmt,
const std::string& who );
383 oscanf (
const octave_value& fmt,
const std::string& who );
392 const std::string& who );
396 const std::string& who );
399 puts (
const std::string& s,
const std::string& who );
403 OCTINTERP_API
bool eof ()
const;
405 OCTINTERP_API std::string
error (
bool clear,
int& err_num);
407 std::string
error (
bool clear =
false)
410 return error (clear, err_num);
427 bool ok ()
const {
return m_rep && m_rep->ok (); }
429 operator bool ()
const {
return ok (); }
431 OCTINTERP_API std::string name ()
const;
433 OCTINTERP_API
int mode ()
const;
435 OCTINTERP_API mach_info::float_format
float_format ()
const;
437 OCTINTERP_API
static std::string mode_as_string (
int mode);
441 return m_rep ? m_rep->encoding () : std::string ();
446 return m_rep ? m_rep->input_stream () :
nullptr;
451 return (m_rep ? m_rep->output_stream () :
nullptr);
457 return (m_rep ? m_rep->preferred_output_stream () :
nullptr);
460 void clearerr () {
if (m_rep) m_rep->clearerr (); }
465 std::shared_ptr<base_stream> m_rep;
467 bool stream_ok (
bool clear =
true)
const
482 void invalid_operation (
const std::string& who,
const char *rw)
485 m_rep->invalid_operation (who, rw);
489 finalize_read (std::list<void *>& input_buf_list,
495 mach_info::float_format ffmt);