Mercurial > hg > octave-lyh
changeset 3353:6b36317855ff
[project @ 1999-11-16 16:13:49 by jwe]
author | jwe |
---|---|
date | Tue, 16 Nov 1999 16:13:51 +0000 |
parents | 0ddc382c245c |
children | 87721841efd7 |
files | src/Cell.cc src/Cell.h src/ov-cell.cc src/ov-cell.h src/pt-cell.cc src/pt-cell.h |
diffstat | 6 files changed, 562 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/src/Cell.cc @@ -0,0 +1,40 @@ +/* + +Copyright (C) 1999 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "Cell.h" + +octave_allocator +Cell::allocator (sizeof (Cell)); + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
new file mode 100644 --- /dev/null +++ b/src/Cell.h @@ -0,0 +1,91 @@ +/* + +Copyright (C) 1999 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (Cell_h) +#define Cell_h 1 + +#if defined (__GNUG__) +#pragma interface +#endif + +#include <string> + +#include "Array2.h" +#include "oct-alloc.h" +#include "str-vec.h" + +#include "ov.h" + +class +Cell +{ +public: + + Cell (void) + : data () { } + + Cell (int n, int m, const octave_value& val = octave_value ()) + : data (n, m, val) { } + + 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 (); } + + 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); } + +private: + + static octave_allocator allocator; + + Array2<octave_value> data; +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
new file mode 100644 --- /dev/null +++ b/src/ov-cell.cc @@ -0,0 +1,159 @@ +/* + +Copyright (C) 1999 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <iostream.h> +#include <strstream.h> + +#include "lo-utils.h" + +#include "defun.h" +#include "error.h" +#include "ov-cell.h" +#include "unwind-prot.h" + +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; + +#if 0 + if (idx.length () == 1) + { + idx_vector i = idx (0).index_vector (); + + retval = octave_value_list (lst.index (i)); + } + else + error ("lists may only be indexed by a single scalar"); +#endif + + 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"); + } + else + error ("lists may only be indexed by a single scalar"); +#endif +} + +void +octave_cell::print (ostream& os, bool) const +{ + print_raw (os); +} + +void +octave_cell::print_raw (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++) + { + ostrstream buf; + buf << "[" << i+1 << "," << j+1 << "]" << 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 (ostream& os, const string& name) const +{ + indent (os); + if (is_empty ()) + os << name << " = "; + else + { + os << name << " ="; + newline (os); + } + return false; +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
new file mode 100644 --- /dev/null +++ b/src/ov-cell.h @@ -0,0 +1,99 @@ +/* + +Copyright (C) 1999 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_cell_h) +#define octave_cell_h 1 + +#if defined (__GNUG__) +#pragma interface +#endif + +#include <cstdlib> + +#include <string> + +class ostream; + +#include "mx-base.h" +#include "oct-alloc.h" +#include "str-vec.h" + +#include "Cell.h" +#include "error.h" +#include "ov-base.h" +#include "ov-typeinfo.h" + +class Octave_map; +class octave_value_list; + +class tree_walker; + +// Cells. + +class +octave_cell : public octave_base_value +{ +public: + + octave_cell (void) + : octave_base_value () { } + + octave_cell (const Cell& c) + : octave_base_value (), cell_val (c) { } + + octave_cell (const octave_cell& c) + : octave_base_value (), cell_val (c.cell_val) { } + + ~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; } + + bool is_constant (void) const { return true; } + + void print (ostream& os, bool pr_as_read_syntax = false) const; + + void print_raw (ostream& os, bool pr_as_read_syntax = false) const; + + bool print_name_tag (ostream& os, const string& name) const; + +private: + + Cell cell_val; + + DECLARE_OCTAVE_ALLOCATOR + + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
new file mode 100644 --- /dev/null +++ b/src/pt-cell.cc @@ -0,0 +1,98 @@ +/* + +Copyright (C) 1999 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <iostream.h> +#include <strstream.h> + +#include "Cell.h" +#include "defun.h" +#include "error.h" +#include "oct-obj.h" +#include "pt-arg-list.h" +#include "pt-exp.h" +#include "pt-cell.h" +#include "pt-walk.h" +#include "utils.h" +#include "ov.h" +#include "variables.h" + +octave_value +tree_cell::rvalue (void) +{ + octave_value retval; + + int nr = length (); + int nc = -1; + + for (Pix p = first (); p != 0; next (p)) + { + tree_argument_list *elt = this->operator () (p); + + if (nc < 0) + nc = elt->length (); + else if (nc != elt->length ()) + { + ::error ("number of columns must match"); + return retval; + } + } + + Cell val (nr, nc); + + int i = 0; + + for (Pix p = first (); p != 0; next (p)) + { + tree_argument_list *elt = this->operator () (p); + + octave_value_list row = elt->convert_to_const_vector (); + + for (int j = 0; j < nc; j++) + val(i,j) = row(j); + + i++; + } + + retval = val; + + return retval; +} + +void +tree_cell::accept (tree_walker& tw) +{ + tw.visit_cell (*this); +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
new file mode 100644 --- /dev/null +++ b/src/pt-cell.h @@ -0,0 +1,75 @@ +/* + +Copyright (C) 1999 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_tree_cell_h) +#define octave_tree_cell_h 1 + +#if defined (__GNUG__) +#pragma interface +#endif + +class ostream; + +class octave_value; +class octave_value_list; +class tree_argument_list; + +class tree_walker; + +#include <SLList.h> + +#include "pt-mat.h" + +// General cells. + +class +tree_cell : public tree_matrix +{ +public: + + tree_cell (tree_argument_list *row = 0) : tree_matrix (row) { } + + ~tree_cell (void) { } + + bool rvalue_ok (void) const + { return true; } + + octave_value rvalue (void); + + void accept (tree_walker& tw); + +private: + + // No copying! + + tree_cell (const tree_cell&); + + tree_cell& operator = (const tree_cell&); +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/