GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-stream.cc File Reference
#include <cassert>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <limits>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include "Array.h"
#include "Cell.h"
#include "byte-swap.h"
#include "lo-ieee.h"
#include "lo-mappers.h"
#include "lo-utils.h"
#include "oct-locbuf.h"
#include "octave-preserve-stream-state.h"
#include "quit.h"
#include "str-vec.h"
#include "strcase-wrappers.h"
#include "error.h"
#include "errwarn.h"
#include "input.h"
#include "interpreter-private.h"
#include "interpreter.h"
#include "octave.h"
#include "oct-iostrm.h"
#include "oct-stdstrm.h"
#include "oct-string.h"
#include "oct-stream.h"
#include "ov.h"
#include "ovl.h"
#include "pager.h"
#include "utils.h"
Include dependency graph for oct-stream.cc:

Go to the source code of this file.

Classes

class  delimited_stream
 
class  printf_format_elt
 
class  printf_format_list
 
class  printf_value_cache
 
class  scanf_format_elt
 
class  scanf_format_list
 
class  textscan
 
class  textscan_format_elt
 
class  textscan_format_list
 
class  ultimate_element_type< T >
 
class  ultimate_element_type< octave_int< T > >
 

Macros

#define BEGIN_C_CONVERSION()
 
#define BEGIN_CHAR_CLASS_CONVERSION()
 
#define BEGIN_S_CONVERSION()
 
#define DO_LITERAL_CONVERSION()
 
#define DO_PCT_CONVERSION()
 
#define DO_WHITESPACE_CONVERSION()
 
#define FILL_TABLE_ROW(T, V)
 
#define FINISH_CHARACTER_CONVERSION()
 
#define INSTANTIATE_WRITE(T)
 
#define TABLE_ELT(T, U, V, W)    conv_fptr_table[oct_data_conv::T][oct_data_conv::U] = convert_and_copy<V, W>
 

Typedefs

typedef octave_value(* conv_fptr) (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, bool swap, bool do_float_fmt_conv, bool do_NA_conv, mach_info::float_format from_flt_fmt)
 

Functions

template<typename SRC_T , typename DST_T >
static octave_value convert_and_copy (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, bool swap, bool do_float_fmt_conv, bool do_NA_conv, mach_info::float_format from_flt_fmt)
 
template<typename T , typename V >
static void convert_chars (const void *data, void *conv_data, octave_idx_type n_elts)
 
template<typename T >
static bool convert_data (const T *data, void *conv_data, octave_idx_type n_elts, oct_data_conv::data_type output_type, mach_info::float_format flt_fmt)
 
template<typename T , typename V >
static void convert_ints (const T *data, void *conv_data, octave_idx_type n_elts, bool swap)
 
static int convert_to_valid_int (const octave_value &tc, int &conv_err)
 
template<typename T >
static int do_printf_conv (std::ostream &os, const char *fmt, int nsa, int sa_1, int sa_2, T arg, const std::string &who)
 
static std::size_t do_printf_string (std::ostream &os, const printf_format_elt *elt, int nsa, int sa_1, int sa_2, const std::string &arg, const std::string &who)
 
template void do_scanf_conv (std::istream &, const scanf_format_elt &, double *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
 
template<typename T >
static void do_scanf_conv (std::istream &is, const scanf_format_elt &fmt, T valptr, Matrix &mval, double *data, octave_idx_type &idx, octave_idx_type &conversion_count, octave_idx_type nr, octave_idx_type max_size, bool discard)
 
static OCTAVE_NORETURN void err_invalid_file_id (int fid, const std::string &who)
 
static std::string expand_char_class (const std::string &s)
 
static void get_size (const Array< double > &size, octave_idx_type &nr, octave_idx_type &nc, bool &one_elt_size_spec, const std::string &who)
 
static octave_idx_type get_size (double d, const std::string &who)
 
static Cell init_inf_nan (void)
 
static bool is_nan_or_inf (const octave_value &val)
 
template<>
std::istream & octave_scan (std::istream &is, const scanf_format_elt &fmt, double *valptr)
 
template<typename T >
static std::istream & octave_scan (std::istream &is, const scanf_format_elt &fmt, T *valptr)
 
template<typename T >
static std::istream & octave_scan_1 (std::istream &is, const scanf_format_elt &fmt, T *valptr)
 
static bool ok_for_signed_int_conv (const octave_value &val)
 
static bool ok_for_unsigned_int_conv (const octave_value &val)
 
static double pown (double x, unsigned int n)
 
static std::string switch_to_g_format (const printf_format_elt *elt)
 

Macro Definition Documentation

◆ BEGIN_C_CONVERSION

#define BEGIN_C_CONVERSION ( )
Value:
is.unsetf (std::ios::skipws); \
\
int width = (elt->width ? elt->width : 1); \
\
std::string tmp (width, '\0'); \
\
int c = std::istream::traits_type::eof (); \
int n = 0; \
\
while (is && n < width \
&& (c = is.get ()) != std::istream::traits_type::eof ()) \
tmp[n++] = static_cast<char> (c); \
\
if (n > 0 && c == std::istream::traits_type::eof ()) \
is.clear (); \
\
tmp.resize (n)
octave_idx_type n
Definition: mx-inlines.cc:753

Definition at line 4555 of file oct-stream.cc.

◆ BEGIN_CHAR_CLASS_CONVERSION

#define BEGIN_CHAR_CLASS_CONVERSION ( )

Definition at line 4625 of file oct-stream.cc.

◆ BEGIN_S_CONVERSION

#define BEGIN_S_CONVERSION ( )

Definition at line 4576 of file oct-stream.cc.

◆ DO_LITERAL_CONVERSION

#define DO_LITERAL_CONVERSION ( )
Value:
do \
{ \
int c = std::istream::traits_type::eof (); \
\
int n = fmt.length (); \
int i = 0; \
\
while (i < n && is \
&& (c = is.get ()) != std::istream::traits_type::eof ()) \
{ \
if (c == static_cast<unsigned char> (fmt[i])) \
{ \
i++; \
continue; \
} \
else \
{ \
is.putback (c); \
break; \
} \
} \
\
if (i != n) \
is.setstate (std::ios::failbit); \
} \
while (0)

Definition at line 4509 of file oct-stream.cc.

◆ DO_PCT_CONVERSION

#define DO_PCT_CONVERSION ( )
Value:
do \
{ \
int c = is.get (); \
\
if (c != std::istream::traits_type::eof ()) \
{ \
if (c != '%') \
{ \
is.putback (c); \
is.setstate (std::ios::failbit); \
} \
} \
else \
is.setstate (std::ios::failbit); \
} \
while (0)

Definition at line 4537 of file oct-stream.cc.

◆ DO_WHITESPACE_CONVERSION

#define DO_WHITESPACE_CONVERSION ( )
Value:
do \
{ \
int c = std::istream::traits_type::eof (); \
\
while (is && (c = is.get ()) != std::istream::traits_type::eof () \
&& isspace (c)) \
{ /* skip whitespace */ } \
\
if (c != std::istream::traits_type::eof ()) \
is.putback (c); \
} \
while (0)

Definition at line 4495 of file oct-stream.cc.

◆ FILL_TABLE_ROW

#define FILL_TABLE_ROW (   T,
  V 
)
Value:
TABLE_ELT (T, dt_int8, V, int8NDArray); \
TABLE_ELT (T, dt_uint8, V, uint8NDArray); \
TABLE_ELT (T, dt_int16, V, int16NDArray); \
TABLE_ELT (T, dt_uint16, V, uint16NDArray); \
TABLE_ELT (T, dt_int32, V, int32NDArray); \
TABLE_ELT (T, dt_uint32, V, uint32NDArray); \
TABLE_ELT (T, dt_int64, V, int64NDArray); \
TABLE_ELT (T, dt_uint64, V, uint64NDArray); \
TABLE_ELT (T, dt_single, V, FloatNDArray); \
TABLE_ELT (T, dt_double, V, NDArray); \
TABLE_ELT (T, dt_char, V, charNDArray); \
TABLE_ELT (T, dt_schar, V, charNDArray); \
TABLE_ELT (T, dt_uchar, V, charNDArray); \
TABLE_ELT (T, dt_logical, V, boolNDArray);
F77_RET_T const F77_INT const F77_INT const F77_INT const F77_DBLE const F77_DBLE F77_INT F77_DBLE * V
#define TABLE_ELT(T, U, V, W)
Definition: oct-stream.cc:6509

Definition at line 6512 of file oct-stream.cc.

◆ FINISH_CHARACTER_CONVERSION

#define FINISH_CHARACTER_CONVERSION ( )

Definition at line 4672 of file oct-stream.cc.

◆ INSTANTIATE_WRITE

#define INSTANTIATE_WRITE (   T)
Value:
template \
OCTINTERP_API octave_idx_type \
stream::write (const Array<T>& data, octave_idx_type block_size, \
oct_data_conv::data_type output_type, \
float_format
Definition: mach-info.h:38

Definition at line 7120 of file oct-stream.cc.

◆ TABLE_ELT

#define TABLE_ELT (   T,
  U,
  V,
 
)     conv_fptr_table[oct_data_conv::T][oct_data_conv::U] = convert_and_copy<V, W>

Definition at line 6509 of file oct-stream.cc.

Typedef Documentation

◆ conv_fptr

typedef octave_value(* conv_fptr) (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, bool swap, bool do_float_fmt_conv, bool do_NA_conv, mach_info::float_format from_flt_fmt)

Definition at line 6503 of file oct-stream.cc.

Function Documentation

◆ convert_and_copy()

template<typename SRC_T , typename DST_T >
static octave_value convert_and_copy ( 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,
bool  swap,
bool  do_float_fmt_conv,
bool  do_NA_conv,
mach_info::float_format  from_flt_fmt 
)
static

Definition at line 6414 of file oct-stream.cc.

References do_float_format_conversion(), and native_float_format().

◆ convert_chars()

template<typename T , typename V >
static void convert_chars ( const void *  data,
void *  conv_data,
octave_idx_type  n_elts 
)
static

Definition at line 6837 of file oct-stream.cc.

References V.

◆ convert_data()

◆ convert_ints()

template<typename T , typename V >
static void convert_ints ( const T *  data,
void *  conv_data,
octave_idx_type  n_elts,
bool  swap 
)
static

Definition at line 6849 of file oct-stream.cc.

References V.

◆ convert_to_valid_int()

static int convert_to_valid_int ( const octave_value tc,
int &  conv_err 
)
static

◆ do_printf_conv()

template<typename T >
static int do_printf_conv ( std::ostream &  os,
const char *  fmt,
int  nsa,
int  sa_1,
int  sa_2,
arg,
const std::string &  who 
)
static

Definition at line 5687 of file oct-stream.cc.

References error(), format(), and textscan_format_list::who.

Referenced by base_stream::do_numeric_printf_conv().

◆ do_printf_string()

static std::size_t do_printf_string ( std::ostream &  os,
const printf_format_elt elt,
int  nsa,
int  sa_1,
int  sa_2,
const std::string &  arg,
const std::string &  who 
)
static

◆ do_scanf_conv() [1/2]

template void do_scanf_conv ( std::istream &  ,
const scanf_format_elt ,
double *  ,
Matrix ,
double *  ,
octave_idx_type ,
octave_idx_type ,
octave_idx_type  ,
octave_idx_type  ,
bool   
)

◆ do_scanf_conv() [2/2]

template<typename T >
static void do_scanf_conv ( std::istream &  is,
const scanf_format_elt fmt,
valptr,
Matrix mval,
double *  data,
octave_idx_type idx,
octave_idx_type conversion_count,
octave_idx_type  nr,
octave_idx_type  max_size,
bool  discard 
)
static

Definition at line 4461 of file oct-stream.cc.

References Array< T, Alloc >::fortran_vec(), octave_scan(), and Matrix::resize().

Referenced by base_stream::do_scanf().

◆ err_invalid_file_id()

static OCTAVE_NORETURN void err_invalid_file_id ( int  fid,
const std::string &  who 
)
static

Definition at line 7452 of file oct-stream.cc.

References error().

Referenced by stream_list::lookup(), and stream_list::remove().

◆ expand_char_class()

static std::string expand_char_class ( const std::string &  s)
static

Definition at line 207 of file oct-stream.cc.

References len.

Referenced by scanf_format_list::finish_conversion().

◆ get_size() [1/2]

static void get_size ( const Array< double > &  size,
octave_idx_type nr,
octave_idx_type nc,
bool &  one_elt_size_spec,
const std::string &  who 
)
static

Definition at line 158 of file oct-stream.cc.

References error(), get_size(), isinf(), max(), and Array< T, Alloc >::numel().

◆ get_size() [2/2]

static octave_idx_type get_size ( double  d,
const std::string &  who 
)
static

Definition at line 129 of file oct-stream.cc.

References d, error(), isinf(), lo_ieee_isnan, max(), and nint_big().

Referenced by get_size(), stream::read(), and base_stream::scanf().

◆ init_inf_nan()

static Cell init_inf_nan ( void  )
static

Definition at line 1201 of file oct-stream.cc.

◆ is_nan_or_inf()

static bool is_nan_or_inf ( const octave_value val)
static

◆ octave_scan() [1/2]

template<>
std::istream& octave_scan ( std::istream &  is,
const scanf_format_elt fmt,
double *  valptr 
)

Definition at line 4423 of file oct-stream.cc.

References panic_impossible, and scanf_format_elt::type.

◆ octave_scan() [2/2]

template<typename T >
static std::istream& octave_scan ( std::istream &  is,
const scanf_format_elt fmt,
T *  valptr 
)
static

Definition at line 4375 of file oct-stream.cc.

References octave_scan_1(), and scanf_format_elt::width.

Referenced by base_stream::do_oscanf(), and do_scanf_conv().

◆ octave_scan_1()

template<typename T >
static std::istream& octave_scan_1 ( std::istream &  is,
const scanf_format_elt fmt,
T *  valptr 
)
static

Definition at line 4286 of file oct-stream.cc.

References scanf_format_elt::type.

Referenced by octave_scan().

◆ ok_for_signed_int_conv()

◆ ok_for_unsigned_int_conv()

static bool ok_for_unsigned_int_conv ( const octave_value val)
static

◆ pown()

static double pown ( double  x,
unsigned int  n 
)
static

Definition at line 1186 of file oct-stream.cc.

References d, n, and x.

Referenced by textscan::read_double().

◆ switch_to_g_format()

static std::string switch_to_g_format ( const printf_format_elt elt)
static