Mercurial > hg > octave-terminal
changeset 2413:44753e0cadf2
[project @ 1996-10-15 17:02:26 by jwe]
author | jwe |
---|---|
date | Tue, 15 Oct 1996 17:02:26 +0000 |
parents | 1a1901564492 |
children | 989c617b63ca |
files | src/ov.cc src/ov.h |
diffstat | 2 files changed, 144 insertions(+), 187 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ov.cc +++ b/src/ov.cc @@ -316,147 +316,12 @@ } static void -gripe_indexed_assignment (const string& tn1, const string& tn2) -{ - error ("assignment of %s to indexed %s not implemented", - tn2.c_str (), tn1.c_str ()); -} - -static void gripe_no_conversion (const string& tn1, const string& tn2) { error ("no suitable conversion found for assignment of %s to indexed %s", tn2.c_str (), tn1.c_str ()); } -static void -gripe_conversion_failed (const string& tn1, const string& tn2) -{ - error ("type conversion for assignment of %s to indexed %s failed", - tn2.c_str (), tn1.c_str ()); -} - -bool -octave_value::convert_and_assign (const octave_value_list& idx, - const octave_value& rhs) -{ - bool assignment_ok = false; - - int t_lhs = type_id (); - int t_rhs = rhs.type_id (); - - int t_result - = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); - - if (t_result >= 0) - { - octave_value::type_conv_fcn cf - = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); - - if (cf) - { - octave_value *tmp = cf (*rep); - - if (tmp) - { - if (tmp != rep) - { - if (--rep->count == 0) - delete rep; - - rep = tmp; - rep->count = 1; - } - else - delete tmp; - - assignment_ok = try_assignment (idx, rhs); - } - else - gripe_conversion_failed (type_name (), rhs.type_name ()); - } - else - gripe_indexed_assignment (type_name (), rhs.type_name ()); - } - - return (assignment_ok && ! error_state); -} - -bool -octave_value::try_assignment_with_conversion (const octave_value_list& idx, - const octave_value& rhs) -{ - bool assignment_ok = convert_and_assign (idx, rhs); - - if (! (error_state || assignment_ok)) - { - octave_value tmp_rhs; - octave_value::type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); - - if (cf_rhs) - tmp_rhs = octave_value (cf_rhs (*rhs.rep)); - else - tmp_rhs = rhs; - - octave_value *old_rep = 0; - octave_value::type_conv_fcn cf_this = numeric_conversion_function (); - - if (cf_this) - { - old_rep = rep; - rep = cf_this (*rep); - rep->count = 1; - } - - cerr << type_name () << "\n"; - cerr << tmp_rhs.type_name () << "\n"; - - if (cf_this || cf_rhs) - { - assignment_ok = try_assignment (idx, tmp_rhs); - - if (! (error_state || assignment_ok)) - assignment_ok = convert_and_assign (idx, tmp_rhs); - } - - if (! assignment_ok && old_rep) - { - if (--rep->count == 0) - delete rep; - - rep = old_rep; - old_rep = 0; - } - - if (old_rep && --old_rep->count == 0) - delete old_rep; - } - - return (assignment_ok && ! error_state); -} - -bool -octave_value::try_assignment (const octave_value_list& idx, - const octave_value& rhs) -{ - bool retval = false; - - int t_lhs = type_id (); - int t_rhs = rhs.type_id (); - - octave_value::assign_op_fcn f - = octave_value_typeinfo::lookup_assign_op (t_lhs, t_rhs); - - if (f) - { - f (*rep, idx, *(rhs.rep)); - - retval = (! error_state); - } - - return retval; -} - octave_value& octave_value::assign (const octave_value_list& idx, const octave_value& rhs) { @@ -627,6 +492,141 @@ } static void +gripe_indexed_assignment (const string& tn1, const string& tn2) +{ + error ("assignment of %s to indexed %s not implemented", + tn2.c_str (), tn1.c_str ()); +} + +static void +gripe_conversion_failed (const string& tn1, const string& tn2) +{ + error ("type conversion for assignment of %s to indexed %s failed", + tn2.c_str (), tn1.c_str ()); +} + +bool +octave_value::convert_and_assign (const octave_value_list& idx, + const octave_value& rhs) +{ + bool assignment_ok = false; + + int t_lhs = type_id (); + int t_rhs = rhs.type_id (); + + int t_result + = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); + + if (t_result >= 0) + { + octave_value::type_conv_fcn cf + = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); + + if (cf) + { + octave_value *tmp = cf (*rep); + + if (tmp) + { + if (tmp != rep) + { + if (--rep->count == 0) + delete rep; + + rep = tmp; + rep->count = 1; + } + else + delete tmp; + + assignment_ok = try_assignment (idx, rhs); + } + else + gripe_conversion_failed (type_name (), rhs.type_name ()); + } + else + gripe_indexed_assignment (type_name (), rhs.type_name ()); + } + + return (assignment_ok && ! error_state); +} + +bool +octave_value::try_assignment_with_conversion (const octave_value_list& idx, + const octave_value& rhs) +{ + bool assignment_ok = convert_and_assign (idx, rhs); + + if (! (error_state || assignment_ok)) + { + octave_value tmp_rhs; + octave_value::type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); + + if (cf_rhs) + tmp_rhs = octave_value (cf_rhs (*rhs.rep)); + else + tmp_rhs = rhs; + + octave_value *old_rep = 0; + octave_value::type_conv_fcn cf_this = numeric_conversion_function (); + + if (cf_this) + { + old_rep = rep; + rep = cf_this (*rep); + rep->count = 1; + } + + cerr << type_name () << "\n"; + cerr << tmp_rhs.type_name () << "\n"; + + if (cf_this || cf_rhs) + { + assignment_ok = try_assignment (idx, tmp_rhs); + + if (! (error_state || assignment_ok)) + assignment_ok = convert_and_assign (idx, tmp_rhs); + } + + if (! assignment_ok && old_rep) + { + if (--rep->count == 0) + delete rep; + + rep = old_rep; + old_rep = 0; + } + + if (old_rep && --old_rep->count == 0) + delete old_rep; + } + + return (assignment_ok && ! error_state); +} + +bool +octave_value::try_assignment (const octave_value_list& idx, + const octave_value& rhs) +{ + bool retval = false; + + int t_lhs = type_id (); + int t_rhs = rhs.type_id (); + + octave_value::assign_op_fcn f + = octave_value_typeinfo::lookup_assign_op (t_lhs, t_rhs); + + if (f) + { + f (*rep, idx, *(rhs.rep)); + + retval = (! error_state); + } + + return retval; +} + +static void gripe_binary_op (const string& on, const string& tn1, const string& tn2) { error ("binary operator %s not implemented for %s by %s operations",
--- a/src/ov.h +++ b/src/ov.h @@ -184,15 +184,6 @@ virtual octave_value index (const octave_value_list& idx) const { return rep->index (idx); } - bool convert_and_assign (const octave_value_list& idx, - const octave_value& rhs); - - bool try_assignment_with_conversion (const octave_value_list& idx, - const octave_value& rhs); - - bool try_assignment (const octave_value_list& idx, - const octave_value& rhs); - octave_value& assign (const octave_value_list& idx, const octave_value& rhs); virtual idx_vector index_vector (void) const @@ -204,19 +195,6 @@ virtual octave_value& struct_elt_ref (const string& nm) { return rep->struct_elt_ref (nm); } -#if 0 - // Simple structure assignment. - - octave_value assign_map_element (SLList<string>& list, - octave_value& rhs); - - // Indexed structure assignment. - - octave_value assign_map_element (SLList<string>& list, - octave_value& rhs, - const octave_value_list& args); -#endif - // Size. virtual int rows (void) const @@ -361,18 +339,6 @@ rep->decrement (); } -#if 0 - virtual octave_value - lookup_map_element (const string& ref, bool insert = false, - bool silent = false) - { return lookup_map_element (ref, insert, silent); } - - virtual octave_value - lookup_map_element (SLList<string>& list, bool insert = false, - bool silent = false) - { return rep->lookup_map_element (list, insert, silent); } -#endif - ColumnVector vector_value (bool frc_str_conv = false, bool frc_vec_conv = false) const; @@ -403,15 +369,6 @@ virtual string type_name (void) const { return rep->type_name (); } -#if 0 - octave_value_rep *make_unique_map (void); - - // We want to eliminate this, or at least make it private. - - virtual octave_value_rep::constant_type const_type (void) const - { return rep->const_type (); } -#endif - virtual void convert_to_matrix_type (bool make_complex) { rep->convert_to_matrix_type (make_complex); } @@ -428,15 +385,6 @@ return *this; } -#if 0 - { - if (is_numeric_type ()) - return *this; - else - return rep->make_numeric (frc_str_conv); - } -#endif - bool print_as_scalar (void); bool print_as_structure (void) { return is_map (); } @@ -458,6 +406,15 @@ octave_value *rep; // The real representation. int count; // A reference count. }; + + bool convert_and_assign (const octave_value_list& idx, + const octave_value& rhs); + + bool try_assignment_with_conversion (const octave_value_list& idx, + const octave_value& rhs); + + bool try_assignment (const octave_value_list& idx, + const octave_value& rhs); }; // If TRUE, allow assignments like