Mercurial > hg > octave-nkf
changeset 2006:95e952f72d66
[project @ 1996-03-04 00:33:32 by jwe]
author | jwe |
---|---|
date | Mon, 04 Mar 1996 00:40:14 +0000 |
parents | c1ffef39e94a |
children | 413b1a8da40f |
files | liboctave/Array-C.cc liboctave/Array-ch.cc liboctave/Array-d.cc liboctave/Array-i.cc liboctave/Array-s.cc liboctave/Array-str.cc liboctave/Array.cc liboctave/Array.h liboctave/Array2.cc liboctave/Array2.h liboctave/MArray-C.cc liboctave/MArray-ch.cc liboctave/MArray-d.cc liboctave/MArray-i.cc liboctave/MArray-s.cc liboctave/MDiagArray2.cc liboctave/pathsearch.cc |
diffstat | 17 files changed, 137 insertions(+), 107 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array-C.cc +++ b/liboctave/Array-C.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate Arrays of Complex values. #include "oct-cmplx.h"
--- a/liboctave/Array-ch.cc +++ b/liboctave/Array-ch.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate Arrays of char values. #include "Array.h"
--- a/liboctave/Array-d.cc +++ b/liboctave/Array-d.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate Arrays of double values. #include "Array.h"
--- a/liboctave/Array-i.cc +++ b/liboctave/Array-i.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate Arrays of integer values. #include "Array.h"
--- a/liboctave/Array-s.cc +++ b/liboctave/Array-s.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate Arrays of short int values. #include "Array.h"
--- a/liboctave/Array-str.cc +++ b/liboctave/Array-str.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate Arrays of strings. #include "Array.h"
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -94,47 +94,6 @@ } template <class T> -T& -Array<T>::checkelem (int n) -{ - if (n < 0 || n >= rep->length ()) - { - (*current_liboctave_error_handler) ("range error"); - static T foo; - return foo; - } - return elem (n); -} - -template <class T> -T -Array<T>::elem (int n) const -{ - return rep->elem (n); -} - -template <class T> -T -Array<T>::checkelem (int n) const -{ - if (n < 0 || n >= rep->length ()) - { - (*current_liboctave_error_handler) ("range error"); - T foo; - static T *bar = &foo; - return foo; - } - return elem (n); -} - -template <class T> -T -Array<T>::operator () (int n) const -{ - return checkelem (n); -} - -template <class T> void Array<T>::resize (int n) {
--- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -82,6 +82,15 @@ } }; + void make_unique (void) + { + if (rep->count > 1) + { + --rep->count; + rep = new ArrayRep (*rep); + } + } + #ifdef HEAVYWEIGHT_INDEXING idx_vector *idx; int max_indices; @@ -148,24 +157,55 @@ int capacity (void) const { return rep->length (); } int length (void) const { return rep->length (); } + // XXX FIXME XXX -- would be nice to fix this so that we don't + // unnecessarily force a copy, but that is not so easy, and I see no + // clean way to do it. + T& elem (int n) { - if (rep->count > 1) - { - --rep->count; - rep = new ArrayRep (*rep); - } + make_unique (); return rep->elem (n); } - T& checkelem (int n); + T& Array<T>::checkelem (int n) + { + if (n < 0 || n >= rep->length ()) + { + (*current_liboctave_error_handler) ("range error"); + static T foo; + return foo; + } + else + return elem (n); + } + +#if defined (NO_BOUNDS_CHECKING) + T& operator () (int n) { return elem (n); } +#else T& operator () (int n) { return checkelem (n); } +#endif + + T Array<T>::elem (int n) const { return rep->elem (n); } - T elem (int n) const; - T checkelem (int n) const; - T operator () (int n) const; + T Array<T>::checkelem (int n) const + { + if (n < 0 || n >= rep->length ()) + { + (*current_liboctave_error_handler) ("range error"); + T foo; + static T *bar = &foo; + return foo; + } + return elem (n); + } - // No checking. +#if defined (NO_BOUNDS_CHECKING) + T Array<T>::operator () (int n) const { return elem (n); } +#else + T Array<T>::operator () (int n) const { return checkelem (n); } +#endif + + // No checking, even for multiple references, ever. T& xelem (int n) { return rep->elem (n); } T xelem (int n) const { return rep->elem (n); }
--- a/liboctave/Array2.cc +++ b/liboctave/Array2.cc @@ -45,54 +45,6 @@ // Two dimensional array class. template <class T> -T& -Array2<T>::checkelem (int i, int j) -{ - if (i < 0 || j < 0 || i >= d1 || j >= d2) - { - (*current_liboctave_error_handler) ("range error"); - static T foo; - return foo; - } - return Array<T>::elem (d1*j+i); -} - -template <class T> -T -Array2<T>::elem (int i, int j) const -{ - return Array<T>::elem (d1*j+i); -} - -template <class T> -T -Array2<T>::checkelem (int i, int j) const -{ - if (i < 0 || j < 0 || i >= d1 || j >= d2) - { - (*current_liboctave_error_handler) ("range error"); - T foo; - static T *bar = &foo; - return foo; - } - return Array<T>::elem (d1*j+i); -} - -template <class T> -T -Array2<T>::operator () (int i, int j) const -{ - if (i < 0 || j < 0 || i >= d1 || j >= d2) - { - (*current_liboctave_error_handler) ("range error"); - T foo; - static T *bar = &foo; - return foo; - } - return Array<T>::elem (d1*j+i); -} - -template <class T> void Array2<T>::resize (int r, int c) {
--- a/liboctave/Array2.h +++ b/liboctave/Array2.h @@ -116,14 +116,47 @@ int columns (void) const { return d2; } T& elem (int i, int j) { return Array<T>::elem (d1*j+i); } - T& checkelem (int i, int j); + + T& checkelem (int i, int j) + { + if (i < 0 || j < 0 || i >= d1 || j >= d2) + { + (*current_liboctave_error_handler) ("range error"); + static T foo; + return foo; + } + else + return elem (i, j); + } + +#if defined (NO_BOUNDS_CHECKING) + T& operator () (int i, int j) { return elem (i, j); } +#else T& operator () (int i, int j) { return checkelem (i, j); } +#endif + + T elem (int i, int j) const { return Array<T>::elem (d1*j+i); } - T elem (int i, int j) const; - T checkelem (int i, int j) const; - T operator () (int i, int j) const; + T checkelem (int i, int j) const + { + if (i < 0 || j < 0 || i >= d1 || j >= d2) + { + (*current_liboctave_error_handler) ("range error"); + T foo; + static T *bar = &foo; + return foo; + } + else + return elem (i, j); + } - // No checking. +#if defined (NO_BOUNDS_CHECKING) + T operator () (int i, int j) const { return elem (i, j); } +#else + T operator () (int i, int j) const { return checkelem (i, j); } +#endif + + // No checking of any kind, ever. T& xelem (int i, int j) { return Array<T>::xelem (d1*j+i); } T xelem (int i, int j) const { return Array<T>::xelem (d1*j+i); }
--- a/liboctave/MArray-C.cc +++ b/liboctave/MArray-C.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate MArrays of Complex values. #include "oct-cmplx.h"
--- a/liboctave/MArray-ch.cc +++ b/liboctave/MArray-ch.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate MArrays of char values. #include "MArray.h"
--- a/liboctave/MArray-d.cc +++ b/liboctave/MArray-d.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate MArrays of double values. #include "MArray.h"
--- a/liboctave/MArray-i.cc +++ b/liboctave/MArray-i.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate MArrays of int values. #include "MArray.h"
--- a/liboctave/MArray-s.cc +++ b/liboctave/MArray-s.cc @@ -20,6 +20,10 @@ */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + // Instantiate MArrays of short int values. #include "MArray.h"
--- a/liboctave/MDiagArray2.cc +++ b/liboctave/MDiagArray2.cc @@ -47,7 +47,8 @@ { (*current_liboctave_error_handler) ("nonconformant array operator += attempted"); - return MDiagArray2<T> (); + static MDiagArray2<T> foo; + return foo; } else { @@ -67,7 +68,8 @@ { (*current_liboctave_error_handler) ("nonconformant array operator -= attempted"); - return MDiagArray2<T> (); + static MDiagArray2<T> foo; + return foo; } else {