Mercurial > hg > octave-nkf
diff src/ov-class.cc @ 10315:57a59eae83cc
untabify src C++ source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:41:46 -0500 |
parents | 272179888089 |
children | 9c4daf174387 |
line wrap: on
line diff
--- a/src/ov-class.cc +++ b/src/ov-class.cc @@ -67,7 +67,7 @@ } octave_class::octave_class (const Octave_map& m, const std::string& id, - const octave_value_list& parents) + const octave_value_list& parents) : octave_base_value (), map (m), c_name (id), obsolete_copies (0) { octave_idx_type n = parents.length (); @@ -77,20 +77,20 @@ octave_value parent = parents(idx); if (! parent.is_object ()) - error ("parents must be objects"); + error ("parents must be objects"); else - { - std::string cnm = parent.class_name (); + { + std::string cnm = parent.class_name (); - if (find_parent_class (cnm)) - error ("duplicate class in parent tree"); - else - { - parent_list.push_back (cnm); + if (find_parent_class (cnm)) + error ("duplicate class in parent tree"); + else + { + parent_list.push_back (cnm); - map.assign (cnm, parent); - } - } + map.assign (cnm, parent); + } + } } if (! error_state) @@ -161,7 +161,7 @@ for (octave_idx_type i = 0; i < ovl.length (); i++) { if (retval(i).is_magic_colon ()) - retval(i) = ":"; + retval(i) = ":"; } return retval; @@ -169,8 +169,8 @@ static inline octave_value make_idx_args (const std::string& type, - const std::list<octave_value_list>& idx, - const std::string& who) + const std::list<octave_value_list>& idx, + const std::string& who) { octave_value retval; @@ -184,52 +184,52 @@ std::list<octave_value_list>::const_iterator p = idx.begin (); for (size_t i = 0; i < len; i++) - { - char t = type[i]; + { + char t = type[i]; - switch (t) - { - case '(': - type_field(i) = "()"; - subs_field(i) = Cell (sanitize (*p++)); - break; + switch (t) + { + case '(': + type_field(i) = "()"; + subs_field(i) = Cell (sanitize (*p++)); + break; - case '{': - type_field(i) = "{}"; - subs_field(i) = Cell (sanitize (*p++)); - break; + case '{': + type_field(i) = "{}"; + subs_field(i) = Cell (sanitize (*p++)); + break; - case '.': - { - type_field(i) = "."; + case '.': + { + type_field(i) = "."; - octave_value_list vlist = *p++; + octave_value_list vlist = *p++; - if (vlist.length () == 1) - { - octave_value val = vlist(0); + if (vlist.length () == 1) + { + octave_value val = vlist(0); - if (val.is_string ()) - subs_field(i) = val; - else - { - error ("expecting character string argument for `.' index"); - return retval; - } - } - else - { - error ("expecting single argument for `.' index"); - return retval; - } - } - break; + if (val.is_string ()) + subs_field(i) = val; + else + { + error ("expecting character string argument for `.' index"); + return retval; + } + } + else + { + error ("expecting single argument for `.' index"); + return retval; + } + } + break; - default: - panic_impossible (); - break; - } - } + default: + panic_impossible (); + break; + } + } Octave_map m; @@ -270,9 +270,9 @@ Octave_map::const_iterator p = my_map.seek (nm); if (p != my_map.end ()) - retval = my_map.contents (p); + retval = my_map.contents (p); else - error ("class has no member `%s'", nm.c_str ()); + error ("class has no member `%s'", nm.c_str ()); } else gripe_invalid_index (); @@ -353,8 +353,8 @@ octave_value_list octave_class::subsref (const std::string& type, - const std::list<octave_value_list>& idx, - int nargout) + const std::list<octave_value_list>& idx, + int nargout) { octave_value_list retval; @@ -367,75 +367,75 @@ int skip = 1; switch (type[0]) - { - case '(': - { - if (type.length () > 1 && type[1] == '.') - { - std::list<octave_value_list>::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; + { + case '(': + { + if (type.length () > 1 && type[1] == '.') + { + std::list<octave_value_list>::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; - Cell tmp = dotref (key_idx); + Cell tmp = dotref (key_idx); - if (! error_state) - { - Cell t = tmp.index (idx.front ()); + if (! error_state) + { + Cell t = tmp.index (idx.front ()); - retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); - // We handled two index elements, so tell - // next_subsref to skip both of them. + // We handled two index elements, so tell + // next_subsref to skip both of them. - skip++; - } - } - else - retval(0) = octave_value (map.index (idx.front ()), - class_name ()); - } - break; + skip++; + } + } + else + retval(0) = octave_value (map.index (idx.front ()), + class_name ()); + } + break; - case '.': - { - if (map.numel() > 0) - { - Cell t = dotref (idx.front ()); + case '.': + { + if (map.numel() > 0) + { + Cell t = dotref (idx.front ()); - retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); - } - } - break; + retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); + } + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } // FIXME -- perhaps there should be an // octave_value_list::next_subsref member function? See also // octave_user_function::subsref. if (idx.size () > 1) - retval = retval(0).next_subsref (nargout, type, idx, skip); + retval = retval(0).next_subsref (nargout, type, idx, skip); } else { octave_value meth = symbol_table::find_method ("subsref", class_name ()); if (meth.is_defined ()) - { - octave_value_list args; + { + octave_value_list args; - args(1) = make_idx_args (type, idx, "subsref"); + args(1) = make_idx_args (type, idx, "subsref"); - if (error_state) - return octave_value_list (); + if (error_state) + return octave_value_list (); - count++; - args(0) = octave_value (this); + count++; + args(0) = octave_value (this); // FIXME: for Matlab compatibility, let us attempt to set up a proper // value for nargout at least in the simple case where the @@ -463,14 +463,14 @@ // rvalue1 calls. if (retval.length () > 1) retval = octave_value (retval, true); - } + } else - { - if (type.length () == 1 && type[0] == '(') - retval(0) = octave_value (map.index (idx.front ()), class_name ()); - else - gripe_invalid_index (); - } + { + if (type.length () == 1 && type[0] == '(') + retval(0) = octave_value (map.index (idx.front ()), class_name ()); + else + gripe_invalid_index (); + } } return retval; @@ -486,7 +486,7 @@ retval = val(0); if (type.length () > 0 && type[0] == '.' && ! retval.is_map ()) - retval = Octave_map (); + retval = Octave_map (); } else gripe_invalid_index_for_assignment (); @@ -496,8 +496,8 @@ octave_value octave_class::subsasgn (const std::string& type, - const std::list<octave_value_list>& idx, - const octave_value& rhs) + const std::list<octave_value_list>& idx, + const octave_value& rhs) { octave_value retval; @@ -506,8 +506,8 @@ octave_value meth = symbol_table::find_method ("subsasgn", class_name ()); if (meth.is_defined ()) - { - octave_value_list args; + { + octave_value_list args; if (rhs.is_cs_list ()) { @@ -519,13 +519,13 @@ else args(2) = rhs; - args(1) = make_idx_args (type, idx, "subsasgn"); + args(1) = make_idx_args (type, idx, "subsasgn"); - if (error_state) - return octave_value_list (); + if (error_state) + return octave_value_list (); - count++; - args(0) = octave_value (this); + count++; + args(0) = octave_value (this); // Now comes the magic. Count copies with me: // 1. myself (obsolete) @@ -554,18 +554,18 @@ else tmp = feval (meth.function_value (), args); - // FIXME -- should the subsasgn method be able to return - // more than one value? + // FIXME -- should the subsasgn method be able to return + // more than one value? - if (tmp.length () > 1) - error ("expecting single return value from @%s/subsasgn", - class_name().c_str ()); + if (tmp.length () > 1) + error ("expecting single return value from @%s/subsasgn", + class_name().c_str ()); - else - retval = tmp(0); + else + retval = tmp(0); - return retval; - } + return retval; + } } // FIXME -- this block of code is the same as the body of @@ -579,65 +579,65 @@ if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) { switch (type[0]) - { - case '(': - { - if (type.length () > 1 && type[1] == '.') - { - std::list<octave_value_list>::const_iterator p = idx.begin (); - octave_value_list t_idx = *p; + { + case '(': + { + if (type.length () > 1 && type[1] == '.') + { + std::list<octave_value_list>::const_iterator p = idx.begin (); + octave_value_list t_idx = *p; - octave_value_list key_idx = *++p; + octave_value_list key_idx = *++p; - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - octave_value u; + if (! error_state) + { + octave_value u; - if (! map.contains (key)) - u = octave_value::empty_conv (type.substr (2), rhs); - else - { - Cell map_val = map.contents (key); + if (! map.contains (key)) + u = octave_value::empty_conv (type.substr (2), rhs); + else + { + Cell map_val = map.contents (key); - Cell map_elt = map_val.index (idx.front (), true); + Cell map_elt = map_val.index (idx.front (), true); - u = numeric_conv (map_elt, type.substr (2)); - } + u = numeric_conv (map_elt, type.substr (2)); + } - if (! error_state) - { - std::list<octave_value_list> next_idx (idx); + if (! error_state) + { + std::list<octave_value_list> next_idx (idx); - // We handled two index elements, so subsasgn to - // needs to skip both of them. + // We handled two index elements, so subsasgn to + // needs to skip both of them. - next_idx.erase (next_idx.begin ()); - next_idx.erase (next_idx.begin ()); + next_idx.erase (next_idx.begin ()); + next_idx.erase (next_idx.begin ()); - u.make_unique (); + u.make_unique (); - t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); - } - } - else - gripe_invalid_index_for_assignment (); - } - else - gripe_invalid_index_for_assignment (); - } - break; + t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); + } + } + else + gripe_invalid_index_for_assignment (); + } + else + gripe_invalid_index_for_assignment (); + } + break; - case '.': - { - octave_value_list key_idx = idx.front (); + case '.': + { + octave_value_list key_idx = idx.front (); - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); std::list<octave_value_list> next_idx (idx); @@ -675,134 +675,134 @@ else gripe_indexed_cs_list (); } - } - break; + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } if (! error_state) { switch (type[0]) - { - case '(': - { - if (n > 1 && type[1] == '.') - { - std::list<octave_value_list>::const_iterator p = idx.begin (); - octave_value_list key_idx = *++p; + { + case '(': + { + if (n > 1 && type[1] == '.') + { + std::list<octave_value_list>::const_iterator p = idx.begin (); + octave_value_list key_idx = *++p; - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - map.assign (idx.front (), key, t_rhs); + if (! error_state) + { + map.assign (idx.front (), key, t_rhs); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - gripe_failed_assignment (); - } - else - { - if (t_rhs.is_object () || t_rhs.is_map ()) - { - Octave_map rhs_map = t_rhs.map_value (); + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + gripe_failed_assignment (); + } + else + { + if (t_rhs.is_object () || t_rhs.is_map ()) + { + Octave_map rhs_map = t_rhs.map_value (); - if (! error_state) - { - map.assign (idx.front (), rhs_map); + if (! error_state) + { + map.assign (idx.front (), rhs_map); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - error ("invalid class assignment"); - } - else - { - if (t_rhs.is_empty ()) - { - map.maybe_delete_elements (idx.front()); + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("invalid class assignment"); + } + else + { + if (t_rhs.is_empty ()) + { + map.maybe_delete_elements (idx.front()); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - error ("invalid class assignment"); - } - } - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("invalid class assignment"); + } + } + } + break; - case '.': - { - // Find the class in which this method resides before - // attempting to access the requested field. + case '.': + { + // Find the class in which this method resides before + // attempting to access the requested field. - std::string method_class = get_current_method_class (); + std::string method_class = get_current_method_class (); - octave_base_value *obvp = unique_parent_class (method_class); + octave_base_value *obvp = unique_parent_class (method_class); - if (obvp) - { - octave_value_list key_idx = idx.front (); + if (obvp) + { + octave_value_list key_idx = idx.front (); - assert (key_idx.length () == 1); + assert (key_idx.length () == 1); - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - obvp->assign (key, t_rhs); + if (! error_state) + { + obvp->assign (key, t_rhs); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - gripe_failed_assignment (); - } - else - error ("malformed class"); - } - break; + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + gripe_failed_assignment (); + } + else + error ("malformed class"); + } + break; - case '{': - gripe_invalid_index_type (type_name (), type[0]); - break; + case '{': + gripe_invalid_index_type (type_name (), type[0]); + break; - default: - panic_impossible (); - } + default: + panic_impossible (); + } } else gripe_failed_assignment (); @@ -825,21 +825,21 @@ octave_value_list tmp = feval (meth.function_value (), args, 1); if (!error_state && tmp.length () >= 1) - { - if (tmp(0).is_object()) - error ("subsindex function must return a valid index vector"); - else - // Index vector returned by subsindex is zero based - // (why this inconsistency Mathworks?), and so we must - // add one to the value returned as the index_vector method - // expects it to be one based. - retval = do_binary_op (octave_value::op_add, tmp (0), - octave_value (1.0)).index_vector (); - } + { + if (tmp(0).is_object()) + error ("subsindex function must return a valid index vector"); + else + // Index vector returned by subsindex is zero based + // (why this inconsistency Mathworks?), and so we must + // add one to the value returned as the index_vector method + // expects it to be one based. + retval = do_binary_op (octave_value::op_add, tmp (0), + octave_value (1.0)).index_vector (); + } } else error ("no subsindex method defined for class %s", - class_name().c_str ()); + class_name().c_str ()); return retval; } @@ -881,22 +881,22 @@ else { for (std::list<std::string>::iterator pit = parent_list.begin (); - pit != parent_list.end (); - pit++) - { - Octave_map::const_iterator smap = map.seek (*pit); + pit != parent_list.end (); + pit++) + { + Octave_map::const_iterator smap = map.seek (*pit); - const Cell& tmp = smap->second; + const Cell& tmp = smap->second; - octave_value vtmp = tmp(0); + octave_value vtmp = tmp(0); - octave_base_value *obvp = vtmp.internal_rep (); + octave_base_value *obvp = vtmp.internal_rep (); - retval = obvp->find_parent_class (parent_class_name); + retval = obvp->find_parent_class (parent_class_name); - if (retval) - break; - } + if (retval) + break; + } } return retval; @@ -912,21 +912,21 @@ else { for (std::list<std::string>::iterator pit = parent_list.begin (); - pit != parent_list.end (); - pit++) - { - Octave_map::iterator smap = map.seek (*pit); + pit != parent_list.end (); + pit++) + { + Octave_map::iterator smap = map.seek (*pit); - Cell& tmp = smap->second; + Cell& tmp = smap->second; - octave_value& vtmp = tmp(0); + octave_value& vtmp = tmp(0); - octave_base_value *obvp = vtmp.internal_rep (); + octave_base_value *obvp = vtmp.internal_rep (); // Use find_parent_class first to avoid uniquifying if not necessary. - retval = obvp->find_parent_class (parent_class_name); + retval = obvp->find_parent_class (parent_class_name); - if (retval) + if (retval) { vtmp.make_unique (); obvp = vtmp.internal_rep (); @@ -934,7 +934,7 @@ break; } - } + } } return retval; @@ -973,7 +973,7 @@ void octave_class::print_with_name (std::ostream& os, const std::string& name, - bool) + bool) { octave_value fcn = symbol_table::find_method ("display", class_name ()); @@ -1018,16 +1018,16 @@ octave_value ctor = symbol_table::find_method (c_name, c_name); if (ctor.is_defined ()) - { - octave_value_list result = feval (ctor, 1); + { + octave_value_list result = feval (ctor, 1); - if (result.length () == 1) - retval = true; - else - warning ("call to constructor for class %s failed", c_name.c_str ()); - } + if (result.length () == 1) + retval = true; + else + warning ("call to constructor for class %s failed", c_name.c_str ()); + } else - warning ("no constructor for class %s", c_name.c_str ()); + warning ("no constructor for class %s", c_name.c_str ()); } return retval; @@ -1058,41 +1058,41 @@ std::string key = map.key (p); Cell val = map.contents (p); if ( val(0).is_object() ) - { - dbgstr = "blork"; - if( key == val(0).class_name() ) - { - might_have_inheritance = true; - dbgstr = "cork"; - break; - } - } + { + dbgstr = "blork"; + if( key == val(0).class_name() ) + { + might_have_inheritance = true; + dbgstr = "cork"; + break; + } + } } if (might_have_inheritance) { octave_class::exemplar_const_iterator it - = octave_class::exemplar_map.find (c_name); + = octave_class::exemplar_map.find (c_name); if (it == octave_class::exemplar_map.end ()) - retval = false; + retval = false; else - { - octave_class::exemplar_info exmplr = it->second; - parent_list = exmplr.parents (); - for (std::list<std::string>::iterator pit = parent_list.begin (); - pit != parent_list.end (); - pit++) - { - dbgstr = *pit; - bool dbgbool = map.contains (*pit); - if (!dbgbool) - { - retval = false; - break; - } - } - } + { + octave_class::exemplar_info exmplr = it->second; + parent_list = exmplr.parents (); + for (std::list<std::string>::iterator pit = parent_list.begin (); + pit != parent_list.end (); + pit++) + { + dbgstr = *pit; + bool dbgbool = map.contains (*pit); + if (!dbgbool) + { + retval = false; + break; + } + } + } } return retval; @@ -1108,9 +1108,9 @@ octave_value in = new octave_class (*this); octave_value_list tmp = feval ("saveobj", in, 1); if (! error_state) - m = tmp(0).map_value (); + m = tmp(0).map_value (); else - return false; + return false; } else m = map_value (); @@ -1125,7 +1125,7 @@ bool b = save_ascii_data (os, val, m.key (i), false, 0); if (! b) - return os; + return os; i++; } @@ -1143,77 +1143,77 @@ if (extract_keyword (is, "classname", classname) && classname != "") { if (extract_keyword (is, "length", len) && len >= 0) - { - if (len > 0) - { - Octave_map m (map); + { + if (len > 0) + { + Octave_map m (map); - for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; + for (octave_idx_type j = 0; j < len; j++) + { + octave_value t2; + bool dummy; - // recurse to read cell elements - std::string nm - = read_ascii_data (is, std::string (), dummy, t2, j); + // recurse to read cell elements + std::string nm + = read_ascii_data (is, std::string (), dummy, t2, j); - if (! is) - break; + if (! is) + break; - Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); + Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); - if (error_state) - { - error ("load: internal error loading class elements"); - return false; - } + if (error_state) + { + error ("load: internal error loading class elements"); + return false; + } - m.assign (nm, tcell); - } + m.assign (nm, tcell); + } - if (is) - { - c_name = classname; - reconstruct_exemplar (); + if (is) + { + c_name = classname; + reconstruct_exemplar (); - map = m; - - if (! reconstruct_parents ()) - warning ("load: unable to reconstruct object inheritance"); - else - { - if (load_path::find_method (classname, "loadobj") - != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + map = m; + + if (! reconstruct_parents ()) + warning ("load: unable to reconstruct object inheritance"); + else + { + if (load_path::find_method (classname, "loadobj") + != std::string ()) + { + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - map = tmp(0).map_value (); - else - success = false; - } - } - } - else - { - error ("load: failed to load class"); - success = false; - } - } - else if (len == 0 ) - { - map = Octave_map (dim_vector (1, 1)); - c_name = classname; - } - else - panic_impossible (); - } + if (! error_state) + map = tmp(0).map_value (); + else + success = false; + } + } + } + else + { + error ("load: failed to load class"); + success = false; + } + } + else if (len == 0 ) + { + map = Octave_map (dim_vector (1, 1)); + c_name = classname; + } + else + panic_impossible (); + } else - { - error ("load: failed to extract number of elements in class"); - success = false; - } + { + error ("load: failed to extract number of elements in class"); + success = false; + } } else { @@ -1238,9 +1238,9 @@ octave_value in = new octave_class (*this); octave_value_list tmp = feval ("saveobj", in, 1); if (! error_state) - m = tmp(0).map_value (); + m = tmp(0).map_value (); else - return false; + return false; } else m = map_value (); @@ -1256,7 +1256,7 @@ bool b = save_binary_data (os, val, m.key (i), "", 0, save_as_floats); if (! b) - return os; + return os; i++; } @@ -1266,7 +1266,7 @@ bool octave_class::load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) + oct_mach_info::float_format fmt) { bool success = true; @@ -1298,54 +1298,54 @@ Octave_map m (map); for (octave_idx_type j = 0; j < len; j++) - { - octave_value t2; - bool dummy; - std::string doc; + { + octave_value t2; + bool dummy; + std::string doc; - // recurse to read cell elements - std::string nm = read_binary_data (is, swap, fmt, std::string (), - dummy, t2, doc); + // recurse to read cell elements + std::string nm = read_binary_data (is, swap, fmt, std::string (), + dummy, t2, doc); - if (! is) - break; + if (! is) + break; - Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); + Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); - if (error_state) - { - error ("load: internal error loading class elements"); - return false; - } + if (error_state) + { + error ("load: internal error loading class elements"); + return false; + } - m.assign (nm, tcell); - } + m.assign (nm, tcell); + } if (is) - { - map = m; + { + map = m; - if (! reconstruct_parents ()) - warning ("load: unable to reconstruct object inheritance"); - else - { - if (load_path::find_method (c_name, "loadobj") != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + if (! reconstruct_parents ()) + warning ("load: unable to reconstruct object inheritance"); + else + { + if (load_path::find_method (c_name, "loadobj") != std::string ()) + { + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - map = tmp(0).map_value (); - else - success = false; - } - } - } + if (! error_state) + map = tmp(0).map_value (); + else + success = false; + } + } + } else - { - warning ("load: failed to load class"); - success = false; - } + { + warning ("load: failed to load class"); + success = false; + } } else if (len == 0 ) map = Octave_map (dim_vector (1, 1)); @@ -1388,13 +1388,13 @@ goto error_cleanup; #if HAVE_HDF5_18 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid, - H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); #else class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid, - H5P_DEFAULT); + H5P_DEFAULT); #endif if (class_hid < 0 || H5Dwrite (class_hid, type_hid, H5S_ALL, H5S_ALL, - H5P_DEFAULT, c_name.c_str ()) < 0) + H5P_DEFAULT, c_name.c_str ()) < 0) goto error_cleanup; #if HAVE_HDF5_18 @@ -1410,9 +1410,9 @@ octave_value in = new octave_class (*this); octave_value_list tmp = feval ("saveobj", in, 1); if (! error_state) - m = tmp(0).map_value (); + m = tmp(0).map_value (); else - goto error_cleanup; + goto error_cleanup; } else m = map_value (); @@ -1424,10 +1424,10 @@ octave_value val = map.contents (i); bool retval2 = add_hdf5_data (data_hid, val, m.key (i), "", false, - save_as_floats); + save_as_floats); if (! retval2) - break; + break; i++; } @@ -1497,7 +1497,7 @@ if (type_class_hid != H5T_STRING) goto error_cleanup; - + space_hid = H5Dget_space (data_hid); rank = H5Sget_simple_extent_ndims (space_hid); @@ -1518,13 +1518,13 @@ H5Tset_size (st_id, slen); if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, - classname) < 0) - { - H5Tclose (st_id); - H5Dclose (data_hid); - H5Gclose (group_hid); - return false; - } + classname) < 0) + { + H5Tclose (st_id); + H5Dclose (data_hid); + H5Gclose (group_hid); + return false; + } H5Tclose (st_id); H5Dclose (data_hid); @@ -1544,18 +1544,18 @@ H5Gclose (subgroup_hid); while (current_item < static_cast<int> (num_obj) - && (retval2 = H5Giterate (group_hid, name, ¤t_item, - hdf5_read_next_data, &dsub)) > 0) + && (retval2 = H5Giterate (group_hid, name, ¤t_item, + hdf5_read_next_data, &dsub)) > 0) { octave_value t2 = dsub.tc; Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); if (error_state) - { - error ("load: internal error loading class elements"); - return false; - } + { + error ("load: internal error loading class elements"); + return false; + } m.assign (dsub.name, tcell); @@ -1566,25 +1566,25 @@ map = m; if (!reconstruct_parents ()) - warning ("load: unable to reconstruct object inheritance"); + warning ("load: unable to reconstruct object inheritance"); else - { - if (load_path::find_method (c_name, "loadobj") != std::string ()) - { - octave_value in = new octave_class (*this); - octave_value_list tmp = feval ("loadobj", in, 1); + { + if (load_path::find_method (c_name, "loadobj") != std::string ()) + { + octave_value in = new octave_class (*this); + octave_value_list tmp = feval ("loadobj", in, 1); - if (! error_state) - { - map = tmp(0).map_value (); - retval = true; - } - else - retval = false; - } - else - retval = true; - } + if (! error_state) + { + map = tmp(0).map_value (); + retval = true; + } + else + retval = false; + } + else + retval = true; + } } error_cleanup: @@ -1613,10 +1613,10 @@ octave_function *fcn = octave_call_stack::current (); return (fcn - && (fcn->is_class_method () - || fcn->is_class_constructor () - || fcn->is_private_function_of_class (class_name ())) - && find_parent_class (fcn->dispatch_class ())); + && (fcn->is_class_method () + || fcn->is_class_constructor () + || fcn->is_private_function_of_class (class_name ())) + && find_parent_class (fcn->dispatch_class ())); } octave_class::exemplar_info::exemplar_info (const octave_value& obj) @@ -1645,51 +1645,51 @@ if (obj.is_object ()) { if (nfields () == obj.nfields ()) - { - Octave_map obj_map = obj.map_value (); - string_vector obj_fnames = obj_map.keys (); - string_vector fnames = fields (); + { + Octave_map obj_map = obj.map_value (); + string_vector obj_fnames = obj_map.keys (); + string_vector fnames = fields (); - for (octave_idx_type i = 0; i < nfields (); i++) - { - if (obj_fnames[i] != fnames[i]) - { - retval = false; - error ("mismatch in field names"); - break; - } - } + for (octave_idx_type i = 0; i < nfields (); i++) + { + if (obj_fnames[i] != fnames[i]) + { + retval = false; + error ("mismatch in field names"); + break; + } + } - if (nparents () == obj.nparents ()) - { - std::list<std::string> obj_parents - = obj.parent_class_name_list (); - std::list<std::string> pnames = parents (); + if (nparents () == obj.nparents ()) + { + std::list<std::string> obj_parents + = obj.parent_class_name_list (); + std::list<std::string> pnames = parents (); - std::list<std::string>::const_iterator p = obj_parents.begin (); - std::list<std::string>::const_iterator q = pnames.begin (); + std::list<std::string>::const_iterator p = obj_parents.begin (); + std::list<std::string>::const_iterator q = pnames.begin (); - while (p != obj_parents.end ()) - { - if (*p++ != *q++) - { - retval = false; - error ("mismatch in parent classes"); - break; - } - } - } - else - { - retval = false; - error ("mismatch in number of parent classes"); - } - } + while (p != obj_parents.end ()) + { + if (*p++ != *q++) + { + retval = false; + error ("mismatch in parent classes"); + break; + } + } + } + else + { + retval = false; + error ("mismatch in number of parent classes"); + } + } else - { - retval = false; - error ("mismatch in number of fields"); - } + { + retval = false; + error ("mismatch in number of fields"); + } } else { @@ -1733,33 +1733,33 @@ if (! error_state) { - if (nargin == 2) - retval = octave_value (new octave_class (m, id)); - else - { - octave_value_list parents = args.slice (2, nargin-2); + if (nargin == 2) + retval = octave_value (new octave_class (m, id)); + else + { + octave_value_list parents = args.slice (2, nargin-2); - retval = octave_value (new octave_class (m, id, parents)); - } + retval = octave_value (new octave_class (m, id, parents)); + } - if (! error_state) - { - octave_class::exemplar_const_iterator it - = octave_class::exemplar_map.find (id); + if (! error_state) + { + octave_class::exemplar_const_iterator it + = octave_class::exemplar_map.find (id); - if (it == octave_class::exemplar_map.end ()) - octave_class::exemplar_map[id] - = octave_class::exemplar_info (retval); - else if (! it->second.compare (retval)) - error ("class: object of class `%s' does not match previously constructed objects", id.c_str ()); - } + if (it == octave_class::exemplar_map.end ()) + octave_class::exemplar_map[id] + = octave_class::exemplar_info (retval); + else if (! it->second.compare (retval)) + error ("class: object of class `%s' does not match previously constructed objects", id.c_str ()); + } } - else + else error ("class: expecting character string as second argument"); - } - else + } + else error ("class: expecting structure as first argument"); - } + } else error ("class: invalid call from outside class constructor"); } @@ -1781,12 +1781,12 @@ octave_value nm = args(1); if (! error_state) - { - if (cls.find_parent_class (nm.string_value ())) - retval = true; - } + { + if (cls.find_parent_class (nm.string_value ())) + retval = true; + } else - error ("__isa_parent__: expecting arguments to be character strings"); + error ("__isa_parent__: expecting arguments to be character strings"); } else print_usage (); @@ -1807,7 +1807,7 @@ octave_value arg = args(0); if (arg.is_object ()) - retval = Cell (arg.parent_class_names ()); + retval = Cell (arg.parent_class_names ()); } else print_usage (); @@ -1847,24 +1847,24 @@ std::string class_name; if (arg.is_object ()) - class_name = arg.class_name (); + class_name = arg.class_name (); else if (arg.is_string ()) - class_name = arg.string_value (); + class_name = arg.string_value (); else - error ("ismethod: expecting object or class name as first argument"); + error ("ismethod: expecting object or class name as first argument"); if (! error_state) - { - std::string method = args(1).string_value (); + { + std::string method = args(1).string_value (); - if (! error_state) - { - if (load_path::find_method (class_name, method) != std::string ()) - retval = true; - else - retval = false; - } - } + if (! error_state) + { + if (load_path::find_method (class_name, method) != std::string ()) + retval = true; + else + retval = false; + } + } } else print_usage (); @@ -1889,27 +1889,27 @@ std::string class_name; if (arg.is_object ()) - class_name = arg.class_name (); + class_name = arg.class_name (); else if (arg.is_string ()) - class_name = arg.string_value (); + class_name = arg.string_value (); else - error ("methods: expecting object or class name as argument"); + error ("methods: expecting object or class name as argument"); if (! error_state) - { - string_vector sv = load_path::methods (class_name); + { + string_vector sv = load_path::methods (class_name); - if (nargout == 0) - { - octave_stdout << "Methods for class " << class_name << ":\n\n"; + if (nargout == 0) + { + octave_stdout << "Methods for class " << class_name << ":\n\n"; - sv.list_in_columns (octave_stdout); + sv.list_in_columns (octave_stdout); - octave_stdout << std::endl; - } - else - retval = Cell (sv); - } + octave_stdout << std::endl; + } + else + retval = Cell (sv); + } } else print_usage (); @@ -1960,35 +1960,35 @@ if (fcn && fcn->is_class_constructor ()) { for (int i = 0; i < args.length(); i++) - { - std::string class_name = args(i).string_value (); + { + std::string class_name = args(i).string_value (); - if (! error_state) - { - if (! is_built_in_class (class_name)) - { - std::string this_class_name = fcn->name (); + if (! error_state) + { + if (! is_built_in_class (class_name)) + { + std::string this_class_name = fcn->name (); - if (! symbol_table::set_class_relationship (this_class_name, - class_name)) - { - error ("superiorto: precedence already set for %s and %s", - this_class_name.c_str (), class_name.c_str ()); - break; - } - } - else - { - // User defined classes always have higher precedence - // than built-in classes. - } - } - else - { - error ("superiorto: expecting argument to be class name"); - break; - } - } + if (! symbol_table::set_class_relationship (this_class_name, + class_name)) + { + error ("superiorto: precedence already set for %s and %s", + this_class_name.c_str (), class_name.c_str ()); + break; + } + } + else + { + // User defined classes always have higher precedence + // than built-in classes. + } + } + else + { + error ("superiorto: expecting argument to be class name"); + break; + } + } } else error ("superiorto: invalid call from outside class constructor"); @@ -2012,38 +2012,38 @@ if (fcn && fcn->is_class_constructor ()) { for (int i = 0; i < args.length(); i++) - { - std::string class_name = args(i).string_value (); + { + std::string class_name = args(i).string_value (); - if (! error_state) - { - if (! is_built_in_class (class_name)) - { - std::string this_class_name = fcn->name (); + if (! error_state) + { + if (! is_built_in_class (class_name)) + { + std::string this_class_name = fcn->name (); - symbol_table::set_class_relationship (class_name, - this_class_name); + symbol_table::set_class_relationship (class_name, + this_class_name); - if (! symbol_table::set_class_relationship (this_class_name, - class_name)) - { - error ("inferiorto: precedence already set for %s and %s", - this_class_name.c_str (), class_name.c_str ()); - break; - } - } - else - { - error ("inferiorto: cannot give user-defined class lower precedence than built-in class"); - break; - } - } - else - { - error ("inferiorto: expecting argument to be class name"); - break; - } - } + if (! symbol_table::set_class_relationship (this_class_name, + class_name)) + { + error ("inferiorto: precedence already set for %s and %s", + this_class_name.c_str (), class_name.c_str ()); + break; + } + } + else + { + error ("inferiorto: cannot give user-defined class lower precedence than built-in class"); + break; + } + } + else + { + error ("inferiorto: expecting argument to be class name"); + break; + } + } } else error ("inferiorto: invalid call from outside class constructor");