changeset 10810:6683f0c9d742

make the maximum extent externally accessible
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 20 Jul 2010 21:19:10 +0200
parents 85cbd239fce2
children e38c071bbc41
files liboctave/ChangeLog liboctave/dim-vector.cc liboctave/dim-vector.h
diffstat 3 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,8 @@
+2010-07-20  Jaroslav Hajek  <highegg@gmail.com>
+
+	* dim-vector.cc (dim_vector::dim_max): New static const member.
+	* dim-vector.h: Declare it.
+
 2010-07-20  Jaroslav Hajek  <highegg@gmail.com>
 
 	* dMatrix.cc (Matrix::extract, Matrix::extract_n): Reimplement using
--- a/liboctave/dim-vector.cc
+++ b/liboctave/dim-vector.cc
@@ -29,6 +29,13 @@
 
 #include "dim-vector.h"
 
+// The maximum allowed value for a dimension extent. This will normally be a tiny bit
+// off the maximum value of octave_idx_type.
+// Currently 1 is subtracted to allow safe conversion of any 2D Array into Sparse,
+// but this offset may change in the future.
+const octave_idx_type
+dim_vector::dim_max = std::numeric_limits<octave_idx_type>::max () - 1;
+
 void
 dim_vector::chop_all_singletons (void)
 {
@@ -82,7 +89,7 @@
 octave_idx_type
 dim_vector::safe_numel (void) const
 {
-  octave_idx_type idx_max = std::numeric_limits<octave_idx_type>::max () - 1;
+  octave_idx_type idx_max = dim_max;
   octave_idx_type n = 1;
   int n_dims = length ();
 
--- a/liboctave/dim-vector.h
+++ b/liboctave/dim-vector.h
@@ -219,6 +219,8 @@
 
 public:
 
+  static const octave_idx_type dim_max;
+
   explicit dim_vector (void) : rep (nil_rep ()) { count()++; }
 
   dim_vector (const dim_vector& dv) : rep (dv.rep) { count()++; }