GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
ov-struct.cc File Reference
#include <iostream>
#include "Cell.h"
#include "defun.h"
#include "error.h"
#include "gripes.h"
#include "mxarray.h"
#include "oct-lvalue.h"
#include "ov-struct.h"
#include "unwind-prot.h"
#include "utils.h"
#include "variables.h"
#include "Array-util.h"
#include "oct-locbuf.h"
#include "byte-swap.h"
#include "ls-oct-ascii.h"
#include "ls-oct-binary.h"
#include "ls-hdf5.h"
#include "ls-utils.h"
#include "pr-output.h"
Include dependency graph for ov-struct.cc:

Go to the source code of this file.

Functions

 DEFINE_OCTAVE_ALLOCATOR (octave_struct)
 DEFINE_OCTAVE_ALLOCATOR (octave_scalar_struct)
 DEFUN (struct, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} struct (@var{field1}, @var{value1}, @var{field2}, @var{value2}, @dots{})\n\ \n\ Create a scalar or array structure and initialize its values. The\n\ @var{field1}, @var{field2}, @dots{} variables are strings giving the\n\ names of the fields and the @var{value1}, @var{value2}, @dots{}\n\ variables can be any type.\n\ \n\ If the values are cell arrays, create a structure array and initialize\n\ its values. The dimensions of each cell array of values must match.\n\ Singleton cells and non-cell values are repeated so that they fill\n\ the entire array. If the cells are empty, create an empty structure\n\ array with the specified field names.\n\ \n\ If the argument is an object, return the underlying struct.\n\ \n\ Observe that the syntax is optimized for struct @strong{arrays}. Consider\n\ the following examples:\n\ \n\ @example\n\ @group\n\ struct (\"foo\", 1)\n\ @result{} scalar structure containing the fields:\n\ foo = 1\n\ \n\ struct (\"foo\", @{@})\n\ @result{} 0x0 struct array containing the fields:\n\ foo\n\ \n\ struct (\"foo\", @{ @{@} @})\n\ @result{} scalar structure containing the fields:\n\ foo = @{@}(0x0)\n\ \n\ struct (\"foo\", @{1, 2, 3@})\n\ @result{} 1x3 struct array containing the fields:\n\ foo\n\ \n\ @end group\n\ @end example\n\ \n\ @noindent\n\ The first case is an ordinary scalar struct, one field, one value. The\n\ second produces an empty struct array with one field and no values, since\n\ s being passed an empty cell array of struct array values. When the value is\n\ a cell array containing a single entry, this becomes a scalar struct with\n\ that single entry as the value of the field. That single entry happens\n\ to be an empty cell array.\n\ \n\ Finally, if the value is a non-scalar cell array, then @code{struct}\n\ produces a struct @strong{array}.\n\ @end deftypefn")
 DEFUN (isstruct, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} isstruct (@var{x})\n\ Return true if @var{x} is a structure or a structure array.\n\ @seealso{ismatrix, iscell, isa}\n\ @end deftypefn")
 DEFUN (__fieldnames__, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} __fieldnames__ (@var{struct})\n\ @deftypefnx {Built-in Function} {} __fieldnames__ (@var{obj})\n\ Internal function.\n\ \n\ Implements @code{fieldnames()} for structures and Octave objects.\n\ @seealso{fieldnames}\n\ @end deftypefn")
 DEFUN (isfield, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} isfield (@var{x}, @var{name})\n\ Return true if the @var{x} is a structure and it\n\ includes an element named @var{name}. If @var{name} is a cell\n\ array of strings then a logical array of equal dimension is returned.\n\ @end deftypefn")
 DEFUN (nfields, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} nfields (@var{s})\n\ Return the number of fields of the structure @var{s}.\n\ @end deftypefn")
 DEFUN (cell2struct, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} cell2struct (@var{cell}, @var{fields}, @var{dim})\n\ Convert @var{cell} to a structure. The number of fields in @var{fields}\n\ must match the number of elements in @var{cell} along dimension @var{dim},\n\ that is @code{numel (@var{fields}) == size (@var{cell}, @var{dim})}.\n\ If @var{dim} is omitted, a value of 1 is assumed.\n\ \n\ @example\n\ @group\n\ A = cell2struct (@{\"Peter\", \"Hannah\", \"Robert\";\n\ 185, 170, 168@},\n\ @{\"Name\",\"Height\"@}, 1);\n\ A(1)\n\ @result{}\n\ @{\n\ Name = Peter\n\ Height = 185\n\ @}\n\ \n\ @end group\n\ @end example\n\ @end deftypefn")
 DEFUN (rmfield, args,,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{s} =} rmfield (@var{s}, \"@var{f}\")\n\ @deftypefnx {Built-in Function} {@var{s} =} rmfield (@var{s}, @var{f})\n\ Return a copy of the structure (array) @var{s} with the field @var{f}\n\ removed. If @var{f} is a cell array of strings or a character array, remove\n\ each of the named fields.\n\ @seealso{cellstr, iscellstr, setfield}\n\ @end deftypefn")
 DEFUN (struct_levels_to_print, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\ @deftypefnx {Built-in Function} {} struct_levels_to_print (@var{new_val}, \"local\")\n\ Query or set the internal variable that specifies the number of\n\ structure levels to display.\n\ \n\ When called from inside a function with the @qcode{\"local\"} option, the\n\ variable is changed locally for the function and any subroutines it calls. \n\ The original variable value is restored when exiting the function.\n\ @end deftypefn")
 DEFUN (print_struct_array_contents, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} print_struct_array_contents ()\n\ @deftypefnx {Built-in Function} {@var{old_val} =} print_struct_array_contents (@var{new_val})\n\ @deftypefnx {Built-in Function} {} print_struct_array_contents (@var{new_val}, \"local\")\n\ Query or set the internal variable that specifies whether to print struct\n\ array contents. If true, values of struct array elements are printed.\n\ This variable does not affect scalar structures. Their elements\n\ are always printed. In both cases, however, printing will be limited to\n\ the number of levels specified by @var{struct_levels_to_print}.\n\ \n\ When called from inside a function with the @qcode{\"local\"} option, the\n\ variable is changed locally for the function and any subroutines it calls. \n\ The original variable value is restored when exiting the function.\n\ @end deftypefn")
octave_value_list Fcellstr (const octave_value_list &args, int)
static void gripe_failed_assignment (void)
static void gripe_invalid_index_for_assignment (void)
static void gripe_invalid_index_type (const std::string &nm, char t)
static void maybe_warn_invalid_field_name (const std::string &key, const char *who)
static bool scalar (const dim_vector &dims)

Variables

static bool Vprint_struct_array_contents = false
static int Vstruct_levels_to_print = 2

Function Documentation

DEFINE_OCTAVE_ALLOCATOR ( octave_struct  )
DEFINE_OCTAVE_ALLOCATOR ( octave_scalar_struct  )
DEFUN ( struct  ,
args   
)
DEFUN ( isstruct  ,
args   
)

Definition at line 1963 of file ov-struct.cc.

References octave_value::is_map(), and print_usage().

DEFUN ( __fieldnames__  ,
args   
)
DEFUN ( isfield  ,
args   
)
DEFUN ( nfields  ,
args   
)

Definition at line 2064 of file ov-struct.cc.

References octave_value::length(), and print_usage().

DEFUN ( cell2struct  ,
args   
)
DEFUN ( rmfield  ,
args   
)
DEFUN ( struct_levels_to_print  ,
args  ,
nargout   
)

Definition at line 2294 of file ov-struct.cc.

References max(), and SET_INTERNAL_VARIABLE_WITH_LIMITS.

DEFUN ( print_struct_array_contents  ,
args  ,
nargout   
)

Definition at line 2311 of file ov-struct.cc.

References SET_INTERNAL_VARIABLE.

octave_value_list Fcellstr ( const octave_value_list args,
int   
)
static void gripe_failed_assignment ( void  )
static

Definition at line 115 of file ov-struct.cc.

References error().

Referenced by octave_struct::subsasgn(), and octave_scalar_struct::subsasgn().

static void gripe_invalid_index_for_assignment ( void  )
static

Definition at line 103 of file ov-struct.cc.

References error().

Referenced by octave_struct::subsasgn().

static void gripe_invalid_index_type ( const std::string &  nm,
char  t 
)
static

Definition at line 109 of file ov-struct.cc.

References error().

Referenced by octave_struct::subsasgn(), and octave_struct::subsref().

static void maybe_warn_invalid_field_name ( const std::string &  key,
const char who 
)
static
static bool scalar ( const dim_vector dims)
static

Definition at line 736 of file ov-struct.cc.

References dim_vector::length().

Referenced by octave_base_scalar< bool >::all(), octave_scalar::any(), octave_float_complex::any(), octave_float_scalar::any(), octave_complex::any(), octave_base_scalar< bool >::any(), octave_scalar::array_value(), octave_float_scalar::array_value(), octave_bool::array_value(), OCTAVE_VALUE_INT_SCALAR_T::array_value(), OCTAVE_VALUE_INT_SCALAR_T::as_mxArray(), octave_float_complex::bool_array_value(), octave_complex::bool_array_value(), octave_bool::bool_array_value(), octave_scalar::bool_array_value(), octave_float_scalar::bool_array_value(), OCTAVE_VALUE_INT_SCALAR_T::bool_array_value(), octave_bool::bool_matrix_value(), octave_float_complex::bool_value(), octave_complex::bool_value(), octave_scalar::bool_value(), octave_float_scalar::bool_value(), octave_bool::bool_value(), OCTAVE_VALUE_INT_SCALAR_T::bool_value(), octave_scalar::char_array_value(), octave_float_scalar::char_array_value(), octave_bool::char_array_value(), OCTAVE_VALUE_INT_SCALAR_T::char_array_value(), octave_bool::complex_array_value(), octave_scalar::complex_array_value(), octave_float_scalar::complex_array_value(), OCTAVE_VALUE_INT_SCALAR_T::complex_array_value(), octave_bool::complex_matrix_value(), octave_scalar::complex_matrix_value(), octave_float_scalar::complex_matrix_value(), OCTAVE_VALUE_INT_SCALAR_T::complex_matrix_value(), octave_bool::complex_value(), octave_scalar::complex_value(), octave_float_scalar::complex_value(), octave_base_int_scalar< T >::convert_to_str_internal(), octave_float_complex::decrement(), octave_complex::decrement(), octave_scalar::decrement(), octave_float_scalar::decrement(), OCTAVE_VALUE_INT_SCALAR_T::decrement(), DEFUN(), octave_base_scalar< ST >::diag(), jit_paren_subsref::do_initialize(), octave_scalar::double_value(), octave_float_scalar::double_value(), octave_bool::double_value(), OCTAVE_VALUE_INT_SCALAR_T::double_value(), octave_base_scalar< ST >::fast_elem_insert_self(), octave_scalar::float_array_value(), octave_float_scalar::float_array_value(), octave_bool::float_array_value(), OCTAVE_VALUE_INT_SCALAR_T::float_array_value(), octave_bool::float_complex_array_value(), octave_scalar::float_complex_array_value(), octave_float_scalar::float_complex_array_value(), OCTAVE_VALUE_INT_SCALAR_T::float_complex_array_value(), octave_bool::float_complex_matrix_value(), octave_scalar::float_complex_matrix_value(), octave_float_scalar::float_complex_matrix_value(), OCTAVE_VALUE_INT_SCALAR_T::float_complex_matrix_value(), octave_bool::float_complex_value(), octave_scalar::float_complex_value(), octave_float_scalar::float_complex_value(), octave_scalar::float_matrix_value(), octave_float_scalar::float_matrix_value(), octave_bool::float_matrix_value(), OCTAVE_VALUE_INT_SCALAR_T::float_matrix_value(), octave_scalar::float_scalar_value(), octave_float_scalar::float_scalar_value(), octave_bool::float_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::float_scalar_value(), octave_scalar::float_value(), octave_float_scalar::float_value(), octave_bool::float_value(), OCTAVE_VALUE_INT_SCALAR_T::float_value(), octave_base_scalar< bool >::full_value(), jit_index_operation::generate(), jit_paren_subsref::generate_matrix(), octave_float_complex::increment(), octave_complex::increment(), octave_scalar::increment(), octave_float_scalar::increment(), OCTAVE_VALUE_INT_SCALAR_T::increment(), octave_bool::index_vector(), octave_scalar::index_vector(), octave_float_scalar::index_vector(), OCTAVE_VALUE_INT_SCALAR_T::index_vector(), octave_bool::int16_array_value(), octave_scalar::int16_array_value(), octave_float_scalar::int16_array_value(), octave_bool::int16_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::int16_scalar_value(), octave_bool::int32_array_value(), octave_scalar::int32_array_value(), octave_float_scalar::int32_array_value(), octave_bool::int32_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::int32_scalar_value(), octave_bool::int64_array_value(), octave_scalar::int64_array_value(), octave_float_scalar::int64_array_value(), octave_bool::int64_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::int64_scalar_value(), octave_bool::int8_array_value(), octave_scalar::int8_array_value(), octave_float_scalar::int8_array_value(), octave_bool::int8_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::int8_scalar_value(), octave_bool::is_true(), octave_base_scalar< ST >::is_true(), octave_base_int_scalar< T >::load_ascii(), octave_base_int_scalar< T >::load_binary(), octave_base_int_scalar< T >::load_hdf5(), OCTAVE_VALUE_INT_SCALAR_T::map(), octave_scalar::matrix_value(), octave_float_scalar::matrix_value(), octave_bool::matrix_value(), OCTAVE_VALUE_INT_SCALAR_T::matrix_value(), octave_base_scalar< bool >::mex_get_data(), OCTAVE_VALUE_INT_SCALAR_T::mex_get_data(), octave_base_scalar< bool >::nnz(), octave_value::octave_value(), octave_base_scalar< ST >::permute(), octave_base_scalar< ST >::print_raw(), octave_base_scalar< ST >::reshape(), OCTAVE_VALUE_INT_SCALAR_T::resize(), octave_base_int_scalar< T >::save_ascii(), octave_base_int_scalar< T >::save_binary(), octave_base_int_scalar< T >::save_hdf5(), octave_base_scalar< bool >::scalar_ref(), octave_scalar::scalar_value(), octave_float_scalar::scalar_value(), octave_bool::scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::scalar_value(), octave_base_scalar< ST >::short_disp(), octave_base_scalar< bool >::sort(), octave_bool::sparse_bool_matrix_value(), octave_scalar::sparse_matrix_value(), octave_float_scalar::sparse_matrix_value(), octave_bool::sparse_matrix_value(), octave_base_scalar< bool >::squeeze(), octave_bool::uint16_array_value(), octave_scalar::uint16_array_value(), octave_float_scalar::uint16_array_value(), octave_bool::uint16_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::uint16_scalar_value(), octave_bool::uint32_array_value(), octave_scalar::uint32_array_value(), octave_float_scalar::uint32_array_value(), octave_bool::uint32_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::uint32_scalar_value(), octave_bool::uint64_array_value(), octave_scalar::uint64_array_value(), octave_float_scalar::uint64_array_value(), octave_bool::uint64_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::uint64_scalar_value(), octave_bool::uint8_array_value(), octave_scalar::uint8_array_value(), octave_float_scalar::uint8_array_value(), octave_bool::uint8_scalar_value(), OCTAVE_VALUE_INT_SCALAR_T::uint8_scalar_value(), and zero_dims_inquire().

Variable Documentation

bool Vprint_struct_array_contents = false
static

Definition at line 59 of file ov-struct.cc.

Referenced by octave_struct::print_raw().

int Vstruct_levels_to_print = 2
static

Definition at line 55 of file ov-struct.cc.