# HG changeset patch # User jwe # Date 1020455762 0 # Node ID e8627dc4bdf2685f870c3abb06dfc41c23ed1168 # Parent e7ad1397d67b5977b248888a8272f04bdd4a95f4 [project @ 2002-05-03 19:56:01 by jwe] diff --git a/doc/interpreter/preface.txi b/doc/interpreter/preface.txi --- a/doc/interpreter/preface.txi +++ b/doc/interpreter/preface.txi @@ -117,6 +117,10 @@ new ideas for improving Octave. @item +Cai Jianming @email{caijianming@@yahoo.co.uk} contributed the inital +cell array implementation. + +@item Phil Johnson @email{johnsonp@@nicco.sscnet.ucla.edu} has helped to make Linux releases available. diff --git a/liboctave/Array.h b/liboctave/Array.h --- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -248,6 +248,8 @@ Array index (idx_vector& i) const; #endif + + static T resize_fill_value (void) { return static_cast (0); } }; template @@ -258,7 +260,7 @@ int assign (Array& lhs, const Array& rhs) { - return assign (lhs, rhs, static_cast (0)); + return assign (lhs, rhs, Array::resize_fill_value ()); } #endif diff --git a/liboctave/Array2.h b/liboctave/Array2.h --- a/liboctave/Array2.h +++ b/liboctave/Array2.h @@ -194,7 +194,7 @@ int assign (Array2& lhs, const Array2& rhs) { - return assign (lhs, rhs, static_cast (0)); + return assign (lhs, rhs, Array::resize_fill_value ()); } #endif diff --git a/liboctave/Array3.h b/liboctave/Array3.h --- a/liboctave/Array3.h +++ b/liboctave/Array3.h @@ -113,7 +113,7 @@ { if (i < 0 || j < 0 || k < 0 || i >= d1 || j >= d2 || k >= d3) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in Array3"); static T foo; return foo; } @@ -132,7 +132,7 @@ { if (i < 0 || j < 0 || k < 0 || i >= d1 || j >= d2 || k >= d3) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in Array3"); return T (); } return Array2::elem (i, d1*k+j); diff --git a/liboctave/ArrayN.cc b/liboctave/ArrayN.cc --- a/liboctave/ArrayN.cc +++ b/liboctave/ArrayN.cc @@ -137,7 +137,7 @@ { // XXX FIXME XXX -- report index values too! - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in ArrayN"); return T (); } @@ -148,7 +148,7 @@ { // XXX FIXME XXX -- report index values too! - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in ArrayN"); static T foo; return foo; diff --git a/liboctave/ArrayN.h b/liboctave/ArrayN.h --- a/liboctave/ArrayN.h +++ b/liboctave/ArrayN.h @@ -193,7 +193,7 @@ int assign (ArrayN& lhs, const ArrayN& rhs) { - return assign (lhs, rhs, static_cast (0)); + return assign (lhs, rhs, Array::resize_fill_value ()); } template diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,21 @@ +2002-05-03 John W. Eaton + + * idx-vector.h (idx_vector::idx_vector (int)): New function. + (idx_vector_rep::idx_vector_rep (int)): New decl. + * idx-vector.cc (idx_vector_rep::idx_vector_rep (int)): New function. + + * Array.h (Array::resize_fill_value (void)): New static function. + (assign (Array&, const Array&)): Use it. + * Array2.h (assign (Array2&, const Array2&)): Use it. + * ArrayN.h (assign (ArrayN&, const ArrayN&)): Use it. + +2002-05-02 Cai Jianming + + * Array3.h (Array3::checkelem): Improve error message. + * ArrayN.h (ArrayN::range_error): Likewise. + * DiagArray2.cc (DiagArray2::checkelem): Likewise. + * DiagArray2.cc (DiagArray2::operator ()): Likewise. + 2002-04-30 John W. Eaton * DASSL.h (DASSL_options::init): Undo previous change. diff --git a/liboctave/DiagArray2.cc b/liboctave/DiagArray2.cc --- a/liboctave/DiagArray2.cc +++ b/liboctave/DiagArray2.cc @@ -55,7 +55,7 @@ static T foo (0); if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return foo; } return (r == c) ? Array::xelem (r) : foo; @@ -68,7 +68,7 @@ static T foo (0); if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return foo; } return (r == c) ? Array::xelem (r) : foo; @@ -88,7 +88,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return T (); } return (r == c) ? Array::xelem (r) : T (0); @@ -100,7 +100,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return T (); } return (r == c) ? Array::xelem (r) : T (0); diff --git a/liboctave/DiagArray2.h b/liboctave/DiagArray2.h --- a/liboctave/DiagArray2.h +++ b/liboctave/DiagArray2.h @@ -201,7 +201,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); } else @@ -212,7 +212,7 @@ { if (r < 0 || c < 0 || r >= nr || c >= nc) { - (*current_liboctave_error_handler) ("range error"); + (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); } else diff --git a/liboctave/idx-vector.cc b/liboctave/idx-vector.cc --- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -75,7 +75,15 @@ static inline int tree_to_mat_idx (double x) { - return (x > 0) ? ((int) (x + 0.5) - 1) : ((int) (x - 0.5) - 1); + return (x > 0) + ? (static_cast (x + 0.5) - 1) + : (static_cast (x - 0.5) - 1); +} + +static inline int +tree_to_mat_idx (int i) +{ + return i - 1; } static inline bool @@ -183,33 +191,6 @@ init_state (); } -IDX_VEC_REP::idx_vector_rep (double d) -{ - data = 0; - initialized = 0; - frozen = 0; - colon_equiv_checked = 0; - colon_equiv = 0; - colon = 0; - one_zero = 0; - - len = 1; - - orig_nr = 1; - orig_nc = 1; - - if (idx_is_inf_or_nan (d)) - return; - else - { - data = new int [len]; - - data[0] = tree_to_mat_idx (d); - } - - init_state (); -} - IDX_VEC_REP::idx_vector_rep (const Range& r) { data = 0; @@ -258,6 +239,55 @@ init_state (); } +IDX_VEC_REP::idx_vector_rep (double d) +{ + data = 0; + initialized = 0; + frozen = 0; + colon_equiv_checked = 0; + colon_equiv = 0; + colon = 0; + one_zero = 0; + + len = 1; + + orig_nr = 1; + orig_nc = 1; + + if (idx_is_inf_or_nan (d)) + return; + else + { + data = new int [len]; + + data[0] = tree_to_mat_idx (d); + } + + init_state (); +} + +IDX_VEC_REP::idx_vector_rep (int i) +{ + data = 0; + initialized = 0; + frozen = 0; + colon_equiv_checked = 0; + colon_equiv = 0; + colon = 0; + one_zero = 0; + + len = 1; + + orig_nr = 1; + orig_nc = 1; + + data = new int [len]; + + data[0] = tree_to_mat_idx (i); + + init_state (); +} + IDX_VEC_REP::idx_vector_rep (char c) { assert (c == ':'); diff --git a/liboctave/idx-vector.h b/liboctave/idx-vector.h --- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -68,6 +68,8 @@ idx_vector_rep (double d); + idx_vector_rep (int i); + idx_vector_rep (char c); idx_vector_rep (bool b); @@ -170,6 +172,12 @@ rep->count = 1; } + idx_vector (int i) + { + rep = new idx_vector_rep (i); + rep->count = 1; + } + idx_vector (char c) { rep = new idx_vector_rep (c); diff --git a/src/Cell.cc b/src/Cell.cc --- a/src/Cell.cc +++ b/src/Cell.cc @@ -30,20 +30,6 @@ #include "Cell.h" -octave_allocator -Cell::allocator (sizeof (Cell)); - -Cell -Cell::index (idx_vector& i) const -{ - return Cell (data.index (i)); -} - -Cell -Cell::index (idx_vector& i, idx_vector& j) const -{ - return Cell (data.index (i, j)); -} /* ;;; Local Variables: *** diff --git a/src/Cell.h b/src/Cell.h --- a/src/Cell.h +++ b/src/Cell.h @@ -36,57 +36,28 @@ #include "ov.h" class -Cell +Cell : public Array2 { public: Cell (void) - : data () { } + : Array2 () { } + + Cell (const octave_value& val) + : Array2 (1, 1, val) { } Cell (int n, int m, const octave_value& val = octave_value ()) - : data (n, m, val) { } + : Array2 (n, m, val) { } Cell (const Array2& c) - : data (c) { } + : Array2 (c) { } Cell (const Cell& c) - : data (c.data) { } - - void *operator new (size_t size) - { return allocator.alloc (size); } - - void operator delete (void *p, size_t size) - { allocator.free (p, size); } - - Cell& operator = (const Cell& c) - { - if (this != &c) - data = c.data; - - return *this; - } - - int rows (void) const { return data.rows (); } + : Array2 (c) { } - int columns (void) const { return data.columns (); } - - octave_value& operator () (int i, int j) { return elem (i, j); } - - octave_value operator () (int i, int j) const { return elem (i, j); } - - octave_value& elem (int i, int j) { return data.elem (i, j); } - - octave_value elem (int i, int j) const { return data.elem (i, j); } - - Cell index (idx_vector& i) const; - - Cell index (idx_vector& i, idx_vector& j) const; - -private: - - static octave_allocator allocator; - - Array2 data; + boolMatrix all(void) const { return boolMatrix();} //FIXME + boolMatrix any(void) const {return boolMatrix();} //FIXME + bool is_true(void) const {return false;} //FIXME }; #endif diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,56 @@ +2002-05-03 John W. Eaton + + * ov-base.cc (cell_conv): New conversion function. + (install_base_type_conversions): Install it. + Install conversion for indexed assignment of octave_cells to + undefined values. + + * TEMPLATE-INST/Array-tc.cc: Instantiate assign functions too. + (Array::resize_fill_value (void)): + Provide specialization for octave_value. + + * ov-cell.cc (octave_cell::assign (const octave_value_list&, + const octave_value&)): New function. + * Cell.h (Cell::Cell (const octave_value&)): New function. + + * OPERATORS/op-cell.cc (install_list_ops): Use DEFASSIGNANYOP_FN + and INSTALL_ASSIGNANYOP, not DEFASSIGNOP_FN and INSTALL_ASSIGNOP. + +2002-05-03 Cai Jianming + + * OPERATORS/op-cell.cc: New file. + * src/Makefile.in (OP_XSRC): Include it in the list. + + * parse.y (cell): Return a cell type instead of Matrix type. + + * ov.cc (install_types): Install octave_cell type. + + * pr-output.cc (octave_print_internal): Handle Cells. + * pr-output.h (octave_print_internal): Provide decl. + + * ov-cell.h (octave_cell): Derive from octave_base_matrix. + * ov-cell.cc (do_index_op, assign, print, print_raw, + print_name_tag): Delete. + + * Cell.cc (allocator, index): Delete. + * Cell.h (Cell): Derive from Array2. + Most functions removed since we can use those from Array2 instead. + +2002-05-02 Cai Jianming + + * ov-base-mat.cc (octave_base_matrix::assign): + New function. + * ov-base-mat.h (octave_base_matrix::assign): Provide decl. + * ov-bool-mat.cc (octave_bool_matrix::assign): Delete. + * ov-bool-mat.h (octave_bool_matrix:assign): Delete decl + * ov-cx-mat.cc (octave_complex_matrix::assign (const + octave_value_list& idx, const ComplexMatrix&)): Delete. + * ov-cx-mat.h (octave_complex_matrix:assign (const + octave_value_list& idx, const ComplexMatrix&)): Replace decl with + function. + * ov-re-mat.cc (octave_bool_matrix::assign): Delete. + * ov-re-mat.h (octave_bool_matrix:assign): Delete decl. + 2002-05-02 Cai Jianming * OPERATORS/op-bm-b.cc: New file.x diff --git a/src/Makefile.in b/src/Makefile.in --- a/src/Makefile.in +++ b/src/Makefile.in @@ -96,9 +96,10 @@ TI_SRC := $(addprefix TEMPLATE-INST/, $(TI_XSRC)) -OP_XSRC := op-b-b.cc op-bm-b.cc op-bm-bm.cc op-chm.cc op-cm-cm.cc \ - op-cm-cs.cc op-cm-m.cc op-cm-s.cc op-cs-cm.cc op-cs-cs.cc \ - op-cs-m.cc op-cs-s.cc op-fil-b.cc op-fil-bm.cc op-fil-cm.cc \ +OP_XSRC := op-b-b.cc op-bm-b.cc op-bm-bm.cc op-cell.cc \ + op-chm.cc op-cm-cm.cc op-cm-cs.cc op-cm-m.cc \ + op-cm-s.cc op-cs-cm.cc op-cs-cs.cc op-cs-m.cc \ + op-cs-s.cc op-fil-b.cc op-fil-bm.cc op-fil-cm.cc \ op-fil-cs.cc op-fil-m.cc op-fil-s.cc op-fil-lis.cc \ op-fil-rec.cc op-fil-str.cc op-list.cc op-m-cm.cc op-m-cs.cc \ op-m-m.cc op-m-s.cc op-range.cc op-s-cm.cc op-s-cs.cc op-s-m.cc \ diff --git a/src/TEMPLATE-INST/Array-tc.cc b/src/TEMPLATE-INST/Array-tc.cc --- a/src/TEMPLATE-INST/Array-tc.cc +++ b/src/TEMPLATE-INST/Array-tc.cc @@ -38,8 +38,27 @@ #include "ov.h" template class Array; + +octave_value +Array::resize_fill_value (void) +{ + static octave_value retval = octave_value (Matrix ()); + return retval; +} + +template int assign (Array&, const Array&); + +template int assign (Array&, + const Array&, const octave_value&); + + template class Array2; +template int assign (Array2&, const Array2&); + +template int assign (Array2&, + const Array2&, const octave_value&); + /* ;;; Local Variables: *** ;;; mode: C++ *** diff --git a/src/ov-base-mat.cc b/src/ov-base-mat.cc --- a/src/ov-base-mat.cc +++ b/src/ov-base-mat.cc @@ -75,6 +75,48 @@ return retval; } +#if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) +template +extern void assign (MT&, const MT&); +#endif + +template +void +octave_base_matrix::assign (const octave_value_list& idx, const MT& rhs) +{ + int len = idx.length (); + + switch (len) + { + case 2: + { + idx_vector i = idx (0).index_vector (); + idx_vector j = idx (1).index_vector (); + + matrix.set_index (i); + matrix.set_index (j); + + ::assign (matrix, rhs); + } + break; + + case 1: + { + idx_vector i = idx (0).index_vector (); + + matrix.set_index (i); + + ::assign (matrix, rhs); + } + break; + + default: + error ("invalid number of indices (%d) for indexed assignment", + len); + break; + } +} + template bool octave_base_matrix::is_true (void) const diff --git a/src/ov-base-mat.h b/src/ov-base-mat.h --- a/src/ov-base-mat.h +++ b/src/ov-base-mat.h @@ -67,6 +67,8 @@ octave_value do_index_op (const octave_value_list& idx); + void assign (const octave_value_list& idx, const MT& rhs); + int rows (void) const { return matrix.rows (); } int columns (void) const { return matrix.columns (); } diff --git a/src/ov-base.cc b/src/ov-base.cc --- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -32,7 +32,6 @@ #include "lo-ieee.h" -#include "Cell.h" #include "gripes.h" #include "oct-map.h" #include "oct-obj.h" @@ -40,14 +39,15 @@ #include "oct-stream.h" #include "ops.h" #include "ov-base.h" -#include "ov-scalar.h" -#include "ov-re-mat.h" +#include "ov-cell.h" +#include "ov-ch-mat.h" #include "ov-complex.h" #include "ov-cx-mat.h" -#include "ov-ch-mat.h" +#include "ov-list.h" +#include "ov-range.h" +#include "ov-re-mat.h" +#include "ov-scalar.h" #include "ov-str-mat.h" -#include "ov-range.h" -#include "ov-list.h" #include "variables.h" DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, ""); @@ -338,6 +338,11 @@ return new octave_char_matrix_str (); } +CONVDECLX (cell_conv) +{ + return new octave_cell (); +} + void install_base_type_conversions (void) { @@ -347,10 +352,12 @@ INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); + INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); + INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); } /* diff --git a/src/ov-bool-mat.cc b/src/ov-bool-mat.cc --- a/src/ov-bool-mat.cc +++ b/src/ov-bool-mat.cc @@ -78,43 +78,6 @@ return retval; } -void -octave_bool_matrix::assign (const octave_value_list& idx, - const boolMatrix& rhs) -{ - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - matrix.set_index (i); - matrix.set_index (j); - - ::assign (matrix, rhs); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - matrix.set_index (i); - - ::assign (matrix, rhs); - } - break; - - default: - error ("invalid number of indices (%d) for indexed matrix assignment", - len); - break; - } -} - bool octave_bool_matrix::valid_as_scalar_index (void) const { diff --git a/src/ov-bool-mat.h b/src/ov-bool-mat.h --- a/src/ov-bool-mat.h +++ b/src/ov-bool-mat.h @@ -72,8 +72,6 @@ octave_value *try_narrowing_conversion (void); - void assign (const octave_value_list& idx, const boolMatrix& rhs); - idx_vector index_vector (void) const { return idx_vector (matrix); } bool is_bool_matrix (void) const { return true; } diff --git a/src/ov-cell.cc b/src/ov-cell.cc --- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -39,139 +39,24 @@ #include "oct-obj.h" #include "unwind-prot.h" #include "utils.h" +#include "ov-base-mat.h" +#include "ov-base-mat.cc" +#include "ov-re-mat.h" +#include "ov-scalar.h" + +template class octave_base_matrix; DEFINE_OCTAVE_ALLOCATOR (octave_cell); DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell"); -octave_value -octave_cell::do_index_op (const octave_value_list& idx) -{ - octave_value retval; - - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - retval = cell_val.index (i, j); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - retval = cell_val.index (i); - } - break; - - default: - { - std::string n = type_name (); - - error ("invalid number of indices (%d) for %s value", - len, n.c_str ()); - } - break; - } - - return retval; -} - void octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) { -#if 0 - if (idx.length () == 1) - { - int i = idx(0).int_value (true); - - if (! error_state) - { - int n = lst.length (); - - if (i > 0 && (Vresize_on_range_error || i <= n)) - lst(i-1) = rhs; - else - error ("list index = %d out of range", i); - } - else - error ("list index must be an integer"); - } + if (rhs.is_cell ()) + octave_base_matrix::assign (idx, rhs.cell_value ()); else - error ("lists may only be indexed by a single scalar"); -#endif -} - -void -octave_cell::print (std::ostream& os, bool) const -{ - print_raw (os); -} - -void -octave_cell::print_raw (std::ostream& os, bool) const -{ - unwind_protect::begin_frame ("octave_cell_print"); - - int nr = cell_val.rows (); - int nc = cell_val.columns(); - - if (nr > 0 && nc > 0) - { - indent (os); - os << "{"; - newline (os); - - increment_indent_level (); - - for (int j = 0; j < nc; j++) - { - for (int i = 0; i < nr; i++) - { - std::ostrstream buf; - buf << "[" << i+1 << "," << j+1 << "]" << std::ends; - const char *nm = buf.str (); - - octave_value val = cell_val(i,j); - - val.print_with_name (os, nm); - - delete [] nm; - } - } - - decrement_indent_level (); - - indent (os); - - os << "}"; - } - else - os << "{}"; - - newline (os); - - unwind_protect::run_frame ("octave_cell_print"); -} - -bool -octave_cell::print_name_tag (std::ostream& os, const std::string& name) const -{ - indent (os); - if (is_empty ()) - os << name << " = "; - else - { - os << name << " ="; - newline (os); - } - return false; + octave_base_matrix::assign (idx, Cell (rhs)); } DEFUN (iscell, args, , diff --git a/src/ov-cell.h b/src/ov-cell.h --- a/src/ov-cell.h +++ b/src/ov-cell.h @@ -38,7 +38,7 @@ #include "Cell.h" #include "error.h" -#include "ov-base.h" +#include "ov-base-mat.h" #include "ov-typeinfo.h" class Octave_map; @@ -49,45 +49,36 @@ // Cells. class -octave_cell : public octave_base_value +octave_cell : public octave_base_matrix { public: octave_cell (void) - : octave_base_value () { } + : octave_base_matrix () { } octave_cell (const Cell& c) - : octave_base_value (), cell_val (c) { } + : octave_base_matrix (c) { } octave_cell (const octave_cell& c) - : octave_base_value (), cell_val (c.cell_val) { } + : octave_base_matrix (c) { } ~octave_cell (void) { } - octave_value *clone (void) { return new octave_cell (*this); } - - octave_value do_index_op (const octave_value_list& idx); - void assign (const octave_value_list& idx, const octave_value& rhs); - bool is_defined (void) const { return true; } + octave_value *clone (void) { return new octave_cell (*this); } - bool is_constant (void) const { return true; } +#if 0 + octave_value *try_narrowing_conversion (void); +#endif + + bool is_defined (void) const { return true; } bool is_cell (void) const { return true; } - Cell cell_value (void) const { return cell_val; } - - void print (std::ostream& os, bool pr_as_read_syntax = false) const; - - void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; - - bool print_name_tag (std::ostream& os, const std::string& name) const; + Cell cell_value (void) const { return matrix; } private: - - Cell cell_val; - DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA diff --git a/src/ov-cx-mat.cc b/src/ov-cx-mat.cc --- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -78,43 +78,6 @@ void octave_complex_matrix::assign (const octave_value_list& idx, - const ComplexMatrix& rhs) -{ - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - matrix.set_index (i); - matrix.set_index (j); - - ::assign (matrix, rhs); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - matrix.set_index (i); - - ::assign (matrix, rhs); - } - break; - - default: - error ("invalid number of indices (%d) for indexed matrix assignment", - len); - break; - } -} - -void -octave_complex_matrix::assign (const octave_value_list& idx, const Matrix& rhs) { int len = idx.length (); diff --git a/src/ov-cx-mat.h b/src/ov-cx-mat.h --- a/src/ov-cx-mat.h +++ b/src/ov-cx-mat.h @@ -77,7 +77,8 @@ octave_value *try_narrowing_conversion (void); - void assign (const octave_value_list& idx, const ComplexMatrix& rhs); + void assign (const octave_value_list& idx, const ComplexMatrix& rhs) + { octave_base_matrix::assign (idx, rhs); } void assign (const octave_value_list& idx, const Matrix& rhs); diff --git a/src/ov-re-mat.cc b/src/ov-re-mat.cc --- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -66,42 +66,6 @@ return retval; } -void -octave_matrix::assign (const octave_value_list& idx, const Matrix& rhs) -{ - int len = idx.length (); - - switch (len) - { - case 2: - { - idx_vector i = idx (0).index_vector (); - idx_vector j = idx (1).index_vector (); - - matrix.set_index (i); - matrix.set_index (j); - - ::assign (matrix, rhs); - } - break; - - case 1: - { - idx_vector i = idx (0).index_vector (); - - matrix.set_index (i); - - ::assign (matrix, rhs); - } - break; - - default: - error ("invalid number of indices (%d) for indexed matrix assignment", - len); - break; - } -} - bool octave_matrix::valid_as_scalar_index (void) const { diff --git a/src/ov-re-mat.h b/src/ov-re-mat.h --- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -77,8 +77,6 @@ octave_value *try_narrowing_conversion (void); - void assign (const octave_value_list& idx, const Matrix& rhs); - idx_vector index_vector (void) const { return idx_vector (matrix); } bool is_real_matrix (void) const { return true; } diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -1525,6 +1525,7 @@ install_types (void) { octave_base_value::register_type (); + octave_cell::register_type (); octave_scalar::register_type (); octave_complex::register_type (); octave_matrix::register_type (); diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -40,6 +40,7 @@ #include +#include "Cell.h" #include "Matrix.h" #include "cmd-edit.h" #include "cmd-hist.h" @@ -606,9 +607,9 @@ ; cell : '{' '}' - { $$ = new tree_constant (octave_value (Matrix ())); } + { $$ = new tree_constant (octave_value (Cell ())); } | '{' ';' '}' - { $$ = new tree_constant (octave_value (Matrix ())); } + { $$ = new tree_constant (octave_value (Cell ())); } | '{' cell_rows '}' { $$ = finish_cell ($2); } ; diff --git a/src/pr-output.cc b/src/pr-output.cc --- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -38,6 +38,7 @@ #include "Range.h" #include "cmd-edit.h" #include "dMatrix.h" +#include "Cell.h" #include "lo-mappers.h" #include "mach-info.h" #include "oct-cmplx.h" @@ -1754,6 +1755,39 @@ } } +void +octave_print_internal (std::ostream& os, const Cell& cell_val, + bool pr_as_read_syntax, int extra_indent) +{ + int nr = cell_val.rows (); + int nc = cell_val.columns(); + + if (nr > 0 && nc > 0) + { + os << "{\n"; + + for (int j = 0; j < nc; j++) + { + for (int i = 0; i < nr; i++) + { + std::ostrstream buf; + buf << "[" << i+1 << "," << j+1 << "]" << std::ends; + const char *nm = buf.str (); + + octave_value val = cell_val(i,j); + + val.print_with_name (os, nm); + + delete [] nm; + } + } + + os << "}"; + } + else + os << "{}"; +} + DEFUN (disp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} disp (@var{x})\n\ diff --git a/src/pr-output.h b/src/pr-output.h --- a/src/pr-output.h +++ b/src/pr-output.h @@ -32,6 +32,7 @@ class Range; class boolMatrix; class charMatrix; +class Cell; extern void octave_print_internal (std::ostream& os, double d, @@ -67,6 +68,11 @@ int extra_indent = 0, bool pr_as_string = false); +extern void +octave_print_internal (std::ostream& os, const Cell& c, + bool pr_as_read_syntax = false, + int extra_indent = 0); + #endif /*