aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-07 14:17:33 +0000
committerjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-07 14:17:33 +0000
commit6b4191b3208a563102e5278b49c4c4a0e2092704 (patch)
treebb9c2a9f1fa45c91b971ea6600baab1853d4a5e2 /src
parentec7974cd2a9ed540cc0022e365a13ff961c128aa (diff)
change rvalue operator() fns to return const references to array data
so they can be used in unary address-of expressions eg const jtutil::array2d<double> A(...) const double *pij = &A(i,j); also add test program for this git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@458 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src')
-rw-r--r--src/jtutil/array.hh16
-rw-r--r--src/jtutil/makefile5
-rw-r--r--src/jtutil/test_array2.cc56
3 files changed, 67 insertions, 10 deletions
diff --git a/src/jtutil/array.hh b/src/jtutil/array.hh
index d2532e0..8da4366 100644
--- a/src/jtutil/array.hh
+++ b/src/jtutil/array.hh
@@ -94,9 +94,9 @@ public:
// normal-use access functions
// ... rvalue
- T operator()(int i) const { return array_[ subscript(i) ]; }
+ const T& operator()(int i) const { return array_[ subscript(i) ]; }
// ... lvalue
- T& operator()(int i) { return array_[ subscript(i) ]; }
+ T& operator()(int i) { return array_[ subscript(i) ]; }
// get access to internal 0-origin 1D storage array
// (low-level, dangerous, use with caution!)
@@ -185,10 +185,10 @@ public:
// normal-use access functions
// ... rvalue
- T operator()(int i, int j) const
+ const T& operator()(int i, int j) const
{ return array_[ subscript(i,j) ]; }
// ... lvalue
- T& operator()(int i, int j)
+ T& operator()(int i, int j)
{ return array_[ subscript(i,j) ]; }
// get access to internal 0-origin 1D storage array
@@ -285,10 +285,10 @@ public:
// normal-use access functions
// ... rvalue
- T operator()(int i, int j, int k) const
+ const T& operator()(int i, int j, int k) const
{ return array_[ subscript(i,j,k) ]; }
// ... lvalue
- T& operator()(int i, int j, int k)
+ T& operator()(int i, int j, int k)
{ return array_[ subscript(i,j,k) ]; }
// get access to internal 0-origin 1D storage array
@@ -398,10 +398,10 @@ public:
// normal-use access functions
// ... rvalue
- T operator()(int i, int j, int k, int l) const
+ const T& operator()(int i, int j, int k, int l) const
{ return array_[ subscript(i,j,k,l) ]; }
// ... lvalue
- T& operator()(int i, int j, int k, int l)
+ T& operator()(int i, int j, int k, int l)
{ return array_[ subscript(i,j,k,l) ]; }
// get access to internal 0-origin 1D storage array
diff --git a/src/jtutil/makefile b/src/jtutil/makefile
index 370ca97..6d62512 100644
--- a/src/jtutil/makefile
+++ b/src/jtutil/makefile
@@ -1,5 +1,5 @@
# Makefile for standalone test drivers in this directory
-# $Id: makefile,v 1.1 2002-04-05 17:42:11 jthorn Exp $
+# $Id: makefile,v 1.2 2002-04-07 14:17:33 jthorn Exp $
#
# CC, CXX = C and C++ compilers. Defaults are gcc and g++ if
# variables aren't set from command line or environment.
@@ -25,13 +25,14 @@ CXXFLAGS := $(STD_GXX_FLAGS) -I.. -g
################################################################################
-test : test_array \
+test : test_array test_array2 \
test_cpm_map test_linear_map \
test_fuzzy test_round \
test_modulo test_norm
test_array : test_array.o array.o \
fuzzy.o round.o -lm
+test_array2 : test_array2.o array.o
test_cpm_map : test_cpm_map.o cpm_map.o \
fuzzy.o round.o error_exit.o -lm
test_linear_map : test_linear_map.o linear_map.o \
diff --git a/src/jtutil/test_array2.cc b/src/jtutil/test_array2.cc
new file mode 100644
index 0000000..555c684
--- /dev/null
+++ b/src/jtutil/test_array2.cc
@@ -0,0 +1,56 @@
+// test_array2.cc -- test driver for array.hh classes
+// $Id$
+
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "jt/stdc.h"
+#include "jt/util.hh"
+#include "jt/array.hh"
+
+void print( jtutil::array2d<double>& Aref);
+void cprint(const jtutil::array2d<double>& Aref);
+
+int main()
+{
+const int imin = 3, imax = 7, jmin = 10, jmax = 12;
+jtutil::array2d<double> A(imin,imax, jmin,jmax);
+
+ for (int i = imin ; i <= imax ; ++i)
+ {
+ for (int j = jmin ; j <= jmax ; ++j)
+ {
+ A(i,j) = i*j;
+ }
+ }
+
+ print(A);
+cprint(A);
+}
+
+void print(jtutil::array2d<double>& Aref)
+{
+printf("=== nonconst ===\n");
+ for (int i = Aref.min_i() ; i <= Aref.max_i() ; ++i)
+ {
+ for (int j = Aref.min_j() ; j <= Aref.max_j() ; ++j)
+ {
+ printf("Aref(%d,%d) = %g at address %p\n",
+ i, j, Aref(i,j), &Aref(i,j));
+ }
+ }
+}
+
+void cprint(const jtutil::array2d<double>& Aref)
+{
+printf("=== const ===\n");
+ for (int i = Aref.min_i() ; i <= Aref.max_i() ; ++i)
+ {
+ for (int j = Aref.min_j() ; j <= Aref.max_j() ; ++j)
+ {
+ printf("Aref(%d,%d) = %g at address %p\n",
+ i, j, Aref(i,j), &Aref(i,j));
+ }
+ }
+}