Mercurial > hg > octave-avbm
changeset 6946:10c7a803b409
[project @ 2007-10-03 14:38:48 by jwe]
author | jwe |
---|---|
date | Wed, 03 Oct 2007 14:38:48 +0000 |
parents | 6bbf56a9718a |
children | 4b41514e5ef0 |
files | src/ChangeLog src/oct-map.cc src/oct-map.h src/ov-struct.cc |
diffstat | 4 files changed, 39 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2007-10-03 John W. Eaton <jwe@octave.org> + + * oct-map.cc (Octave_map::Octave_map (const dim_vector&, + const string_vector&)): Delete. + (Octave_map::Octave_map (const dim_vector&, const Cell&)): + New function. + * ov-struct.cc (Fstruct): Allow creation of empty struct arrays + with field names. + 2007-10-01 Shai Ayal <shaiay@users.sourceforge.net> * graphics.cc ((color_property::color_property (const
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -31,18 +31,22 @@ #include "oct-map.h" #include "utils.h" -Octave_map::Octave_map (const dim_vector& dv, - const string_vector& key_list_arg) +Octave_map::Octave_map (const dim_vector& dv, const Cell& keys) : map (), key_list (), dimensions (dv) { Cell c (dv); - for (octave_idx_type i = 0; i < key_list_arg.length (); i++) + if (keys.is_cellstr ()) { - std::string k = key_list_arg[i]; - map[k] = c; - key_list.push_back (k); + for (octave_idx_type i = 0; i < keys.numel (); i++) + { + std::string k = keys(i).string_value (); + map[k] = c; + key_list.push_back (k); + } } + else + error ("Octave_map: expecting keys to be cellstr"); } Cell&
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -47,7 +47,7 @@ // Warning! You should always use at least two dimensions. Octave_map (const dim_vector& dv = dim_vector (0, 0), - const string_vector& key_list_arg = string_vector ()); + const Cell& keys = Cell ()); Octave_map (const std::string& k, const octave_value& value) : map (), key_list (), dimensions (1, 1)
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -560,7 +560,7 @@ array with the specified field names.\n\ @end deftypefn") { - octave_value_list retval; + octave_value retval; int nargin = args.length (); @@ -572,8 +572,23 @@ // Note that struct () creates a 1x1 struct with no fields for // compatibility with Matlab. - if (nargin == 1 && args(0).is_empty () && args(0).is_real_matrix ()) - return octave_value (Octave_map (args(0).dims ())); + if ((nargin == 1 || nargin == 2) + && args(0).is_empty () && args(0).is_real_matrix ()) + { + Cell fields; + + if (nargin == 2) + { + if (args(1).is_cellstr ()) + retval = Octave_map (args(0).dims (), args(1).cell_value ()); + else + error ("struct: expecting cell array of field names as second argument"); + } + else + retval = Octave_map (args(0).dims ()); + + return retval; + } // Check for "field", VALUE pairs. @@ -658,7 +673,7 @@ if (error_state) return retval; } - + return octave_value (map); }