GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
data-conv.cc File Reference
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <vector>
#include "byte-swap.h"
#include "data-conv.h"
#include "lo-error.h"
#include "lo-ieee.h"
#include "oct-locbuf.h"
Include dependency graph for data-conv.cc:

Go to the source code of this file.

Macros

#define FIND_SIZED_FLOAT_TYPE(VAL, BITS)
 
#define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q)
 
#define GET_SIZED_INT_TYPE(T, U)
 
#define LS_DO_READ(TYPE, swap, data, size, len, stream)
 
#define LS_DO_WRITE(TYPE, data, size, len, stream)
 

Functions

void do_double_format_conversion (void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt)
 
void do_float_format_conversion (void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt)
 
void do_float_format_conversion (void *data, size_t sz, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt)
 
static OCTAVE_NORETURN void err_unrecognized_float_fmt (void)
 
static void IEEE_big_double_to_IEEE_little_double (void *d, octave_idx_type len)
 
static void IEEE_big_float_to_IEEE_little_float (void *d, octave_idx_type len)
 
static void IEEE_little_double_to_IEEE_big_double (void *d, octave_idx_type len)
 
static void IEEE_little_float_to_IEEE_big_float (void *d, octave_idx_type len)
 
static void init_sized_type_lookup_table (oct_data_conv::data_type table[3][4])
 
void read_doubles (std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
 
void read_floats (std::istream &is, float *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
 
static std::string strip_spaces (const std::string &str)
 
void write_doubles (std::ostream &os, const double *data, save_type type, octave_idx_type len)
 
void write_floats (std::ostream &os, const float *data, save_type type, octave_idx_type len)
 

Macro Definition Documentation

◆ FIND_SIZED_FLOAT_TYPE

#define FIND_SIZED_FLOAT_TYPE (   VAL,
  BITS 
)
Value:
do \
{ \
int sz = BITS / std::numeric_limits<unsigned char>::digits; \
if (sizeof (float) == sz) \
else if (sizeof (double) == sz) \
else \
} \
while (0)
sz
Definition: data.cc:5264

Definition at line 83 of file data-conv.cc.

Referenced by init_sized_type_lookup_table().

◆ FIND_SIZED_INT_TYPE

#define FIND_SIZED_INT_TYPE (   VAL,
  BITS,
  TQ,
  Q 
)
Value:
do \
{ \
int sz = BITS / std::numeric_limits<unsigned char>::digits; \
if (sizeof (TQ char) == sz) \
VAL = oct_data_conv::dt_ ## Q ## char; \
else if (sizeof (TQ short) == sz) \
VAL = oct_data_conv::dt_ ## Q ## short; \
else if (sizeof (TQ int) == sz) \
VAL = oct_data_conv::dt_ ## Q ## int; \
else if (sizeof (TQ long) == sz) \
VAL = oct_data_conv::dt_ ## Q ## long; \
else \
} \
while (0)
sz
Definition: data.cc:5264
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Q

Definition at line 65 of file data-conv.cc.

Referenced by init_sized_type_lookup_table().

◆ GET_SIZED_INT_TYPE

#define GET_SIZED_INT_TYPE (   T,
 
)
Value:
do \
{ \
switch (sizeof (T)) \
{ \
case 1: \
retval = dt_ ## U ## int8; \
break; \
\
case 2: \
retval = dt_ ## U ## int16; \
break; \
\
case 4: \
retval = dt_ ## U ## int32; \
break; \
\
case 8: \
retval = dt_ ## U ## int64; \
break; \
\
default: \
retval = dt_unknown; \
break; \
} \
} \
while (0)

Definition at line 154 of file data-conv.cc.

Referenced by oct_data_conv::string_to_data_type().

◆ LS_DO_READ

#define LS_DO_READ (   TYPE,
  swap,
  data,
  size,
  len,
  stream 
)
Value:
do \
{ \
if (len > 0) \
{ \
OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
stream.read (reinterpret_cast<char *> (ptr), n_bytes); \
if (swap) \
swap_bytes< size > (ptr, len); \
for (octave_idx_type i = 0; i < len; i++) \
data[i] = ptr[i]; \
} \
} \
while (0)
bool swap
Definition: load-save.cc:738
for i
Definition: data.cc:5264

Definition at line 576 of file data-conv.cc.

Referenced by read_doubles(), and read_floats().

◆ LS_DO_WRITE

#define LS_DO_WRITE (   TYPE,
  data,
  size,
  len,
  stream 
)
Value:
do \
{ \
if (len > 0) \
{ \
char tmp_type = type; \
stream.write (&tmp_type, 1); \
OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
for (octave_idx_type i = 0; i < len; i++) \
ptr[i] = static_cast<TYPE> (data[i]); \
std::streamsize n_bytes = size * static_cast<std::streamsize> (len); \
stream.write (reinterpret_cast<char *> (ptr), n_bytes); \
} \
} \
while (0)
idx type
Definition: ov.cc:3114
for i
Definition: data.cc:5264

Definition at line 595 of file data-conv.cc.

Referenced by write_doubles(), and write_floats().

Function Documentation

◆ do_double_format_conversion()

◆ do_float_format_conversion() [1/2]

◆ do_float_format_conversion() [2/2]

void do_float_format_conversion ( void *  data,
size_t  sz,
octave_idx_type  len,
octave::mach_info::float_format  from_fmt,
octave::mach_info::float_format  to_fmt 
)

Definition at line 749 of file data-conv.cc.

References do_double_format_conversion(), do_float_format_conversion(), and sz.

◆ err_unrecognized_float_fmt()

static OCTAVE_NORETURN void err_unrecognized_float_fmt ( void  )
static

Definition at line 615 of file data-conv.cc.

Referenced by do_double_format_conversion(), and do_float_format_conversion().

◆ IEEE_big_double_to_IEEE_little_double()

static void IEEE_big_double_to_IEEE_little_double ( void *  d,
octave_idx_type  len 
)
static

Definition at line 631 of file data-conv.cc.

References d, and swap_bytes< 8 >().

Referenced by do_double_format_conversion().

◆ IEEE_big_float_to_IEEE_little_float()

static void IEEE_big_float_to_IEEE_little_float ( void *  d,
octave_idx_type  len 
)
static

Definition at line 637 of file data-conv.cc.

References d, and swap_bytes< 4 >().

Referenced by do_float_format_conversion().

◆ IEEE_little_double_to_IEEE_big_double()

static void IEEE_little_double_to_IEEE_big_double ( void *  d,
octave_idx_type  len 
)
static

Definition at line 643 of file data-conv.cc.

References d, and swap_bytes< 8 >().

Referenced by do_double_format_conversion().

◆ IEEE_little_float_to_IEEE_big_float()

static void IEEE_little_float_to_IEEE_big_float ( void *  d,
octave_idx_type  len 
)
static

Definition at line 649 of file data-conv.cc.

References d, and swap_bytes< 4 >().

Referenced by do_float_format_conversion().

◆ init_sized_type_lookup_table()

static void init_sized_type_lookup_table ( oct_data_conv::data_type  table[3][4])
static

Definition at line 120 of file data-conv.cc.

References FIND_SIZED_FLOAT_TYPE, FIND_SIZED_INT_TYPE, i, and u.

Referenced by oct_data_conv::string_to_data_type().

◆ read_doubles()

◆ read_floats()

◆ strip_spaces()

static std::string strip_spaces ( const std::string str)
static

Definition at line 137 of file data-conv.cc.

References i, k, s, str, and string.

Referenced by oct_data_conv::string_to_data_type().

◆ write_doubles()

◆ write_floats()