23 #if defined (HAVE_CONFIG_H) 30 #include "builtin-defun-decls.h" 78 assert (idx.
length () == 1);
90 "structure has no member '%s'",
nm.c_str ());
98 error (
"invalid index for structure array assignment");
104 error (
"%s cannot be indexed with %c",
nm.c_str (),
t);
114 "%s: invalid structure field name '%s'",
118 "invalid structure field name '%s'",
125 const std::list<octave_value_list>& idx,
136 if (
type.length () > 1 &&
type[1] ==
'.')
138 std::list<octave_value_list>::const_iterator
p = idx.begin ();
143 const Cell t =
tmp.index (idx.front ());
188 const std::list<octave_value_list>& idx,
199 if (
type.length () > 1 &&
type[1] ==
'.')
201 std::list<octave_value_list>::const_iterator
p = idx.begin ();
206 const Cell t =
tmp.index (idx.front (), auto_add);
264 if (
type.length () > 0 &&
type[0] ==
'.' && !
val.isstruct ())
274 const std::list<octave_value_list>& idx,
279 int n =
type.length ();
283 if (idx.front ().empty ())
284 error (
"missing index in indexed assignment");
286 if (n > 1 && ! (
type.length () == 2 &&
type[0] ==
'(' &&
type[1] ==
'.'))
292 if (
type.length () > 1 &&
type[1] ==
'.')
294 std::list<octave_value_list>::const_iterator
p = idx.begin ();
299 assert (key_idx.
length () == 1);
305 std::list<octave_value_list> next_idx (idx);
310 next_idx.erase (next_idx.begin ());
311 next_idx.erase (next_idx.begin ());
325 if (tmpc.
numel () != 1)
330 bool orig_undefined =
tmp.is_undefined ();
332 if (orig_undefined ||
tmp.is_zero_by_zero ())
342 t_rhs =(orig_undefined
343 ?
tmp.undef_subsasgn (next_type, next_idx, rhs)
344 :
tmp.subsasgn (next_type, next_idx, rhs));
355 assert (key_idx.
length () == 1);
361 std::list<octave_value_list> next_idx (idx);
363 next_idx.erase (next_idx.begin ());
377 if (tmpc.
numel () == 1)
381 bool orig_undefined =
tmp.is_undefined ();
383 if (orig_undefined ||
tmp.is_zero_by_zero ())
393 t_rhs = (orig_undefined
394 ?
tmp.undef_subsasgn (next_type, next_idx, rhs)
395 :
tmp.subsasgn (next_type, next_idx, rhs));
415 if (n > 1 &&
type[1] ==
'.')
417 std::list<octave_value_list>::const_iterator
p = idx.begin ();
421 assert (key_idx.
length () == 1);
435 if (! idxf(
k).is_magic_colon ())
436 didx(
k) = idxf(
k).numel ();
438 if (didx.numel () == tmp_cell.
numel ())
439 tmp_cell = tmp_cell.
reshape (didx);
478 error (
"invalid structure assignment");
493 assert (key_idx.
length () == 1);
582 bool print_fieldnames_only
589 os <<
dv.
str () <<
" struct array containing the fields:";
605 if (print_fieldnames_only)
613 tmp.print_with_name (
os, key);
617 if (print_fieldnames_only)
683 return "[" + dimstr +
" " + tname +
"]";
696 os <<
"# ndims: " <<
dv.
ndims () <<
"\n";
702 os <<
"# length: " << nf <<
"\n";
735 keywords[0] =
"ndims";
736 keywords[1] =
"length";
742 if (kw == keywords[0])
744 int mdims =
std::max (static_cast<int> (len), 2);
746 for (
int i = 0;
i < mdims;
i++)
755 if (! success || len < 0)
756 error (
"load: failed to extract number of elements in structure");
780 error (
"load: failed to load structure");
805 os.
write (reinterpret_cast<char *> (&di), 4);
809 os.
write (reinterpret_cast<char *> (&di), 4);
813 os.
write (reinterpret_cast<char *> (&len), 4);
840 if (!
is.read (reinterpret_cast<char *> (&len), 4))
855 for (
int i = 0;
i < mdims;
i++)
857 if (!
is.read (reinterpret_cast<char *> (&di), 4))
864 if (!
is.read (reinterpret_cast<char *> (&len), 4))
893 error (
"load: failed to load structure");
909 #if defined (HAVE_HDF5) 913 #if defined (HAVE_HDF5_18) 917 data_hid = H5Gcreate (loc_id,
name, 0);
919 if (data_hid < 0)
return false;
948 octave_unused_parameter (loc_id);
949 octave_unused_parameter (
name);
963 #if defined (HAVE_HDF5) 969 int current_item = 0;
971 #if defined (HAVE_HDF5_18) 974 hid_t group_id = H5Gopen (loc_id,
name);
976 H5Gget_num_objs (group_id, &num_obj);
982 while (current_item < static_cast<int> (num_obj)
1001 octave_unused_parameter (loc_id);
1002 octave_unused_parameter (
name);
1018 for (
int i = 0;
i < nf;
i++)
1019 f[
i] = kv[
i].c_str ();
1029 for (
int i = 0;
i < nf;
i++)
1036 for (
mwIndex j =
i; j < ntot; j += nf)
1063 void *here =
reinterpret_cast<void *
>(&sm_ptr);
1064 return (
x.get_rep ().fast_elem_insert_self (here,
btyp_struct)
1079 assert (idx.
length () == 1);
1089 "structure has no member '%s'",
nm.c_str ());
1096 const std::list<octave_value_list>& idx)
1106 if (idx.size () > 1)
1117 const std::list<octave_value_list>& idx,
1128 if (idx.size () > 1)
1139 const std::list<octave_value_list>& idx,
1150 if (idx.size () > 1)
1174 if (
type.length () > 0 &&
type[0] ==
'.' && !
val.isstruct ())
1184 const std::list<octave_value_list>& idx,
1189 if (idx.front ().empty ())
1190 error (
"missing index in indexed assignment");
1194 int n =
type.length ();
1200 assert (key_idx.
length () == 1);
1208 std::list<octave_value_list> next_idx (idx);
1210 next_idx.erase (next_idx.begin ());
1222 bool orig_undefined =
tmp.is_undefined ();
1224 if (orig_undefined ||
tmp.is_zero_by_zero ())
1231 tmp.make_unique (1);
1233 t_rhs = (orig_undefined
1234 ?
tmp.undef_subsasgn (next_type, next_idx, rhs)
1235 :
tmp.subsasgn (next_type, next_idx, rhs));
1296 bool print_fieldnames_only = max_depth_reached;
1301 os <<
"scalar structure containing the fields:";
1316 if (print_fieldnames_only)
1321 os <<
": " <<
dv.
str () <<
' ' <<
val.type_name ();
1325 val.print_with_name (
os, key);
1334 os <<
"<structure>";
1373 return "[" + dimstr +
" " + tname +
"]";
1385 os <<
"# ndims: " <<
dv.
ndims () <<
"\n";
1391 os <<
"# length: " << nf <<
"\n";
1406 return !
os.fail ();
1418 error (
"load: failed to extract number of elements in structure");
1440 error (
"load: failed to load structure");
1460 os.
write (reinterpret_cast<char *> (&len), 4);
1475 return !
os.fail ();
1485 bool success =
true;
1487 if (!
is.read (reinterpret_cast<char *> (&len), 4))
1513 error (
"load: failed to load structure");
1529 #if defined (HAVE_HDF5) 1531 hid_t data_hid = -1;
1533 #if defined (HAVE_HDF5_18) 1537 data_hid = H5Gcreate (loc_id,
name, 0);
1539 if (data_hid < 0)
return false;
1563 H5Gclose (data_hid);
1568 octave_unused_parameter (loc_id);
1569 octave_unused_parameter (
name);
1583 #if defined (HAVE_HDF5) 1589 int current_item = 0;
1590 hsize_t num_obj = 0;
1591 #if defined (HAVE_HDF5_18) 1594 hid_t group_id = H5Gopen (loc_id,
name);
1596 H5Gget_num_objs (group_id, &num_obj);
1597 H5Gclose (group_id);
1602 while (current_item < static_cast<int> (num_obj)
1619 octave_unused_parameter (loc_id);
1620 octave_unused_parameter (
name);
1636 for (
int i = 0;
i < nf;
i++)
1637 f[
i] = kv[
i].c_str ();
1647 for (
int i = 0;
i < nf;
i++)
1654 for (
mwIndex j =
i; j < ntot; j += nf)
1681 DEFUN (
struct, args, ,
1738 int nargin = args.length ();
1749 return ovl (args(0));
1751 if (
nargin == 1 && args(0).isobject ())
1752 return ovl (args(0).map_value ());
1755 && args(0).isempty () && args(0).is_real_matrix ())
1759 Array<std::string> cstr = args(1).xcellstr_value (
"struct: second argument should be a cell array of field names");
1771 if (! args(
i).is_string () ||
i + 1 >=
nargin)
1772 error (R
"(struct: additional arguments must occur as "field", VALUE pairs)"); 1783 if (args(
i).iscell ())
1794 else if (
dims != argdims)
1796 error (
"struct: dimensions of parameter %d " 1797 "do not match those of parameter %d",
1822 if (args(
i+1).iscell ())
1865 if (args.length () != 1)
1871 DEFUN (__fieldnames__, args, ,
1910 if (args.length () != 2)
1915 if (args(0).isstruct ())
1921 if (args(1).is_string ())
1927 else if (args(1).iscell ())
1929 Cell c = args(1).cell_value ();
1935 if (
c(
i).is_string ())
1952 DEFUN (numfields, args, ,
1959 if (args.length () != 1)
1962 if (! args(0).isstruct ())
1963 error (
"numfields: argument must be a struct");
1965 return ovl (static_cast<double> (args(0).nfields ()));
2008 int nargin = args.length ();
2013 if (! args(0).iscell ())
2014 error (
"cell2struct: argument CELL must be of type cell");
2016 if (! (args(1).
iscellstr () || args(1).is_char_matrix ()))
2017 error (
"cell2struct: FIELDS must be a cell array of strings or a character matrix");
2023 if (! args(2).is_real_scalar ())
2024 error (
"cell2struct: DIM must be a real scalar");
2026 dim = (
nargin == 2 ? 0 : args(2).int_value () - 1);
2030 error (
"cell2struct: DIM must be a valid dimension");
2032 const Cell vals = args(0).cell_value ();
2037 if (ext !=
fields.numel ())
2038 error (
"cell2struct: number of FIELDS does not match dimension");
2044 assert (ext == rdv(dim));
2047 rdv(0) = rdv(1-dim);
2052 for (
int i = dim + 1;
i < nd;
i++)
2098 if (args.length () != 2)
2101 octave_map m = args(0).xmap_value (
"rmfield: first argument must be a struct");
2107 for (
int i = 0;
i < fcell.
numel ();
i++)
2112 error (
"rmfield: structure does not contain field %s", key.c_str ());
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)
static void err_invalid_index_for_assignment(void)
string_vector fieldnames(void) const
mxArray * as_mxArray(void) const
std::string str(char sep='x') const
Cell index(const octave_value_list &idx, bool resize_ok=false) const
void warning_with_id(const char *id, const char *fmt,...)
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode isstruct
#define SET_INTERNAL_VARIABLE_WITH_LIMITS(NM, MINVAL, MAXVAL)
octave_idx_type rows(void) const
scalar structure containing the fields
void err_nonbraced_cs_list_assignment(void)
std::string type_name(void) const
void delete_elements(const idx_vector &i)
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
void assign(const std::string &k, const Cell &val)
octave_value fast_elem_extract(octave_idx_type n) const
octave_idx_type nfields(void) const
bool print_name_tag(std::ostream &os, const std::string &name) const
octave_map map_value(void) const
static const idx_vector colon
string_vector fieldnames(void) const
dim_vector dims(void) const
OCTINTERP_API void print_usage(void)
bool print_name_tag(std::ostream &os, const std::string &name) const
identity matrix If supplied two scalar respectively For allows like xample val
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
size_t byte_size(void) const
static bool Vprint_struct_array_contents
bool save_ascii(std::ostream &os)
void newline(std::ostream &os) const
octave_map map_value(void) const
octave_scalar_map checkelem(octave_idx_type n) const
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
bool is_cs_list(void) const
void resize(int n, int fill_value=0)
mxArray * as_mxArray(void) const
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
size_t byte_size(void) const
void error(const char *fmt,...)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
#define SET_INTERNAL_VARIABLE(NM)
std::string key(const_iterator p) const
const_iterator seek(const std::string &k) const
bool save_ascii(std::ostream &os)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
void setfield(const std::string &key, const octave_value &val)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
octave_value to_array(void)
bool load_ascii(std::istream &is)
const_iterator end(void) const
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode rmfield
bool isobject(void) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
octave_idx_type numel(void) const
void warn_load(const char *type) const
void err_indexed_cs_list(void)
octave_value storable_value(void) const
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode cell2struct
octave_idx_type index(const_iterator p) const
bool isfield(const std::string &name) const
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
octave_value do_index_op(const octave_value_list &idx, bool resize_ok=false)
nd deftypefn *std::string name
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
static octave_value numeric_conv(const octave_value &val, const std::string &type)
void swap_bytes< 4 >(void *ptr)
static void err_invalid_index_type(const std::string &nm, char t)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
string_vector map_keys(void) const
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
bool valid_identifier(const char *s)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
octave_idx_type columns(void) const
Cell dotref(const octave_value_list &idx, bool auto_add=false)
void error_with_id(const char *id, const char *fmt,...)
octave_idx_type numel(void) const
const_iterator end(void) const
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
bool fast_elem_insert(octave_idx_type n, const octave_scalar_map &rhs)
const_iterator begin(void) const
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
#define panic_impossible()
void rmfield(const std::string &key)
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
const Cell & contents(const_iterator p) const
void decrement_indent_level(void) const
void warn_save(const char *type) const
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode nargin
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
bool all_scalars(void) const
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
octave_value getfield(const std::string &key) const
bool isstruct(void) const
std::string key(const_iterator p) const
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
octave_idx_type numel(void) const
dim_vector dims(void) const
void indent(std::ostream &os) const
OCTAVE_EXPORT octave_value_list iscellstr
octave_map map_value(void) const
friend class octave_value
void setfield(const std::string &key, const Cell &val)
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_idx_type nfields(void) const
void print(std::ostream &os, bool pr_as_read_syntax=false)
octave::unwind_protect frame
static int Vstruct_levels_to_print
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
charNDArray max(char d, const charNDArray &m)
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_idx_type nfields(void) const
octave_value_list list_value(void) const
const octave_value & contents(const_iterator p) const
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode isfield
bool is_undefined(void) const
octave_value dotref(const octave_value_list &idx, bool auto_add=false)
static octave_value numeric_conv(const octave_value &val, const std::string &type)
bool save_binary(std::ostream &os, bool &save_as_floats)
bool fast_elem_insert_self(void *where, builtin_type_t btyp) const
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)
Cell cell_value(void) const
octave_idx_type length(void) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void increment_indent_level(void) const
octave_scalar_map scalar_map_value(void) const
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
octave_map xmap_value(const char *fmt,...) const
octave::refcount< octave_idx_type > count
bool load_ascii(std::istream &is)
const octave_hdf5_id octave_H5P_DEFAULT
Cell reshape(const dim_vector &new_dims) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
octave_idx_type ndims(void) const
Number of dimensions.
octave_fields::const_iterator const_iterator
octave_idx_type numel(void) const
Number of elements in the array.
static void maybe_warn_invalid_field_name(const std::string &key, const char *who)
octave_idx_type nfields(void) const
write the output to stdout if nargout is
bool save_binary(std::ostream &os, bool &save_as_floats)
Vector representing the dimensions (size) of an Array.
const_iterator begin(void) const
const_iterator seek(const std::string &k) const
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
int first_dimensioned_value
void print(std::ostream &os, bool pr_as_read_syntax=false)
Cell xcell_value(const char *fmt,...) const
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
octave_base_value * try_narrowing_conversion(void)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
static bool scalar(const dim_vector &dims)
std::string edit_display(const float_display_format &fmt, octave_idx_type i, octave_idx_type j) const
string_vector map_keys(void) const