26 #if ! defined (octave_oct_stream_h)
27 #define octave_oct_stream_h 1
29 #include "octave-config.h"
74 base_stream (std::ios::openmode arg_md = std::ios::in | std::ios::out,
76 const std::string&
encoding =
"utf-8")
77 : m_mode (arg_md), m_flt_fmt (ff), m_encoding (
encoding),
78 m_conv_ostream (nullptr), m_fail (false), m_open_state (true),
95 virtual int seek (off_t offset,
int origin) = 0;
99 virtual off_t
tell (
void) = 0;
103 virtual bool eof (
void)
const = 0;
107 virtual std::string
name (
void)
const = 0;
126 if (! m_encoding.compare (
"utf-8"))
130 return m_conv_ostream;
137 std::wbuffer_convert<convfacet_u8, char> *converter
138 =
new std::wbuffer_convert<convfacet_u8, char> (os->rdbuf (),
140 m_conv_ostream =
new std::ostream (converter);
148 bool is_open (
void)
const {
return m_open_state; }
156 m_open_state =
false;
165 if (
name () ==
"stdin")
167 else if (
name () ==
"stdout")
169 else if (
name () ==
"stderr")
175 bool ok (
void)
const {
return ! m_fail; }
179 std::string
error (
bool clear,
int& err_num);
183 int mode (
void)
const {
return m_mode; }
187 std::string
encoding (
void)
const {
return m_encoding; }
191 OCTINTERP_API
void error (
const std::string& msg);
192 OCTINTERP_API
void error (
const std::string& who,
const std::string& msg);
196 OCTINTERP_API
void clear (
void);
239 OCTINTERP_API std::string
241 const std::string& who );
243 OCTINTERP_API std::string
245 const std::string& who );
246 OCTINTERP_API std::string
248 const std::string& who );
250 skipl (off_t count,
bool& err,
const std::string& who );
263 const std::string& who );
266 oscanf (
const std::string& fmt,
const std::string& who );
276 OCTINTERP_API
int flush (
void);
280 int nsa,
int sa_1,
int sa_2,
282 const std::string& who);
284 OCTINTERP_API
void field_width_error (
const std::string& who)
const;
288 const std::string& who );
292 const std::string& who );
295 puts (
const std::string& s,
const std::string& who );
319 OCTINTERP_API
int flush (
void);
321 OCTINTERP_API std::string
323 const std::string& who );
325 OCTINTERP_API std::string
327 const std::string& who );
329 OCTINTERP_API std::string
331 const std::string& who );
333 OCTINTERP_API std::string
335 const std::string& who );
338 skipl (off_t count,
bool& err,
const std::string& who );
342 const std::string& who );
344 OCTINTERP_API
int seek (off_t offset,
int origin);
349 OCTINTERP_API off_t
tell (
void);
351 OCTINTERP_API
int rewind (
void);
353 OCTINTERP_API
bool is_open (
void)
const;
355 OCTINTERP_API
void close (
void);
369 OCTINTERP_API
bool write_bytes (
const void *data, std::size_t n_elts);
371 OCTINTERP_API
bool skip_bytes (std::size_t n_elts);
373 template <
typename T>
388 oscanf (
const std::string& fmt,
const std::string& who );
400 const std::string& who );
404 const std::string& who );
407 puts (
const std::string& s,
const std::string& who );
411 OCTINTERP_API
bool eof (
void)
const;
413 OCTINTERP_API std::string
error (
bool clear,
int& err_num);
415 std::string
error (
bool clear =
false)
418 return error (clear, err_num);
437 operator bool ()
const {
return ok (); }
439 OCTINTERP_API std::string
name (
void)
const;
441 OCTINTERP_API
int mode (
void)
const;
449 return m_rep ?
m_rep->encoding () : std::string ();
454 return m_rep ?
m_rep->input_stream () :
nullptr;
459 return (
m_rep ?
m_rep->preferred_output_stream () :
nullptr);
487 m_rep->invalid_operation (who, rw);
513 OCTINTERP_API
int insert (
stream& os);
515 OCTINTERP_API
stream lookup (
int fid,
const std::string& who =
"")
const;
519 OCTINTERP_API
int remove (
int fid,
const std::string& who =
"");
521 const std::string& who =
"");
523 OCTINTERP_API
void clear (
bool flush =
true);
528 OCTINTERP_API std::string list_open_files (
void)
const;
530 OCTINTERP_API
octave_value open_file_numbers (
void)
const;
532 OCTINTERP_API
int get_file_number (
const octave_value& fid)
const;
octave_idx_type lookup(const T *x, octave_idx_type n, T y)
base_stream(const base_stream &)=delete
virtual int file_number(void) const
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 ~base_stream(void)=default
std::ostream * m_conv_ostream
virtual std::string name(void) const =0
mach_info::float_format float_format(void) const
virtual off_t tell(void)=0
virtual int seek(off_t offset, int origin)=0
virtual bool eof(void) const =0
virtual void do_close(void)
virtual std::istream * input_stream(void)
virtual std::ostream * output_stream(void)
std::ostream * preferred_output_stream(void)
mach_info::float_format m_flt_fmt
std::string encoding(void) const
string::deletable_facet< string::codecvt_u8 > convfacet_u8
std::map< int, stream > ostrl_map
ostrl_map::const_iterator m_lookup_cache
stream_list(const stream_list &)=delete
std::string error(bool clear=false)
OCTINTERP_API octave_value finalize_read(std::list< void * > &input_buf_list, octave_idx_type input_buf_elts, octave_idx_type elts_read, octave_idx_type nr, octave_idx_type nc, oct_data_conv::data_type input_type, oct_data_conv::data_type output_type, mach_info::float_format ffmt)
void error(const std::string &msg)
static OCTINTERP_API std::string mode_as_string(int mode)
stream & operator=(const stream &)=default
OCTINTERP_API octave_value scanf(const std::string &fmt, const Array< double > &size, octave_idx_type &count, const std::string &who)
std::istream * input_stream(void)
OCTINTERP_API std::string gets(octave_idx_type max_len, bool &err, const std::string &who)
std::ostream * output_stream(void)
bool is_valid(void) const
OCTINTERP_API bool skip_bytes(std::size_t n_elts)
OCTINTERP_API bool eof(void) const
OCTINTERP_API int rewind(void)
OCTINTERP_API std::string name(void) const
bool stream_ok(bool clear=true) const
std::shared_ptr< base_stream > m_rep
OCTINTERP_API off_t skipl(off_t count, bool &err, const std::string &who)
OCTINTERP_API octave_value textscan(const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, const std::string &who, octave_idx_type &count)
stream(base_stream *bs=nullptr)
OCTINTERP_API int puts(const std::string &s, const std::string &who)
OCTINTERP_API int printf(const std::string &fmt, const octave_value_list &args, const std::string &who)
OCTINTERP_API octave_idx_type write(const Array< T > &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
void error(const char *msg)
OCTINTERP_API int flush(void)
OCTINTERP_API bool write_bytes(const void *data, std::size_t n_elts)
OCTINTERP_API bool is_open(void) const
OCTINTERP_API int mode(void) const
OCTINTERP_API int seek(off_t offset, int origin)
void invalid_operation(const std::string &who, const char *rw)
stream(const stream &)=default
OCTINTERP_API octave_value_list oscanf(const std::string &fmt, const std::string &who)
OCTINTERP_API off_t tell(void)
OCTINTERP_API std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
std::string encoding(void)
OCTINTERP_API void close(void)
OCTINTERP_API octave_value read(const Array< double > &size, octave_idx_type block_size, oct_data_conv::data_type input_type, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt, octave_idx_type &count)
OCTINTERP_API octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
float_format native_float_format(void)