Mercurial > hg > octave-nkf
changeset 3928:e8627dc4bdf2
[project @ 2002-05-03 19:56:01 by jwe]
author | jwe |
---|---|
date | Fri, 03 May 2002 19:56:02 +0000 |
parents | e7ad1397d67b |
children | cc8ae49d6e79 |
files | doc/interpreter/preface.txi liboctave/Array.h liboctave/Array2.h liboctave/Array3.h liboctave/ArrayN.cc liboctave/ArrayN.h liboctave/ChangeLog liboctave/DiagArray2.cc liboctave/DiagArray2.h liboctave/idx-vector.cc liboctave/idx-vector.h src/Cell.cc src/Cell.h src/ChangeLog src/Makefile.in src/TEMPLATE-INST/Array-tc.cc src/ov-base-mat.cc src/ov-base-mat.h src/ov-base.cc src/ov-bool-mat.cc src/ov-bool-mat.h src/ov-cell.cc src/ov-cell.h src/ov-cx-mat.cc src/ov-cx-mat.h src/ov-re-mat.cc src/ov-re-mat.h src/ov.cc src/parse.y src/pr-output.cc src/pr-output.h |
diffstat | 31 files changed, 314 insertions(+), 366 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -248,6 +248,8 @@ Array<T> index (idx_vector& i) const; #endif + + static T resize_fill_value (void) { return static_cast<T> (0); } }; template <class LT, class RT> @@ -258,7 +260,7 @@ int assign (Array<LT>& lhs, const Array<RT>& rhs) { - return assign (lhs, rhs, static_cast<LT> (0)); + return assign (lhs, rhs, Array<LT>::resize_fill_value ()); } #endif
--- a/liboctave/Array2.h +++ b/liboctave/Array2.h @@ -194,7 +194,7 @@ int assign (Array2<LT>& lhs, const Array2<RT>& rhs) { - return assign (lhs, rhs, static_cast<LT> (0)); + return assign (lhs, rhs, Array<LT>::resize_fill_value ()); } #endif
--- 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<T>::elem (i, d1*k+j);
--- 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;
--- a/liboctave/ArrayN.h +++ b/liboctave/ArrayN.h @@ -193,7 +193,7 @@ int assign (ArrayN<LT>& lhs, const ArrayN<RT>& rhs) { - return assign (lhs, rhs, static_cast<LT> (0)); + return assign (lhs, rhs, Array<LT>::resize_fill_value ()); } template <class T>
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,21 @@ +2002-05-03 John W. Eaton <jwe@bevo.che.wisc.edu> + + * 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<T>::resize_fill_value (void)): New static function. + (assign (Array<LT>&, const Array<RT>&)): Use it. + * Array2.h (assign (Array2<LT>&, const Array2<RT>&)): Use it. + * ArrayN.h (assign (ArrayN<LT>&, const ArrayN<RT>&)): Use it. + +2002-05-02 Cai Jianming <caijianming@yahoo.co.uk> + + * Array3.h (Array3<T>::checkelem): Improve error message. + * ArrayN.h (ArrayN<T>::range_error): Likewise. + * DiagArray2.cc (DiagArray2<T>::checkelem): Likewise. + * DiagArray2.cc (DiagArray2<T>::operator ()): Likewise. + 2002-04-30 John W. Eaton <jwe@bevo.che.wisc.edu> * DASSL.h (DASSL_options::init): Undo previous change.
--- 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<T>::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<T>::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<T>::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<T>::xelem (r) : T (0);
--- 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
--- 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<int> (x + 0.5) - 1) + : (static_cast<int> (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 == ':');
--- 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);
--- 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: ***
--- a/src/Cell.h +++ b/src/Cell.h @@ -36,57 +36,28 @@ #include "ov.h" class -Cell +Cell : public Array2<octave_value> { public: Cell (void) - : data () { } + : Array2<octave_value> () { } + + Cell (const octave_value& val) + : Array2<octave_value> (1, 1, val) { } Cell (int n, int m, const octave_value& val = octave_value ()) - : data (n, m, val) { } + : Array2<octave_value> (n, m, val) { } Cell (const Array2<octave_value>& c) - : data (c) { } + : Array2<octave_value> (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<octave_value> (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<octave_value> data; + boolMatrix all(void) const { return boolMatrix();} //FIXME + boolMatrix any(void) const {return boolMatrix();} //FIXME + bool is_true(void) const {return false;} //FIXME }; #endif
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,56 @@ +2002-05-03 John W. Eaton <jwe@bevo.che.wisc.edu> + + * 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<octave_value>::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 <caijianming@yahoo.co.uk> + + * 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<Cell>. + * 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<octave_value>. + Most functions removed since we can use those from Array2 instead. + +2002-05-02 Cai Jianming <caijianming@yahoo.co.uk> + + * ov-base-mat.cc (octave_base_matrix<MT>::assign): + New function. + * ov-base-mat.h (octave_base_matrix<MT>::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 <caijianming@yahoo.co.uk> * OPERATORS/op-bm-b.cc: New file.x
--- 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 \
--- 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>; + +octave_value +Array<octave_value>::resize_fill_value (void) +{ + static octave_value retval = octave_value (Matrix ()); + return retval; +} + +template int assign (Array<octave_value>&, const Array<octave_value>&); + +template int assign (Array<octave_value>&, + const Array<octave_value>&, const octave_value&); + + template class Array2<octave_value>; +template int assign (Array2<octave_value>&, const Array2<octave_value>&); + +template int assign (Array2<octave_value>&, + const Array2<octave_value>&, const octave_value&); + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- 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 <class MT> +extern void assign (MT&, const MT&); +#endif + +template <class MT> +void +octave_base_matrix<MT>::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 <class MT> bool octave_base_matrix<MT>::is_true (void) const
--- 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 (); }
--- 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, "<unknown type>"); @@ -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); } /*
--- 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 {
--- 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; }
--- 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<Cell>; 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<Cell>::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<Cell>::assign (idx, Cell (rhs)); } DEFUN (iscell, args, ,
--- 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<Cell> { public: octave_cell (void) - : octave_base_value () { } + : octave_base_matrix<Cell> () { } octave_cell (const Cell& c) - : octave_base_value (), cell_val (c) { } + : octave_base_matrix<Cell> (c) { } octave_cell (const octave_cell& c) - : octave_base_value (), cell_val (c.cell_val) { } + : octave_base_matrix<Cell> (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
--- 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 ();
--- 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<ComplexMatrix>::assign (idx, rhs); } void assign (const octave_value_list& idx, const Matrix& rhs);
--- 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 {
--- 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; }
--- 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 ();
--- a/src/parse.y +++ b/src/parse.y @@ -40,6 +40,7 @@ #include <strstream.h> +#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); } ;
--- 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\
--- 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 /*