Mercurial > hg > octave-terminal
changeset 4197:40f76ce7a051
[project @ 2002-11-21 18:56:25 by jwe]
author | jwe |
---|---|
date | Thu, 21 Nov 2002 18:56:25 +0000 |
parents | f874c6c68845 |
children | af1d77a5e44d |
files | src/ChangeLog src/DLD-FUNCTIONS/fsolve.cc src/oct-map.cc src/oct-map.h src/ov-struct.cc |
diffstat | 5 files changed, 96 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-11-21 John W. Eaton <jwe@bevo.che.wisc.edu> + + * oct-map.h (Octave_map::operator[]): New const version. + * oct-map.cc (equiv_keys): New function. + (assign (const idx_vector&, const Octave_map&)): New function. + * ov-struct.cc (octave_struct::subsasgn): Use it. + 2002-11-20 John W. Eaton <jwe@bevo.che.wisc.edu> * version.h (OCTAVE_VERSION): Now 2.1.40.
--- a/src/DLD-FUNCTIONS/fsolve.cc +++ b/src/DLD-FUNCTIONS/fsolve.cc @@ -229,9 +229,9 @@ @ifinfo\n\ \n\ @example\n\ - df_i -jac = ---- - dx_j + df_i\n\ +jac(i,j) = ----\n\ + dx_j\n\ @end example\n\ @end ifinfo\n\ \n\
--- a/src/oct-map.cc +++ b/src/oct-map.cc @@ -34,6 +34,14 @@ #include "oct-map.h" #include "utils.h" +octave_value_list +Octave_map::operator [] (const std::string& key) const +{ + Pix p = map.seek (key); + + return p ? map.contents (p) : octave_value_list (); +} + string_vector Octave_map::keys (void) const { @@ -60,6 +68,58 @@ return array_len; } +static string_vector +equiv_keys (const Octave_map& a, const Octave_map& b) +{ + string_vector retval; + + string_vector a_keys = a.keys().qsort (); + string_vector b_keys = b.keys().qsort (); + + int a_len = a_keys.length (); + int b_len = b_keys.length (); + + if (a_len == b_len) + { + for (int i = 0; i < a_len; i++) + { + if (a_keys[i] != b_keys[i]) + return retval; + } + + retval = a_keys; + } + + return retval; +} + +Octave_map& +Octave_map::assign (const idx_vector& idx, const Octave_map& rhs) +{ + string_vector t_keys = empty () ? rhs.keys () : equiv_keys (*this, rhs); + + if (! t_keys.empty ()) + { + int len = t_keys.length (); + + for (int i = 0; i < len; i++) + { + std::string key = t_keys[i]; + + octave_value_list t_rhs = rhs[key]; + + assign (idx, key, t_rhs); + + if (error_state) + break; + } + } + else + error ("field name mismatch in structure assignment"); + + return *this; +} + Octave_map& Octave_map::assign (const idx_vector& idx, const std::string& key, const octave_value_list& rhs)
--- a/src/oct-map.h +++ b/src/oct-map.h @@ -67,6 +67,8 @@ octave_value_list& operator [] (const std::string& key) { return map[key]; } + octave_value_list operator [] (const std::string& key) const; + void del (const std::string& key) { map.del (key); } Pix first (void) const { return map.first (); } @@ -86,6 +88,8 @@ int array_length () const; + Octave_map& assign (const idx_vector& idx, const Octave_map& rhs); + Octave_map& assign (const idx_vector& idx, const std::string& key, const octave_value_list& rhs);
--- a/src/ov-struct.cc +++ b/src/ov-struct.cc @@ -331,7 +331,28 @@ gripe_failed_assignment (); } else - gripe_invalid_index_for_assignment (); + { + octave_value_list t_idx = idx.front (); + + if (t_idx.length () == 1) + { + idx_vector i = t_idx(0).index_vector (); + + Octave_map rhs_map = t_rhs.map_value (); + + if (! error_state) + { + map.assign (i, rhs_map); + + if (! error_state) + retval = octave_value (this, count + 1); + else + gripe_failed_assignment (); + } + else + error ("invalid structure assignment"); + } + } } break;