Classes | Defines | Typedefs | Functions

oct-stream.cc File Reference

#include <cassert>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <Array.h>
#include "byte-swap.h"
#include "lo-ieee.h"
#include "lo-mappers.h"
#include "lo-utils.h"
#include "quit.h"
#include "singleton-cleanup.h"
#include "str-vec.h"
#include "error.h"
#include "gripes.h"
#include "input.h"
#include "oct-stdstrm.h"
#include "oct-stream.h"
#include "oct-obj.h"
#include "utils.h"
Include dependency graph for oct-stream.cc:

Go to the source code of this file.

Classes

class  printf_value_cache

Defines

#define BEGIN_C_CONVERSION()
#define BEGIN_CHAR_CLASS_CONVERSION()
#define BEGIN_S_CONVERSION()
#define DO_DOUBLE_CONV(TQUAL)
#define DO_LITERAL_CONVERSION()
#define DO_PCT_CONVERSION()
#define DO_READ_VAL_TEMPLATE(RET_T, READ_T)
#define DO_WHITESPACE_CONVERSION()
#define FILL_TABLE_ROW(R, VAL_T)
#define FINISH_CHARACTER_CONVERSION()
#define INSTANTIATE_DO_READ(VAL_T)
#define OCTAVE_SCAN(is, fmt, arg)   octave_scan (is, fmt, arg)

Typedefs

typedef octave_value(* read_fptr )(octave_stream &, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool, oct_mach_info::float_format ffmt, octave_idx_type &)

Functions

static int convert_to_valid_int (const octave_value &tc, int &conv_err)
template<class T >
int do_printf_conv (std::ostream &os, const char *fmt, int nsa, int sa_1, int sa_2, T arg, const std::string &who)
template int do_printf_conv (std::ostream &, const char *, int, int, int, int, const std::string &)
template int do_printf_conv (std::ostream &, const char *, int, int, int, long, const std::string &)
template int do_printf_conv (std::ostream &, const char *, int, int, int, unsigned int, const std::string &)
template int do_printf_conv (std::ostream &, const char *, int, int, int, double, const std::string &)
template int do_printf_conv (std::ostream &, const char *, int, int, int, const char *, const std::string &)
template<class RET_T , class READ_T >
octave_value do_read (octave_stream &strm, octave_idx_type nr, octave_idx_type nc, octave_idx_type block_size, octave_idx_type skip, bool do_float_fmt_conv, bool do_NA_conv, oct_mach_info::float_format from_flt_fmt, octave_idx_type &count)
template void do_scanf_conv (std::istream &, const scanf_format_elt &, long int *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
template void do_scanf_conv (std::istream &, const scanf_format_elt &, short int *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
template void do_scanf_conv (std::istream &, const scanf_format_elt &, unsigned int *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
template void do_scanf_conv (std::istream &, const scanf_format_elt &, int *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
template void do_scanf_conv (std::istream &, const scanf_format_elt &, unsigned short int *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
template void do_scanf_conv (std::istream &, const scanf_format_elt &, unsigned long int *, Matrix &, double *, octave_idx_type &, octave_idx_type &, octave_idx_type, octave_idx_type, bool)
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<class T >
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)
template<class T >
static bool do_write (std::ostream &os, const T &val, oct_data_conv::data_type output_type, oct_mach_info::float_format flt_fmt, bool swap, bool do_float_conversion)
template bool do_write (std::ostream &, const octave_int8 &, oct_data_conv::data_type, oct_mach_info::float_format, bool, bool)
static std::string expand_char_class (const std::string &s)
static int get_size (double d, const std::string &who)
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 void gripe_invalid_file_id (int fid, const std::string &who)
 INSTANTIATE_DO_READ (NDArray)
 INSTANTIATE_DO_READ (FloatNDArray)
 INSTANTIATE_DO_READ (charNDArray)
 INSTANTIATE_DO_READ (boolNDArray)
 INSTANTIATE_DO_READ (int8NDArray)
template std::istream & octave_scan (std::istream &, const scanf_format_elt &, int *)
template std::istream & octave_scan (std::istream &, const scanf_format_elt &, unsigned int *)
template<>
std::istream & octave_scan (std::istream &is, const scanf_format_elt &fmt, double *valptr)
template<>
std::istream & octave_scan (std::istream &is, const scanf_format_elt &, char *valptr)
template std::istream & octave_scan (std::istream &, const scanf_format_elt &, short int *)
template std::istream & octave_scan (std::istream &, const scanf_format_elt &, long int *)
template<class T >
std::istream & octave_scan (std::istream &is, const scanf_format_elt &fmt, T *valptr)
template std::istream & octave_scan (std::istream &, const scanf_format_elt &, unsigned long int *)
template std::istream & octave_scan (std::istream &, const scanf_format_elt &, unsigned short int *)
template<class T >
std::istream & octave_scan_1 (std::istream &is, const scanf_format_elt &fmt, T *valptr)
template<class T >
void write_int (std::ostream &os, bool swap, const T &val)
template void write_int (std::ostream &, bool, const octave_int8 &)

Define Documentation

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

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

Referenced by octave_base_stream::do_oscanf(), and octave_base_stream::do_scanf().

#define BEGIN_CHAR_CLASS_CONVERSION (  ) 

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

Referenced by octave_base_stream::do_oscanf(), and octave_base_stream::do_scanf().

#define BEGIN_S_CONVERSION (  ) 

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

Referenced by octave_base_stream::do_oscanf(), and octave_base_stream::do_scanf().

#define DO_DOUBLE_CONV (   TQUAL  ) 
Value:
do \
    { \
      if (val > std::numeric_limits<TQUAL long>::max () \
          || val < std::numeric_limits<TQUAL long>::min ()) \
        { \
          std::string tfmt = fmt; \
 \
          tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \
 \
          if (elt->modifier == 'l') \
            tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \
 \
          retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \
                                    val, who); \
        } \
      else \
        retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \
                                  static_cast<TQUAL long> (val), who); \
    } \
  while (0)

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

Referenced by octave_base_stream::do_printf().

#define DO_LITERAL_CONVERSION (  ) 
Value:
do \
    { \
      int c = EOF; \
 \
      int n = strlen (fmt); \
      int i = 0; \
 \
      while (i < n && is && (c = is.get ()) != 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 1324 of file oct-stream.cc.

Referenced by octave_base_stream::do_oscanf(), and octave_base_stream::do_scanf().

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

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

Referenced by octave_base_stream::do_oscanf(), and octave_base_stream::do_scanf().

#define DO_READ_VAL_TEMPLATE (   RET_T,
  READ_T 
)
Value:
template octave_value \
  do_read<RET_T, READ_T> (octave_stream&, octave_idx_type, octave_idx_type, octave_idx_type, octave_idx_type, bool, bool, \
                          oct_mach_info::float_format, octave_idx_type&)

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

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

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

Referenced by octave_base_stream::do_oscanf(), and octave_base_stream::do_scanf().

#define FILL_TABLE_ROW (   R,
  VAL_T 
)
Value:
read_fptr_table[R][oct_data_conv::dt_int8] = do_read<VAL_T, octave_int8>; \
  read_fptr_table[R][oct_data_conv::dt_uint8] = do_read<VAL_T, octave_uint8>; \
  read_fptr_table[R][oct_data_conv::dt_int16] = do_read<VAL_T, octave_int16>; \
  read_fptr_table[R][oct_data_conv::dt_uint16] = do_read<VAL_T, octave_uint16>; \
  read_fptr_table[R][oct_data_conv::dt_int32] = do_read<VAL_T, octave_int32>; \
  read_fptr_table[R][oct_data_conv::dt_uint32] = do_read<VAL_T, octave_uint32>; \
  read_fptr_table[R][oct_data_conv::dt_int64] = do_read<VAL_T, octave_int64>; \
  read_fptr_table[R][oct_data_conv::dt_uint64] = do_read<VAL_T, octave_uint64>; \
  read_fptr_table[R][oct_data_conv::dt_single] = do_read<VAL_T, float>; \
  read_fptr_table[R][oct_data_conv::dt_double] = do_read<VAL_T, double>; \
  read_fptr_table[R][oct_data_conv::dt_char] = do_read<VAL_T, char>; \
  read_fptr_table[R][oct_data_conv::dt_schar] = do_read<VAL_T, signed char>; \
  read_fptr_table[R][oct_data_conv::dt_uchar] = do_read<VAL_T, unsigned char>; \
  read_fptr_table[R][oct_data_conv::dt_logical] = do_read<VAL_T, unsigned char>

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

Referenced by octave_stream::read().

#define FINISH_CHARACTER_CONVERSION (  ) 

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

Referenced by octave_base_stream::do_scanf().

#define INSTANTIATE_DO_READ (   VAL_T  ) 
Value:

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

#define OCTAVE_SCAN (   is,
  fmt,
  arg 
)    octave_scan (is, fmt, arg)

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

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


Typedef Documentation

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


Function Documentation

static int convert_to_valid_int ( const octave_value tc,
int conv_err 
) [static]
template<class T >
int do_printf_conv ( std::ostream &  os,
const char fmt,
int  nsa,
int  sa_1,
int  sa_2,
arg,
const std::string &  who 
)

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

References error(), and octave_format().

Referenced by octave_base_stream::do_printf().

template int do_printf_conv ( std::ostream &  ,
const char ,
int  ,
int  ,
int  ,
int  ,
const std::string &   
)
template int do_printf_conv ( std::ostream &  ,
const char ,
int  ,
int  ,
int  ,
long  ,
const std::string &   
)
template int do_printf_conv ( std::ostream &  ,
const char ,
int  ,
int  ,
int  ,
unsigned  int,
const std::string &   
)
template int do_printf_conv ( std::ostream &  ,
const char ,
int  ,
int  ,
int  ,
double  ,
const std::string &   
)
template int do_printf_conv ( std::ostream &  ,
const char ,
int  ,
int  ,
int  ,
const char ,
const std::string &   
)
template<class RET_T , class READ_T >
octave_value do_read ( octave_stream strm,
octave_idx_type  nr,
octave_idx_type  nc,
octave_idx_type  block_size,
octave_idx_type  skip,
bool  do_float_fmt_conv,
bool  do_NA_conv,
oct_mach_info::float_format  from_flt_fmt,
octave_idx_type count 
)
template void do_scanf_conv ( std::istream &  ,
const scanf_format_elt ,
long int ,
Matrix ,
double ,
octave_idx_type ,
octave_idx_type ,
octave_idx_type  ,
octave_idx_type  ,
bool   
)
template void do_scanf_conv ( std::istream &  ,
const scanf_format_elt ,
short int ,
Matrix ,
double ,
octave_idx_type ,
octave_idx_type ,
octave_idx_type  ,
octave_idx_type  ,
bool   
)
template void do_scanf_conv ( std::istream &  ,
const scanf_format_elt ,
unsigned int ,
Matrix ,
double ,
octave_idx_type ,
octave_idx_type ,
octave_idx_type  ,
octave_idx_type  ,
bool   
)
template void do_scanf_conv ( std::istream &  ,
const scanf_format_elt ,
int ,
Matrix ,
double ,
octave_idx_type ,
octave_idx_type ,
octave_idx_type  ,
octave_idx_type  ,
bool   
)
template void do_scanf_conv ( std::istream &  ,
const scanf_format_elt ,
unsigned short int ,
Matrix ,
double ,
octave_idx_type ,
octave_idx_type ,
octave_idx_type  ,
octave_idx_type  ,
bool   
)
template void do_scanf_conv ( std::istream &  ,
const scanf_format_elt ,
unsigned long int ,
Matrix ,
double ,
octave_idx_type ,
octave_idx_type ,
octave_idx_type  ,
octave_idx_type  ,
bool   
)
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<class T >
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 
)

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

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

Referenced by octave_base_stream::do_scanf().

template<class T >
static bool do_write ( std::ostream &  os,
const T &  val,
oct_data_conv::data_type  output_type,
oct_mach_info::float_format  flt_fmt,
bool  swap,
bool  do_float_conversion 
) [inline, static]
template bool do_write ( std::ostream &  ,
const octave_int8 ,
oct_data_conv::data_type  ,
oct_mach_info::float_format  ,
bool  ,
bool   
)
static std::string expand_char_class ( const std::string &  s  )  [static]

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

Referenced by scanf_format_list::finish_conversion().

static int get_size ( double  d,
const std::string &  who 
) [static]

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

References error(), lo_ieee_isnan, NINT(), and xisinf().

Referenced by get_size(), octave_stream::read(), and octave_base_stream::scanf().

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 115 of file oct-stream.cc.

References error(), error_state, get_size(), Array< T >::length(), size(), and xisinf().

static void gripe_invalid_file_id ( int  fid,
const std::string &  who 
) [static]

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

References error().

Referenced by octave_stream_list::do_lookup(), and octave_stream_list::do_remove().

INSTANTIATE_DO_READ ( NDArray   ) 
INSTANTIATE_DO_READ ( FloatNDArray   ) 
INSTANTIATE_DO_READ ( charNDArray   ) 
INSTANTIATE_DO_READ ( boolNDArray   ) 
INSTANTIATE_DO_READ ( int8NDArray   ) 
template std::istream& octave_scan ( std::istream &  ,
const scanf_format_elt ,
int  
)
template std::istream& octave_scan ( std::istream &  ,
const scanf_format_elt ,
unsigned int  
)
template<>
std::istream& octave_scan ( std::istream &  is,
const scanf_format_elt fmt,
double valptr 
)

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

References c1, and panic_impossible.

template<>
std::istream& octave_scan ( std::istream &  is,
const scanf_format_elt ,
char valptr 
)

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

template std::istream& octave_scan ( std::istream &  ,
const scanf_format_elt ,
short int  
)
template std::istream& octave_scan ( std::istream &  ,
const scanf_format_elt ,
long int  
)
template<class T >
std::istream& octave_scan ( std::istream &  is,
const scanf_format_elt fmt,
T *  valptr 
)

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

References octave_scan_1(), and scanf_format_elt::width.

template std::istream& octave_scan ( std::istream &  ,
const scanf_format_elt ,
unsigned long int  
)
template std::istream& octave_scan ( std::istream &  ,
const scanf_format_elt ,
unsigned short int  
)
template<class T >
std::istream& octave_scan_1 ( std::istream &  is,
const scanf_format_elt fmt,
T *  valptr 
)

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

References c1, and scanf_format_elt::type.

Referenced by octave_scan().

template<class T >
void write_int ( std::ostream &  os,
bool  swap,
const T &  val 
)

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

Referenced by do_write().

template void write_int ( std::ostream &  ,
bool  ,
const octave_int8  
)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines