26 #if ! defined (octave_oct_stream_h)
27 #define octave_oct_stream_h 1
29 #include "octave-config.h"
40 template <
typename T>
class Array;
56 class scanf_format_elt;
57 class scanf_format_list;
59 class printf_format_elt;
60 class printf_format_list;
72 base_stream (std::ios::openmode arg_md = std::ios::in | std::ios::out,
74 const std::string& encoding =
"utf-8")
75 : m_mode (arg_md), m_flt_fmt (ff), m_encoding (encoding),
76 m_fail (false), m_open_state (true), m_errmsg ()
92 virtual int seek (off_t offset,
int origin) = 0;
96 virtual off_t
tell (
void) = 0;
100 virtual bool eof (
void)
const = 0;
104 virtual std::string
name (
void)
const = 0;
120 bool is_open (
void)
const {
return m_open_state; }
128 m_open_state =
false;
137 if (
name () ==
"stdin")
139 else if (
name () ==
"stdout")
141 else if (
name () ==
"stderr")
147 bool ok (
void)
const {
return ! m_fail; }
151 std::string
error (
bool clear,
int& err_num);
155 int mode (
void)
const {
return m_mode; }
159 std::string
encoding (
void)
const {
return m_encoding; }
163 void error (
const std::string& msg);
164 void error (
const std::string& who,
const std::string& msg);
172 void clearerr (
void);
198 std::string do_gets (
octave_idx_type max_len,
bool& err,
bool strip_newline,
199 const std::string& who );
202 const std::string& who );
204 const std::string& who );
205 off_t skipl (off_t count,
bool& err,
const std::string& who );
210 const std::string& who );
216 const std::string& who );
219 const std::string& who );
231 int nsa,
int sa_1,
int sa_2,
233 const std::string& who);
235 void field_width_error (
const std::string& who)
const;
238 const std::string& who );
241 const std::string& who );
243 int puts (
const std::string& s,
const std::string& who );
248 void invalid_operation (
const std::string& who,
const char *rw);
269 const std::string& who );
270 std::string getl (
const octave_value& max_len,
bool& err,
271 const std::string& who );
274 const std::string& who );
275 std::string gets (
const octave_value& max_len,
bool& err,
276 const std::string& who );
278 off_t skipl (off_t count,
bool& err,
const std::string& who );
280 const std::string& who );
282 int seek (off_t offset,
int origin);
289 bool is_open (
void)
const;
304 bool write_bytes (
const void *data,
size_t n_elts);
306 bool skip_bytes (
size_t n_elts);
308 template <
typename T>
321 const std::string& who );
324 const std::string& who );
331 const std::string& who );
334 const std::string& who );
336 int puts (
const std::string& s,
const std::string& who );
337 int puts (
const octave_value& s,
const std::string& who );
339 bool eof (
void)
const;
341 std::string
error (
bool clear,
int& err_num);
343 std::string
error (
bool clear =
false)
346 return error (clear, err_num);
359 int file_number (
void) {
return m_rep ? m_rep->file_number () : -1; }
361 bool is_valid (
void)
const {
return bool (m_rep); }
363 bool ok (
void)
const {
return m_rep && m_rep->ok (); }
365 operator bool ()
const {
return ok (); }
367 std::string
name (
void)
const;
369 int mode (
void)
const;
373 static std::string mode_as_string (
int mode);
377 return m_rep ? m_rep->encoding () : std::string ();
382 return m_rep ? m_rep->input_stream () :
nullptr;
387 return m_rep ? m_rep->output_stream () :
nullptr;
390 void clearerr (
void) {
if (m_rep) m_rep->clearerr (); }
415 m_rep->invalid_operation (who, rw);
419 finalize_read (std::list<void *>& input_buf_list,
443 stream lookup (
int fid,
const std::string& who =
"")
const;
446 int remove (
int fid,
const std::string& who =
"");
447 int remove (
const octave_value& fid,
const std::string& who =
"");
449 void clear (
bool flush =
true);
454 std::string list_open_files (
void)
const;
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
N Dimensional Array with copy-on-write semantics.
virtual bool eof(void) const =0
virtual std::ostream * output_stream(void)
virtual void do_close(void)
virtual int seek(off_t offset, int origin)=0
mach_info::float_format float_format(void) const
mach_info::float_format m_flt_fmt
virtual std::istream * input_stream(void)
base_stream(const base_stream &)=delete
base_stream(std::ios::openmode arg_md=std::ios::in|std::ios::out, mach_info::float_format ff=mach_info::native_float_format(), const std::string &encoding="utf-8")
virtual std::string name(void) const =0
std::string encoding(void) const
virtual ~base_stream(void)=default
virtual off_t tell(void)=0
virtual int file_number(void) const
ostrl_map::const_iterator m_lookup_cache
std::map< int, stream > ostrl_map
stream_list(const stream_list &)=delete
void error(const std::string &msg)
void invalid_operation(const std::string &who, const char *rw)
std::istream * input_stream(void)
bool stream_ok(bool clear=true) const
std::shared_ptr< base_stream > m_rep
stream(base_stream *bs=nullptr)
std::ostream * output_stream(void)
bool is_valid(void) const
std::string encoding(void)
void error(const char *msg)
stream(const stream &)=default
std::string error(bool clear=false)
void error(const char *fmt,...)
float_format native_float_format(void)
octave_value::octave_value(const Array< char > &chm, char type) return retval