Mercurial > hg > octave-nkf
changeset 4645:bd2067547b40
[project @ 2003-11-23 08:07:52 by jwe]
author | jwe |
---|---|
date | Sun, 23 Nov 2003 08:07:53 +0000 |
parents | 3b74f1a86750 |
children | eff8f977508c |
files | ChangeLog configure.in liboctave/Array2.h liboctave/Array3.h liboctave/ArrayN.h liboctave/ChangeLog liboctave/DiagArray2.cc liboctave/DiagArray2.h liboctave/MArrayN.cc liboctave/MDiagArray2.h src/ChangeLog src/OPERATORS/op-streamoff.cc src/oct-stream.cc src/ov-base.cc src/ov-base.h src/ov-builtin.h src/ov-cell.h src/ov-dld-fcn.h src/ov-fcn.h src/ov-mapper.h src/ov-re-mat.cc src/ov-re-mat.h src/ov-scalar.cc src/ov-scalar.h src/ov-streamoff.cc src/ov-streamoff.h src/ov-typeinfo.h src/ov-usr-fcn.cc src/ov-usr-fcn.h src/ov.cc src/ov.h |
diffstat | 31 files changed, 784 insertions(+), 149 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-11-20 John W. Eaton <jwe@bevo.che.wisc.edu> + + * configure.in: Also maybe add -W to WARN_CFLAGS and WARN_CXXFLAGS. + 2003-11-15 John W. Eaton <jwe@bevo.che.wisc.edu> * Makeconf.in (SHLLIB_VER): Fix typo.
--- a/configure.in +++ b/configure.in @@ -29,7 +29,7 @@ EXTERN_CXXFLAGS="$CXXFLAGS" AC_INIT -AC_REVISION($Revision: 1.440 $) +AC_REVISION($Revision: 1.441 $) AC_PREREQ(2.57) AC_CONFIG_SRCDIR([src/octave.cc]) AC_CONFIG_HEADER(config.h) @@ -1282,13 +1282,16 @@ AC_MSG_RESULT([defining UGLY_DEFS to be $UGLY_DEFS]) AC_SUBST(UGLY_DEFS) -### Maybe add -Wall and -Wshadow to compiler flags now that we're +### Maybe add -Wall, -W, and -Wshadow to compiler flags now that we're ### done feature testing. if test -z "$EXTERN_CFLAGS"; then OCTAVE_CC_FLAG(-Wall, [ WARN_CFLAGS="$WARN_CFLAGS -Wall"; AC_MSG_RESULT([adding -Wall to WARN_CFLAGS])]) + OCTAVE_CC_FLAG(-W, [ + WARN_CFLAGS="$WARN_CFLAGS -W"; + AC_MSG_RESULT([adding -W to WARN_CFLAGS])]) OCTAVE_CC_FLAG(-Wshadow, [ WARN_CFLAGS="$WARN_CFLAGS -Wshadow"; AC_MSG_RESULT([adding -Wshadow to WARN_CFLAGS])]) @@ -1298,6 +1301,9 @@ OCTAVE_CXX_FLAG(-Wall, [ WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"; AC_MSG_RESULT([adding -Wall to WARN_CXXFLAGS])]) + OCTAVE_CXX_FLAG(-W, [ + WARN_CXXFLAGS="$WARN_CXXFLAGS -W"; + AC_MSG_RESULT([adding -W to WARN_CXXFLAGS])]) OCTAVE_CXX_FLAG(-Wshadow, [ WARN_CXXFLAGS="$WARN_CXXFLAGS -Wshadow"; AC_MSG_RESULT([adding -Wshadow to WARN_CXXFLAGS])])
--- a/liboctave/Array2.h +++ b/liboctave/Array2.h @@ -69,18 +69,15 @@ Array2<T>& operator = (const Array2<T>& a) { if (this != &a) - { - Array<T>::operator = (a); - - dimensions = a.dimensions; - } + Array<T>::operator = (a); return *this; } - void resize (int r, int c) { resize_no_fill (r, c); } + void resize (int r, int c) { this->resize_no_fill (r, c); } - void resize (int r, int c, const T& val) { resize_and_fill (r, c, val); } + void resize (int r, int c, const T& val) + { this->resize_and_fill (r, c, val); } Array2<T>& insert (const Array2<T>& a, int r, int c) {
--- a/liboctave/Array3.h +++ b/liboctave/Array3.h @@ -69,19 +69,15 @@ Array3<T>& operator = (const Array3<T>& a) { if (this != &a) - { - Array<T>::operator = (a); - - dimensions = a.dimensions; - } + Array<T>::operator = (a); return *this; } - void resize (int r, int c, int p) { resize_no_fill (r, c, p); } + void resize (int r, int c, int p) { this->resize_no_fill (r, c, p); } void resize (int r, int c, int p, const T& val) - { resize_and_fill (r, c, p, val); } + { this->resize_and_fill (r, c, p, val); } }; #endif
--- a/liboctave/ArrayN.h +++ b/liboctave/ArrayN.h @@ -83,7 +83,7 @@ } void resize (const dim_vector& dv) - { Array<T>::resize_no_fill (dv); } + { this->resize_no_fill (dv); } void resize (const dim_vector& dv, const T& val) { Array<T>::resize (dv, val); }
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,19 @@ +2003-11-20 John W. Eaton <jwe@bevo.che.wisc.edu> + + * MArrayN.cc (operator -=, operator +=): Check dimensions, not + just length. + + * Array2.h, Array3.h, DiagArray2.h, DiagArray2.cc, MDiagArray2.h, + ArrayN.h: Add this-> or Base:: qualifiers for references to + non-dependent member functions and data as needed. + + * DiagArray2.h, DiagArray2.cc: Delete unused code. + + * Array2.h (Array2<T>::operator =): Don't copy dimensions here. + * Array3.h (Array3<T>::operator =): Likewise. + * DiagArray2.h (DiagArray2<T>::operator =): Likewise. + Include Array.h, not Array2.h. + 2003-11-19 John W. Eaton <jwe@bevo.che.wisc.edu> * str-vec.cc (list_in_columns): Fix previous change.
--- a/liboctave/DiagArray2.cc +++ b/liboctave/DiagArray2.cc @@ -39,42 +39,6 @@ // A two-dimensional array with diagonal elements only. -#if 0 -template <class T> -T& -DiagArray2<T>::elem (int r, int c) -{ - static T foo (0); - return (r == c) ? Array<T>::xelem (r) : foo; -} - -template <class T> -T& -DiagArray2<T>::checkelem (int r, int c) -{ - static T foo (0); - if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) - { - (*current_liboctave_error_handler) ("range error in DiagArray2"); - return foo; - } - return (r == c) ? Array<T>::xelem (r) : foo; -} - -template <class T> -T& -DiagArray2<T>::operator () (int r, int c) -{ - static T foo (0); - if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) - { - (*current_liboctave_error_handler) ("range error in DiagArray2"); - return foo; - } - return (r == c) ? Array<T>::xelem (r) : foo; -} -#endif - template <class T> T DiagArray2<T>::elem (int r, int c) const @@ -86,7 +50,7 @@ T DiagArray2<T>::checkelem (int r, int c) const { - if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) + if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) { (*current_liboctave_error_handler) ("range error in DiagArray2"); return T (); @@ -98,7 +62,7 @@ T DiagArray2<T>::operator () (int r, int c) const { - if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) + if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) { (*current_liboctave_error_handler) ("range error in DiagArray2"); return T (); @@ -131,18 +95,18 @@ return; } - if (r == dim1 () && c == dim2 ()) + if (r == this->dim1 () && c == this->dim2 ()) return; typename Array<T>::ArrayRep *old_rep = Array<T>::rep; - const T *old_data = data (); - int old_len = length (); + const T *old_data = this->data (); + int old_len = this->length (); int new_len = r < c ? r : c; Array<T>::rep = new typename Array<T>::ArrayRep (new_len); - dimensions = dim_vector (r, c); + this->dimensions = dim_vector (r, c); if (old_data && old_len > 0) { @@ -166,18 +130,18 @@ return; } - if (r == dim1 () && c == dim2 ()) + if (r == this->dim1 () && c == this->dim2 ()) return; typename Array<T>::ArrayRep *old_rep = Array<T>::rep; - const T *old_data = data (); - int old_len = length (); + const T *old_data = this->data (); + int old_len = this->length (); int new_len = r < c ? r : c; Array<T>::rep = new typename Array<T>::ArrayRep (new_len); - dimensions = dim_vector (r, c); + this->dimensions = dim_vector (r, c); int min_len = old_len < new_len ? old_len : new_len;
--- a/liboctave/DiagArray2.h +++ b/liboctave/DiagArray2.h @@ -31,7 +31,7 @@ #include <cassert> #include <cstdlib> -#include "Array2.h" +#include "Array.h" #include "lo-error.h" class idx_vector; @@ -111,59 +111,38 @@ protected: DiagArray2 (T *d, int r, int c) : Array<T> (d, r < c ? r : c) - { dimensions = dim_vector (r, c); } + { Array<T>::dimensions = dim_vector (r, c); } public: DiagArray2 (void) : Array<T> (dim_vector (0, 0)) { } DiagArray2 (int r, int c) : Array<T> (r < c ? r : c) - { dimensions = dim_vector (r, c); } + { this->dimensions = dim_vector (r, c); } DiagArray2 (int r, int c, const T& val) : Array<T> (r < c ? r : c) { - dimensions = dim_vector (r, c); + this->dimensions = dim_vector (r, c); fill (val); } DiagArray2 (const Array<T>& a) : Array<T> (a) - { dimensions = dim_vector (a.length (), a.length ()); } + { this->dimensions = dim_vector (a.length (), a.length ()); } DiagArray2 (const DiagArray2<T>& a) : Array<T> (a) - { dimensions = a.dims (); } + { this->dimensions = a.dims (); } ~DiagArray2 (void) { } DiagArray2<T>& operator = (const DiagArray2<T>& a) { if (this != &a) - { - Array<T>::operator = (a); - dimensions = a.dims (); - } + Array<T>::operator = (a); return *this; } -#if 0 - operator Array2<T> () const - { - int nr = dim1 (); - int nc = dim2 (); - - Array2<T> retval (nr, nc, T (0)); - - int len = nr < nc ? nr : nc; - - for (int i = 0; i < len; i++) - retval.xelem (i, i) = xelem (i, i); - - return retval; - } -#endif - -#if 1 Proxy elem (int r, int c) { return Proxy (this, r, c); @@ -171,7 +150,7 @@ Proxy checkelem (int r, int c) { - if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) + if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) { (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); @@ -182,7 +161,7 @@ Proxy operator () (int r, int c) { - if (r < 0 || c < 0 || r >= dim1 () || c >= dim2 ()) + if (r < 0 || c < 0 || r >= this->dim1 () || c >= this->dim2 ()) { (*current_liboctave_error_handler) ("range error in DiagArray2"); return Proxy (0, r, c); @@ -190,11 +169,6 @@ else return Proxy (this, r, c); } -#else - T& elem (int r, int c); - T& checkelem (int r, int c); - T& operator () (int r, int c); -#endif T elem (int r, int c) const; T checkelem (int r, int c) const;
--- a/liboctave/MArrayN.cc +++ b/liboctave/MArrayN.cc @@ -61,14 +61,18 @@ operator += (MArrayN<T>& a, const MArrayN<T>& b) { int l = a.length (); + if (l > 0) { - int bl = b.length (); - if (l != bl) - gripe_nonconformant ("operator +=", l, bl); + dim_vector a_dims = a.dims (); + dim_vector b_dims = b.dims (); + + if (a_dims != b_dims) + gripe_nonconformant ("operator +=", a_dims, b_dims); else DO_VV_OP2 (+=); } + return a; } @@ -77,11 +81,14 @@ operator -= (MArrayN<T>& a, const MArrayN<T>& b) { int l = a.length (); + if (l > 0) { - int bl = b.length (); - if (l != bl) - gripe_nonconformant ("operator -=", l, bl); + dim_vector a_dims = a.dims (); + dim_vector b_dims = b.dims (); + + if (a_dims != b_dims) + gripe_nonconformant ("operator -=", a_dims, b_dims); else DO_VV_OP2 (-=); }
--- a/liboctave/MDiagArray2.h +++ b/liboctave/MDiagArray2.h @@ -79,7 +79,7 @@ int len = nr < nc ? nr : nc; for (int i = 0; i < len; i++) - retval.xelem (i, i) = xelem (i, i); + retval.xelem (i, i) = this->xelem (i, i); return retval; }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,22 +1,61 @@ +2003-11-23 John W. Eaton <jwe@bevo.che.wisc.edu> + + * oct-stream.cc (octave_stream::seek): Extract std::streamoff from + tc_offset instead of int. + + * ov-re-mat.cc (octave_matrix::double_value): Use numel, not length. + + * ov-re-mat.cc (octave_matrix::streamoff_array_value): New function. + * ov-re-mat.h: Provide decl. + + * ov-scalar.cc (octave_scalar::streamoff_value): New function. + * ov-scalar.h: Provide decl. + + * ov.cc (octave_value::streamoff_array_value, + octave_value::streamoff_value): New functions. + * ov.h: Provide decls. + + * ov-base.cc (octave_base_value::streamoff_array_value, + octave_base_value::streamoff_value): New functions. + * ov-base.h: Provide decls. + + * ov-usr-fcn.cc (install_automatic_vars): Don't do anything unless + sym_tab is defined. + + * ov-streamoff.h, ov-streamoff.cc, OPERATORS/op-streamoff.cc: + New files. + + * ov-cell.h (octave_value_cell::is_matrix_type): New function. + + * ov-mapper.h (octave_mapper::octave_mapper): No copying. + * ov-fcn.h (octave_function::octave_function): Likewise. + * ov-usr-fcn.h (octave_function::octave_function): Likewise. + * ov-builtin.h (octave_builtin::octave_builtin): Likewise. + * ov-dld-fcn.h (octave_dld_function::octave_dld_function): Likewise. + 2003-11-22 John W. Eaton <jwe@bevo.che.wisc.edu> - * ov-dld-fcn.h (octave_dld_function::octave_dld_function): - Make public, but abort if called. + * ov-mapper.h (octave_mapper::octave_mapper): Make public. + Provide copy constructor and assignment operator. + * ov-fcn.h (octave_function::octave_function): Likewise. * ov-builtin.h (octave_builtin::octave_builtin): Likewise. - * ov-fcn.h (octave_function::octave_function): Likewise. + * ov-dld-fcn.h (octave_dld_function::octave_dld_function): Likewise. * ov-typeinfo.cc (octave_value_typeinfo::register_type, octave_value_typeinfo::do_register_type): New arg, val. + Save it in vals array. (octave_value_typeinfo::lookup_type, octave_value_typeinfo::do_lookup_type): New functions. * ov-typeinfo.h: Provide decl. + (octave_value_typeinfo::vals): New data member. + (octave_value_typeinfo::octave_value_typeinfo): Initialize it. * ov.h (DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA): Pass * ov.h (DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA): Define register_type here. Also pass an empty object of the to-be-registered type to register_type. - (DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA): Declare register type + (DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA): Declare register_type here, but don't define it. 2003-11-21 John W. Eaton <jwe@bevo.che.wisc.edu>
new file mode 100644 --- /dev/null +++ b/src/OPERATORS/op-streamoff.cc @@ -0,0 +1,159 @@ +/* + +Copyright (C) 2003 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. + +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "gripes.h" +#include "ov.h" +#include "ov-re-mat.h" +#include "ov-scalar.h" +#include "ov-streamoff.h" +#include "ov-typeinfo.h" +#include "ops.h" + +// streamoff unary ops. + +DEFUNOP (transpose, streamoff) +{ + CAST_UNOP_ARG (const octave_streamoff&); + + return octave_value (streamoff_array (v.streamoff_array_value().transpose ())); +} + +// DEFNCUNOP_METHOD (incr, streamoff, increment) +// DEFNCUNOP_METHOD (decr, streamoff, decrement) + +// streamoff by streamoff ops. + +DEFNDBINOP_OP (add, streamoff, streamoff, streamoff_array, streamoff_array, +) +DEFNDBINOP_OP (sub, streamoff, streamoff, streamoff_array, streamoff_array, -) + +DEFNDBINOP_OP (add_so_m, streamoff, matrix, streamoff_array, streamoff_array, +) +DEFNDBINOP_OP (sub_so_m, streamoff, matrix, streamoff_array, streamoff_array, -) + +DEFNDBINOP_OP (add_m_so, matrix, streamoff, streamoff_array, streamoff_array, +) +DEFNDBINOP_OP (sub_m_so, matrix, streamoff, streamoff_array, streamoff_array, +) +DEFNDBINOP_OP (add_so_s, streamoff, scalar, streamoff_array, streamoff, +) +DEFNDBINOP_OP (sub_so_s, streamoff, scalar, streamoff_array, streamoff, -) + +DEFNDBINOP_OP (add_s_so, scalar, streamoff, streamoff, streamoff_array, +) +DEFNDBINOP_OP (sub_s_so, scalar, streamoff, streamoff, streamoff_array, +) + +DEFBINOP (eq, streamoff, streamoff) +{ + CAST_BINOP_ARGS (const octave_streamoff&, + const octave_streamoff&); + + streamoff_array cm1 = v1.streamoff_array_value (); + streamoff_array cm2 = v2.streamoff_array_value (); + + if (cm1.rows () == 1 && cm1.columns () == 1) + { + if (cm2.rows () == 1 && cm2.columns () == 1) + return octave_value (cm1 (0, 0) == cm2 (0, 0)); + else + SC_MX_BOOL_OP (std::streamoff, c, cm1 (0, 0), streamoff_array, m, cm2, + c == m (i, j), 0.0); + } + else + { + int cm2_nr = cm2.rows (); + int cm2_nc = cm2.cols (); + + if (cm2_nr == 1 && cm2_nc == 1) + MX_SC_BOOL_OP (streamoff_array, m, cm1, std::streamoff, c, cm2 (0, 0), + c == m (i, j), 0.0); + else + MX_MX_BOOL_OP (streamoff_array, m1, cm1, streamoff_array, m2, cm2, + m1 (i, j) == m2 (i, j), "==", 0.0, 1.0); + } +} + +DEFBINOP (ne, streamoff, streamoff) +{ + CAST_BINOP_ARGS (const octave_streamoff&, + const octave_streamoff&); + + streamoff_array cm1 = v1.streamoff_array_value (); + streamoff_array cm2 = v2.streamoff_array_value (); + + if (cm1.rows () == 1 && cm1.columns () == 1) + { + if (cm2.rows () == 1 && cm2.columns () == 1) + return octave_value (cm1 (0, 0) != cm2 (0, 0)); + else + SC_MX_BOOL_OP (std::streamoff, c, cm1 (0, 0), streamoff_array, m, cm2, + c != m (i, j), 1.0); + } + else + { + if (cm2.rows () == 1 && cm2.columns () == 1) + MX_SC_BOOL_OP (streamoff_array, m, cm1, std::streamoff, c, cm2 (0, 0), + c != m (i, j), 1.0); + else + MX_MX_BOOL_OP (streamoff_array, m1, cm1, streamoff_array, m2, cm2, + m1 (i, j) != m2 (i, j), "!=", 1.0, 0.0); + } +} + +DEFASSIGNOP (assign, streamoff, streamoff) +{ + CAST_BINOP_ARGS (octave_streamoff&, const octave_streamoff&); + + v1.assign (idx, v2.streamoff_array_value ()); + return octave_value (); +} + +void +install_streamoff_ops (void) +{ + INSTALL_UNOP (op_transpose, octave_streamoff, transpose); + INSTALL_UNOP (op_hermitian, octave_streamoff, transpose); + + INSTALL_BINOP (op_eq, octave_streamoff, octave_streamoff, eq); + INSTALL_BINOP (op_ne, octave_streamoff, octave_streamoff, ne); + + INSTALL_BINOP (op_add, octave_streamoff, octave_streamoff, add); + INSTALL_BINOP (op_sub, octave_streamoff, octave_streamoff, sub); + + INSTALL_BINOP (op_add, octave_streamoff, octave_matrix, add_so_m); + INSTALL_BINOP (op_sub, octave_streamoff, octave_matrix, sub_so_m); + + INSTALL_BINOP (op_add, octave_matrix, octave_streamoff, add_m_so); + INSTALL_BINOP (op_sub, octave_matrix, octave_streamoff, sub_m_so); + + INSTALL_BINOP (op_add, octave_streamoff, octave_scalar, add_so_s); + INSTALL_BINOP (op_sub, octave_streamoff, octave_scalar, sub_so_s); + + INSTALL_BINOP (op_add, octave_scalar, octave_streamoff, add_s_so); + INSTALL_BINOP (op_sub, octave_scalar, octave_streamoff, sub_s_so); + + INSTALL_ASSIGNOP (op_asn_eq, octave_streamoff, octave_streamoff, assign); +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -43,6 +43,7 @@ #include "oct-stdstrm.h" #include "oct-stream.h" #include "oct-obj.h" +#include "ov-streamoff.h" #include "utils.h" // Possible values for conv_err: @@ -2697,12 +2698,12 @@ { int retval = -1; - int conv_err = 0; - - int xoffset = convert_to_valid_int (tc_offset, conv_err); - - if (! conv_err) + std::streamoff xoffset = tc_offset.streamoff_value (); + + if (! error_state) { + int conv_err = 0; + std::ios::seekdir origin = std::ios::beg; if (tc_origin.is_string ())
--- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -466,11 +466,20 @@ return retval; } -streamoff_array +std::streamoff octave_base_value::streamoff_value (void) const { + std::streamoff retval; + gripe_wrong_type_arg ("octave_base_value::streamoff_value()", type_name ()); + return retval; +} + +streamoff_array +octave_base_value::streamoff_array_value (void) const +{ streamoff_array retval; - gripe_wrong_type_arg ("octave_base_value::streamoff_value()", type_name ()); + gripe_wrong_type_arg ("octave_base_value::streamoff_array_value()", + type_name ()); return retval; }
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -226,7 +226,9 @@ int stream_number (void) const; - streamoff_array streamoff_value (void) const; + std::streamoff streamoff_value (void) const; + + streamoff_array streamoff_array_value (void) const; octave_function *function_value (bool silent);
--- a/src/ov-builtin.h +++ b/src/ov-builtin.h @@ -27,8 +27,6 @@ #pragma interface #endif -#include <cstdlib> - #include <string> #include "ov-fcn.h" @@ -44,7 +42,7 @@ { public: - octave_builtin (void) { abort (); } + octave_builtin (void) { } typedef octave_value_list (*fcn) (const octave_value_list&, int); @@ -79,7 +77,11 @@ private: - octave_builtin (const octave_builtin& m); + // No copying! + + octave_builtin (const octave_builtin& ob); + + octave_builtin& operator = (const octave_builtin& ob); DECLARE_OCTAVE_ALLOCATOR
--- a/src/ov-cell.h +++ b/src/ov-cell.h @@ -88,6 +88,8 @@ const std::list<octave_value_list>& idx, const octave_value& rhs); + bool is_matrix_type (void) const { return false; } + bool is_numeric_type (void) const { return false; } bool is_defined (void) const { return true; }
--- a/src/ov-dld-fcn.h +++ b/src/ov-dld-fcn.h @@ -27,8 +27,6 @@ #pragma interface #endif -#include <cstdlib> - #include <string> #include "oct-shlib.h" @@ -49,7 +47,7 @@ { public: - octave_dld_function (void) { abort (); } + octave_dld_function (void) { } octave_dld_function (octave_builtin::fcn ff, const octave_shlib& shl, const std::string& nm = std::string (), @@ -73,8 +71,6 @@ private: - octave_dld_function (const octave_dld_function& m); - octave_shlib sh_lib; // The time the file was last checked to see if it needs to be @@ -86,6 +82,12 @@ // on the file to see if it has changed. bool system_fcn_file; + // No copying! + + octave_dld_function (const octave_dld_function& fn); + + octave_dld_function& operator = (const octave_dld_function& fn); + DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
--- a/src/ov-fcn.h +++ b/src/ov-fcn.h @@ -27,8 +27,6 @@ #pragma interface #endif -#include <cstdlib> - #include <string> #include "oct-time.h" @@ -47,10 +45,7 @@ { public: - octave_function (void) { abort (); } - - octave_function (const octave_function& f) - : octave_base_value (), my_name (f.my_name), doc (f.doc) { } + octave_function (void) { } ~octave_function (void) { } @@ -98,6 +93,12 @@ private: + // No copying! + + octave_function (const octave_function& f); + + octave_function& operator = (const octave_function& f); + DECLARE_OCTAVE_ALLOCATOR };
--- a/src/ov-mapper.h +++ b/src/ov-mapper.h @@ -27,8 +27,6 @@ #pragma interface #endif -#include <cstdlib> - #include <string> #include "oct-obj.h" @@ -45,7 +43,7 @@ { public: - octave_mapper (void) { abort (); } + octave_mapper (void) { } typedef int (*ch_mapper) (int); typedef bool (*d_b_mapper) (double); @@ -86,8 +84,6 @@ private: - octave_mapper (const octave_mapper& m); - octave_value apply (const octave_value& arg) const; // ch_map_fcn is a kluge. @@ -121,6 +117,12 @@ bool can_ret_cmplx_for_real; + // No copying! + + octave_mapper (const octave_mapper& om); + + octave_mapper& operator = (const octave_mapper& om); + DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -82,8 +82,7 @@ { double retval = lo_ieee_nan_value (); - // XXX FIXME XXX -- maybe this should be a function, valid_as_scalar() - if (rows () > 0 && columns () > 0) + if (numel () > 0) { // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? if (Vwarn_fortran_indexing) @@ -135,6 +134,29 @@ return ComplexMatrix (matrix.matrix_value ()); } +streamoff_array +octave_matrix::streamoff_array_value (void) const +{ + streamoff_array retval (dims ()); + + int nel = numel (); + + for (int i = 0; i < nel; i++) + { + double d = matrix(i); + + if (D_NINT (d) == d) + retval(i) = std::streamoff (static_cast<long> (d)); + else + { + error ("conversion to streamoff_array value failed"); + break; + } + } + + return retval; +} + octave_value octave_matrix::convert_to_str_internal (bool, bool) const {
--- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -39,6 +39,7 @@ #include "error.h" #include "ov-base.h" #include "ov-base-mat.h" +#include "ov-streamoff.h" #include "ov-typeinfo.h" class Octave_map; @@ -103,6 +104,8 @@ NDArray array_value (bool = false) const { return matrix; } + streamoff_array streamoff_array_value (void) const; + void increment (void) { matrix += 1.0; } void decrement (void) { matrix -= 1.0; }
--- a/src/ov-scalar.cc +++ b/src/ov-scalar.cc @@ -76,6 +76,19 @@ return retval; } +std::streamoff +octave_scalar::streamoff_value (void) const +{ + std::streamoff retval (-1); + + if (D_NINT (scalar) == scalar) + retval = std::streamoff (static_cast<long> (scalar)); + else + error ("conversion to streamoff value failed"); + + return retval; +} + octave_value octave_scalar::convert_to_str_internal (bool, bool) const {
--- a/src/ov-scalar.h +++ b/src/ov-scalar.h @@ -100,6 +100,8 @@ ComplexNDArray complex_array_value (bool = false) const { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } + std::streamoff streamoff_value (void) const; + octave_value convert_to_str_internal (bool pad, bool force) const; void increment (void) { ++scalar; }
new file mode 100644 --- /dev/null +++ b/src/ov-streamoff.cc @@ -0,0 +1,235 @@ +/* + +Copyright (C) 2003 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__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <iostream> + +#include "Array.h" +#include "Array.cc" +#include "ArrayN.h" +#include "ArrayN.cc" + +#include "defun.h" +#include "error.h" +#include "gripes.h" +#include "ov-streamoff.h" +#include "oct-obj.h" +#include "unwind-prot.h" +#include "utils.h" +#include "ov-base-mat.h" +#include "ov-base-mat.cc" + +INSTANTIATE_ARRAY_AND_ASSIGN (std::streamoff); + +template class ArrayN<std::streamoff>; + +template class octave_base_matrix<streamoff_array>; + +DEFINE_OCTAVE_ALLOCATOR (octave_streamoff); + +DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_streamoff, + "streamoff", "streamoff"); +boolNDArray +streamoff_array::all (int dim) const +{ + MX_ND_ANY_ALL_REDUCTION (MX_ND_ALL_EVAL (MX_ND_ALL_EXPR), true); +} + +boolNDArray +streamoff_array::any (int dim) const +{ + MX_ND_ANY_ALL_REDUCTION (MX_ND_ANY_EVAL (MX_ND_ANY_EXPR), false); +} + +#if 0 +streamoff_array& +streamoff_array::operator += (const streamoff_array& a) +{ + // XXX FIXME XXX + return *this; +} + +streamoff_array& +streamoff_array::operator -= (const streamoff_array& a) +{ + // XXX FIXME XXX + return *this; +} +#endif + +int +streamoff_array::compute_index (Array<int>& ra_idx, + const dim_vector& dimensions) +{ + return ::compute_index (ra_idx, dimensions); +} + +SND_CMP_OP (mx_el_eq, ==, std::streamoff, , streamoff_array, , FBM) +SND_CMP_OP (mx_el_ne, !=, std::streamoff, , streamoff_array, , TBM) + +NDS_CMP_OP (mx_el_eq, ==, streamoff_array, , std::streamoff, , FBM) +NDS_CMP_OP (mx_el_ne, !=, streamoff_array, , std::streamoff, , TBM) + +NDND_CMP_OP (mx_el_eq, ==, streamoff_array, , streamoff_array, , FBM, TBM) +NDND_CMP_OP (mx_el_ne, !=, streamoff_array, , streamoff_array, , TBM, FBM) + +NDND_BIN_OP (streamoff_array, operator +, streamoff_array, streamoff_array, mx_inline_add) +NDND_BIN_OP (streamoff_array, operator -, streamoff_array, streamoff_array, mx_inline_subtract) + +NDS_BIN_OP (streamoff_array, operator +, streamoff_array, std::streamoff, mx_inline_add) +NDS_BIN_OP (streamoff_array, operator -, streamoff_array, std::streamoff, mx_inline_subtract) + +SND_BIN_OP (streamoff_array, operator +, std::streamoff, streamoff_array, mx_inline_add) +SND_BIN_OP (streamoff_array, operator -, std::streamoff, streamoff_array, mx_inline_subtract) + +std::streamoff +octave_streamoff::streamoff_value (void) const +{ + std::streamoff retval (-1); + + if (numel () > 0) + { + // XXX FIXME XXX -- is warn_fortran_indexing the right variable here? + if (Vwarn_fortran_indexing) + gripe_implicit_conversion ("streamoff array", "scalar streamoff"); + + retval = matrix (0, 0); + } + else + gripe_invalid_conversion ("streamoff array", "scalar streamoff"); + + return retval; +} + +void +octave_streamoff::print (std::ostream& os, bool) const +{ + print_raw (os); + newline (os); +} + +void +octave_streamoff::print_raw (std::ostream& os, bool) const +{ + dim_vector dv = matrix.dims (); + os << "<" << dv.str () << " streamoff object>"; +} + +DEFUN (isstreamoff, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} isstreamoff (@var{x})\n\ +Return true if @var{x} is a streamoff object. Otherwise, return\n\ +false.\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + retval = args(0).is_streamoff (); + else + print_usage ("isstreamoff"); + + return retval; +} + +DEFUN (streamoff, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} streamoff (@var{x})\n\ +@deftypefnx {Built-in Function} {} streamoff (@var{n}, @var{m})\n\ +Create a new streamoff array object. If invoked with a single scalar\n\ +argument, @code{streamoff} returns a square streamoff array with\n\ +the dimension specified. If you supply two scalar arguments,\n\ +@code{streamoff} takes them to be the number of rows and columns.\n\ +If given a vector with two elements, @code{streamoff} uses the values\n\ +of the elements as the number of rows and columns, respectively.\n\ +@end deftypefn") +{ + octave_value retval; + + int nargin = args.length (); + + dim_vector dims; + + switch (nargin) + { + case 0: + dims = dim_vector (0, 0); + break; + + case 1: + get_dimensions (args(0), "streamoff", dims); + break; + + default: + { + dims.resize (nargin); + + for (int i = 0; i < nargin; i++) + { + dims(i) = args(i).is_empty () ? 0 : args(i).nint_value (); + + if (error_state) + { + error ("streamoff: expecting scalar arguments"); + break; + } + } + } + break; + } + + if (! error_state) + { + int ndim = dims.length (); + + check_dimensions (dims, "streamoff"); + + if (! error_state) + { + switch (ndim) + { + case 1: + retval = Cell (dims(0), dims(0), Matrix ()); + break; + + default: + retval = Cell (dims, Matrix ()); + break; + } + } + } + + return retval; +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
new file mode 100644 --- /dev/null +++ b/src/ov-streamoff.h @@ -0,0 +1,160 @@ +/* + +Copyright (C) 2003 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_streamoff_h) +#define octave_streamoff_h 1 + +#if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) +#pragma interface +#endif + +#include <iostream> +#include <string> + +#include "mx-base.h" +#include "mx-op-defs.h" +#include "oct-alloc.h" +#include "str-vec.h" + +#include "error.h" +#include "oct-obj.h" +#include "ov-base-mat.h" +#include "ov-typeinfo.h" + +class tree_walker; + +// Stream offsets. + +class streamoff_array : public ArrayN<std::streamoff> +{ +public: + + streamoff_array (void) : ArrayN<std::streamoff> () { } + + streamoff_array (const dim_vector& dv, + const std::streamoff& val = resize_fill_value ()) + : ArrayN<std::streamoff> (dv, val) { } + + streamoff_array (const ArrayN<std::streamoff>& sa) + : ArrayN<std::streamoff> (sa) { } + + streamoff_array (const streamoff_array& sa) + : ArrayN<std::streamoff> (sa) { } + + ~streamoff_array (void) { } + + streamoff_array& operator = (const streamoff_array& a) + { + if (this != &a) + ArrayN<std::streamoff>::operator = (a); + + return *this; + } + + streamoff_array squeeze (void) const + { return ArrayN<std::streamoff>::squeeze (); } + + boolNDArray all (int dim = -1) const; + boolNDArray any (int dim = -1) const; + + // streamoff_array& operator += (const streamoff_array& a); + // streamoff_array& operator -= (const streamoff_array& a); + + static int compute_index (Array<int>& ra_idx, + const dim_vector& dimensions); + + static std::streamoff resize_fill_value (void) { return 0; } +}; + +NDCMP_OP_DECL (mx_el_eq, std::streamoff, streamoff_array); +NDCMP_OP_DECL (mx_el_ne, std::streamoff, streamoff_array); + +NDCMP_OP_DECL (mx_el_eq, streamoff_array, std::streamoff); +NDCMP_OP_DECL (mx_el_ne, streamoff_array, std::streamoff); + +NDCMP_OP_DECL (mx_el_eq, streamoff_array, streamoff_array); +NDCMP_OP_DECL (mx_el_ne, streamoff_array, streamoff_array); + +BIN_OP_DECL (streamoff_array, operator +, streamoff_array, streamoff_array); +BIN_OP_DECL (streamoff_array, operator -, streamoff_array, streamoff_array); + +BIN_OP_DECL (streamoff_array, operator +, streamoff_array, std::streamoff); +BIN_OP_DECL (streamoff_array, operator -, streamoff_array, std::streamoff); + +BIN_OP_DECL (streamoff_array, operator +, std::streamoff, streamoff_array); +BIN_OP_DECL (streamoff_array, operator -, std::streamoff, streamoff_array); + +class +octave_streamoff : public octave_base_matrix<streamoff_array> +{ +public: + + octave_streamoff (void) + : octave_base_matrix<streamoff_array> () { } + + octave_streamoff (const std::streamoff& off) + : octave_base_matrix<streamoff_array> + (streamoff_array (dim_vector (1, 1), off)) { } + + octave_streamoff (const streamoff_array& off) + : octave_base_matrix<streamoff_array> (off) { } + + octave_streamoff (const octave_streamoff& off) + : octave_base_matrix<streamoff_array> (off) { } + + ~octave_streamoff (void) { } + + octave_value *clone (void) const { return new octave_streamoff (*this); } + octave_value *empty_clone (void) const { return new octave_streamoff (); } + + bool is_defined (void) const { return true; } + + bool is_streamoff (void) const { return true; } + + std::streamoff streamoff_value (void) const; + + streamoff_array streamoff_array_value (void) const { return matrix; } + + // void increment (void) { matrix += 1; } + + // void decrement (void) { matrix -= 1; } + + bool print_as_scalar (void) const { return true; } + + 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; + +private: + + DECLARE_OCTAVE_ALLOCATOR + + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
--- a/src/ov-typeinfo.h +++ b/src/ov-typeinfo.h @@ -122,6 +122,7 @@ octave_value_typeinfo (void) : num_types (0), types (init_tab_sz, std::string ()), + vals (init_tab_sz), unary_ops (octave_value::num_unary_ops, init_tab_sz, (unary_op_fcn) 0), non_const_unary_ops (octave_value::num_unary_ops, init_tab_sz,
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -558,12 +558,15 @@ void octave_user_function::install_automatic_vars (void) { - argn_sr = sym_tab->lookup ("argn", true); - nargin_sr = sym_tab->lookup ("nargin", true); - nargout_sr = sym_tab->lookup ("nargout", true); + if (sym_tab) + { + argn_sr = sym_tab->lookup ("argn", true); + nargin_sr = sym_tab->lookup ("nargin", true); + nargout_sr = sym_tab->lookup ("nargout", true); - if (takes_varargs ()) - varargin_sr = sym_tab->lookup ("varargin", true); + if (takes_varargs ()) + varargin_sr = sym_tab->lookup ("varargin", true); + } } void
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -168,8 +168,6 @@ private: - octave_user_function (const octave_user_function& m); - // List of arguments for this function. These are local variables. tree_parameter_list *param_list; @@ -256,6 +254,13 @@ void bind_automatic_vars (const string_vector& arg_names, int nargin, int nargout, const octave_value_list& va_args); + + // No copying! + + octave_user_function (const octave_user_function& fn); + + octave_user_function& operator = (const octave_user_function& fn); + DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
--- a/src/ov.cc +++ b/src/ov.cc @@ -930,12 +930,18 @@ return rep->stream_number (); } -streamoff_array +std::streamoff octave_value::streamoff_value (void) const { return rep->streamoff_value (); } +streamoff_array +octave_value::streamoff_array_value (void) const +{ + return rep->streamoff_array_value (); +} + octave_function * octave_value::function_value (bool silent) {
--- a/src/ov.h +++ b/src/ov.h @@ -548,7 +548,9 @@ virtual int stream_number (void) const; - virtual streamoff_array streamoff_value (void) const; + virtual std::streamoff streamoff_value (void) const; + + virtual streamoff_array streamoff_array_value (void) const; virtual octave_function *function_value (bool silent = false); @@ -779,7 +781,7 @@ { \ t_id = octave_value_typeinfo::register_type (t::t_name, \ t::c_name, \ - octave_value (new t)); \ + octave_value (new t ())); \ } // If TRUE, print a warning for assignments like