diff options
author | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2001-06-15 16:08:48 +0000 |
---|---|---|
committer | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2001-06-15 16:08:48 +0000 |
commit | 9f8c71b602a884413ae9b5ded47c5eb594554a93 (patch) | |
tree | 32cdee67c503bc78c317b462ce981342ac7f5058 /src/jtutil/array.hh | |
parent | b32429af16d0c317941f8f5f7473f6c0ec8d84a1 (diff) |
fix comments around assert() error traps
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@28 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/jtutil/array.hh')
-rw-r--r-- | src/jtutil/array.hh | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/src/jtutil/array.hh b/src/jtutil/array.hh index 7bdddf1..cc3349d 100644 --- a/src/jtutil/array.hh +++ b/src/jtutil/array.hh @@ -11,16 +11,15 @@ // prerequisites: // <assert.h> // "jt/stdc.h" -// "jt/util++.h" // jtutil::how_many_in_range() +// "jt/util++.h" // for jtutil::how_many_in_range() // // -// The templates defined in this file represent n-dimensional contiguous -// arrays, parameterized by the data type (most commonly float or double, -// but could also be bool, int, long double, ...). In all cases the arrays -// are stored in row-major fashion, i.e. the last axis is contiguous and -// the first axis is least contiguous. These arrays cannot be copied or -// passed to functions by value; use pass by reference instead. +// The templates defined in this file represent n-dimensional row-major +// contiguous arrays, parameterized by the data type (most commonly float +// or double, but could also be bool, int, long double, ...). These +// arrays cannot be copied or passed to functions by value; use pass +// by reference instead. // // Stroustrup ("The C++ Programming Language", 3rd edition, appendix C.7) // suggests the use of STL vectors of STL vectors to provide multidimensional @@ -42,8 +41,10 @@ // #endif -//***************************************************************************** +//****************************************************************************** +namespace jtutil + { template <class fpt> class array1d { @@ -95,9 +96,12 @@ private: // min/max array bounds const int min_i_, max_i_; }; + }; // close namespace jtutil:: -//***************************************************************************** +//****************************************************************************** +namespace jtutil + { template <class fpt> class array2d { @@ -111,14 +115,8 @@ public: int N_j() const { return jtutil::how_many_in_range(min_j_, max_j_); } bool is_valid_i(int i) const { return (i >= min_i_) && (i <= max_i_); } bool is_valid_j(int j) const { return (j >= min_j_) && (j <= max_j_); } - bool is_valid_subscript(int i, int j) - const - { - // we want each fn call here to be on a separate source line, - // so assert() failure message can pinpoint which index is bad - return is_valid_i(i) - && is_valid_j(j); - } + bool is_valid_subscript(int i, int j) const + { return is_valid_i(i) && is_valid_j(j); } // subscripting functions // (low-level, dangerous, use with caution!) @@ -130,7 +128,10 @@ public: { assert( is_valid_subscript(i,j) ); const int posn = subscript_unchecked(i,j); - assert(posn >= 0); assert(posn <= N_array_); + // we want each assert() here to be on a separate source line, + // so assert() failure message can pinpoint which index is bad + assert(posn >= 0); + assert(posn <= N_array_); return posn; } @@ -174,9 +175,12 @@ private: const int min_i_, max_i_; const int min_j_, max_j_; }; + }; // close namespace jtutil:: -//***************************************************************************** +//****************************************************************************** +namespace jtutil + { template <class fpt> class array3d { @@ -194,15 +198,8 @@ public: bool is_valid_i(int i) const { return (i >= min_i_) && (i <= max_i_); } bool is_valid_j(int j) const { return (j >= min_j_) && (j <= max_j_); } bool is_valid_k(int k) const { return (k >= min_k_) && (k <= max_k_); } - bool is_valid_subscript(int i, int j, int k) - const - { - // we want each fn call here to be on a separate source line, - // so assert() failure message can pinpoint which index is bad - return is_valid_i(i) - && is_valid_j(j) - && is_valid_k(k); - } + bool is_valid_subscript(int i, int j, int k) const + { return is_valid_i(i) && is_valid_j(j) && is_valid_k(k); } // subscripting functions // (low-level, dangerous, use with caution!) @@ -214,7 +211,10 @@ public: { assert( is_valid_subscript(i,j,k) ); const int posn = subscript_unchecked(i,j,k); - assert(posn >= 0); assert(posn <= N_array_); + // we want each assert() here to be on a separate source line, + // so assert() failure message can pinpoint which index is bad + assert(posn >= 0); + assert(posn <= N_array_); return posn; } @@ -260,9 +260,12 @@ private: const int min_j_, max_j_; const int min_k_, max_k_; }; + }; // close namespace jtutil:: -//***************************************************************************** +//****************************************************************************** +namespace jtutil + { template <class fpt> class array4d { @@ -287,12 +290,8 @@ public: bool is_valid_subscript(int i, int j, int k, int l) const { - // we want each fn call here to be on a separate source line, - // so assert() failure message can pinpoint which index is bad - return is_valid_i(i) - && is_valid_j(j) - && is_valid_k(k) - && is_valid_l(l); + return is_valid_i(i) && is_valid_j(j) + && is_valid_k(k) && is_valid_l(l); } // subscripting functions @@ -307,7 +306,10 @@ public: { assert( is_valid_subscript(i,j,k,l) ); const int posn = subscript_unchecked(i,j,k,l); - assert(posn >= 0); assert(posn <= N_array_); + // we want each assert() here to be on a separate source line, + // so assert() failure message can pinpoint which index is bad + assert(posn >= 0); + assert(posn <= N_array_); return posn; } @@ -355,3 +357,4 @@ private: const int min_k_, max_k_; const int min_l_, max_l_; }; + }; // close namespace jtutil:: |