changeset 10150:3778ea95adea

style fixes
author John W. Eaton <jwe@octave.org>
date Wed, 20 Jan 2010 13:31:45 -0500
parents 722b43fd486e
children c2f1cdb59821
files liboctave/ChangeLog liboctave/dim-vector.h
diffstat 2 files changed, 221 insertions(+), 192 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Wed Jan 20 12:49:09 2010 -0500
+++ b/liboctave/ChangeLog	Wed Jan 20 13:31:45 2010 -0500
@@ -1,3 +1,8 @@
+2010-01-20  John W. Eaton  <jwe@octave.org>
+
+	* dim-vector.h: Style fixes.  Remove Emacs local variables block.
+	Untabify.
+
 2010-01-20  John W. Eaton  <jwe@octave.org>
 
 	* Makefile.am (PRIVATE_INCS): New variable.  List oct-glob.h
--- a/liboctave/dim-vector.h	Wed Jan 20 12:49:09 2010 -0500
+++ b/liboctave/dim-vector.h	Wed Jan 20 13:31:45 2010 -0500
@@ -32,20 +32,21 @@
 
 #include "lo-error.h"
 
-// Rationale: This implementation is more tricky than Array, but the big plus
-// is that dim_vector requires only one allocation instead of two.
-// It is (slightly) patterned after GCC's basic_string implementation.
-// rep is a pointer to an array of memory, comprising count, length,
-// and the data:
+// Rationale: This implementation is more tricky than Array, but the
+// big plus is that dim_vector requires only one allocation instead of
+// two.  It is (slightly) patterned after GCC's basic_string
+// implementation.  rep is a pointer to an array of memory, comprising
+// count, length, and the data:
+//
 //          <count>
 //          <ndims>
 //  rep --> <dims[0]>
 //          <dims[1]>
-// ...
+//          ...
 //
-// The inlines count(), ndims() recover this data
-// from the rep. rep points to the beginning of dims to grant
-// faster access (internally, reinterpret_cast is a no-op).
+// The inlines count(), ndims() recover this data from the rep.  Note
+// that rep points to the beginning of dims to grant faster access
+// (reinterpret_cast is assumed to be an inexpensive operation).
 
 class
 dim_vector
@@ -54,57 +55,76 @@
 
   octave_idx_type *rep;
 
-  octave_idx_type& ndims() const
-    { return rep[-1]; }
+  octave_idx_type& ndims (void) const { return rep[-1]; }
 
-  octave_idx_type& count() const
-    { return rep[-2]; }
+  octave_idx_type& count (void) const { return rep[-2]; }
 
-  // Constructs a new rep with count = 1 and ndims given.
+  // Construct a new rep with count = 1 and ndims given.
+
   static octave_idx_type *newrep (int ndims)
-    {
-      octave_idx_type *r = new octave_idx_type[ndims + 2];
-      *r++ = 1; *r++ = ndims;
-      return r;
-    }
+  {
+    octave_idx_type *r = new octave_idx_type[ndims + 2];
+
+    *r++ = 1;
+    *r++ = ndims;
 
-  // Clones this->rep.
+    return r;
+  }
+
+  // Clone this->rep.
+
   octave_idx_type *clonerep (void)
-    {
-      int l = ndims();
-      octave_idx_type *r = new octave_idx_type[l + 2];
-      *r++ = 1; *r++ = l;
-      for (int i = 0; i < l; i++)
-        r[i] = rep[i];
-      return r;
-    }
+  {
+    int l = ndims ();
+
+    octave_idx_type *r = new octave_idx_type[l + 2];
+
+    *r++ = 1;
+    *r++ = l;
 
-  // Clones & resizes this->rep to length n, filling by given value.
+    for (int i = 0; i < l; i++)
+      r[i] = rep[i];
+
+    return r;
+  }
+
+  // Clone and resize this->rep to length n, filling by given value.
+
   octave_idx_type *resizerep (int n, octave_idx_type fill_value)
-    {
-      int l = ndims();
-      if (n < 2) n = 2;
-      octave_idx_type *r = new octave_idx_type[n + 2];
-      *r++ = 1; *r++ = n;
-      if (l > n) l = n;
-      int j;
-      for (j = 0; j < l; j++)
-        r[j] = rep[j];
-      for (; j < n; j++)
-        r[j] = fill_value;
-      return r;
-    }
+  {
+    int l = ndims ();
+
+    if (n < 2)
+      n = 2;
+
+    octave_idx_type *r = new octave_idx_type[n + 2];
+
+    *r++ = 1;
+    *r++ = n;
+
+    if (l > n)
+      l = n;
 
-  // Frees the rep.
+    int j;
+    for (j = 0; j < l; j++)
+      r[j] = rep[j];
+    for (; j < n; j++)
+      r[j] = fill_value;
+
+    return r;
+  }
+
+  // Free the rep.
+
   void freerep (void)
-    {
-      assert (count() == 0);
-      delete [] (rep - 2);
-    }
+  {
+    assert (count () == 0);
+    delete [] (rep - 2);
+  }
 
   void make_unique (void)
   {
-    if (count() > 1)
+    if (count () > 1)
       {
         --count();
         rep = clonerep ();
@@ -115,69 +135,70 @@
 
   explicit dim_vector (octave_idx_type n)
     : rep (newrep (2))
-    {
-      rep[0] = n;
-      rep[1] = 1;
-    }
+  {
+    rep[0] = n;
+    rep[1] = 1;
+  }
 
   explicit dim_vector (octave_idx_type r, octave_idx_type c)
     : rep (newrep (2))
-    {
-      rep[0] = r;
-      rep[1] = c;
-    }
+  {
+    rep[0] = r;
+    rep[1] = c;
+  }
 
   explicit dim_vector (octave_idx_type r, octave_idx_type c, octave_idx_type p)
     : rep (newrep (3))
-    {
-      rep[0] = r;
-      rep[1] = c;
-      rep[2] = p;
-    }
+  {
+    rep[0] = r;
+    rep[1] = c;
+    rep[2] = p;
+  }
 
   octave_idx_type& elem (int i)
-    {
-      assert (i >= 0 && i < ndims());
-      make_unique ();
-      return rep[i];
-    }
+  {
+    assert (i >= 0 && i < ndims ());
+    make_unique ();
+    return rep[i];
+  }
 
   octave_idx_type elem (int i) const
-    {
-      assert (i >= 0 && i < ndims());
-      return rep[i];
-    }
+  {
+    assert (i >= 0 && i < ndims ());
+    return rep[i];
+  }
 
   void chop_trailing_singletons (void)
-    {
-      int l = ndims();
-      if (l > 2 && rep[l-1] == 1)
-        {
-          make_unique ();
-          do
-            l--;
-          while (l > 2 && rep[l-1] == 1);
-          ndims() = l;
-        }
-    }
+  {
+    int l = ndims ();
+    if (l > 2 && rep[l-1] == 1)
+      {
+        make_unique ();
+        do
+          l--;
+        while (l > 2 && rep[l-1] == 1);
+        ndims () = l;
+      }
+  }
 
   void chop_all_singletons (void)
-    {
-      make_unique ();
-      int j = 0;
-      int l = ndims();
+  {
+    make_unique ();
+
+    int j = 0;
+    int l = ndims();
 
-      for (int i = 0; i < l; i++)
-        {
-          if (rep[i] != 1)
-            rep[j++] = rep[i];
-        }
+    for (int i = 0; i < l; i++)
+      {
+        if (rep[i] != 1)
+          rep[j++] = rep[i];
+      }
 
-      if (j == 1)
-        rep[1] = 1;
+    if (j == 1)
+      rep[1] = 1;
 
-      ndims() = j > 2 ? j : 2;
-    }
+    ndims () = j > 2 ? j : 2;
+  }
 
 private:
   
@@ -192,25 +213,23 @@
 
 public:
 
-  explicit dim_vector (void)
-    : rep (nil_rep ()) { count()++; }
+  explicit dim_vector (void) : rep (nil_rep ()) { count()++; }
 
-  dim_vector (const dim_vector& dv)
-    : rep (dv.rep) { count()++; }
+  dim_vector (const dim_vector& dv) : rep (dv.rep) { count()++; }
 
   static dim_vector alloc (int n)
-    {
-      return dim_vector (newrep (n < 2 ? 2 : n));
-    }
+  {
+    return dim_vector (newrep (n < 2 ? 2 : n));
+  }
 
   dim_vector& operator = (const dim_vector& dv)
   {
     if (&dv != this)
       {
-	if (--count() <= 0)
+        if (--count() <= 0)
           freerep ();
 
-	rep = dv.rep;
+        rep = dv.rep;
         count()++;
       }
 
@@ -223,7 +242,7 @@
       freerep ();
   }
 
-  int length (void) const { return ndims(); }
+  int length (void) const { return ndims (); }
 
   octave_idx_type& operator () (int i) { return elem (i); }
 
@@ -250,10 +269,10 @@
 
     for (int i = 0; i < length (); i++)
       {
-	buf << elem (i);
+        buf << elem (i);
 
-	if (i < length () - 1)
-	  buf << sep;
+        if (i < length () - 1)
+          buf << sep;
       }
 
     std::string retval = buf.str ();
@@ -267,11 +286,11 @@
 
     for (int i = 0; i < length (); i++)
       {
-	if (elem (i) != 0)
-	  {
-	    retval = false;
-	    break;
-	  }
+        if (elem (i) != 0)
+          {
+            retval = false;
+            break;
+          }
       }
 
     return retval;
@@ -288,35 +307,33 @@
 
     for (int i = 0; i < length (); i++)
       {
-	if (elem (i) == 0)
-	  {
-	    retval = true;
-	    break;
-	  }
+        if (elem (i) == 0)
+          {
+            retval = true;
+            break;
+          }
       }
 
     return retval;
   }
 
-  int
-  num_ones (void) const
+  int num_ones (void) const
   {
     int retval = 0;
 
     for (int i = 0; i < length (); i++)
       if (elem (i) == 1)
-	retval++;
+        retval++;
 
     return retval;
   }
 
-  bool
-  all_ones (void) const
+  bool all_ones (void) const
   {
     return (num_ones () == length ());
   }
 
-  // This is the number of elements that a matrix with this dimension
+  // Return the number of elements that a matrix with this dimension
   // vector would have, NOT the number of dimensions (elements in the
   // dimension vector).
 
@@ -345,6 +362,7 @@
     octave_idx_type idx_max = std::numeric_limits<octave_idx_type>::max () - 1;
     octave_idx_type n = 1;
     int n_dims = length ();
+
     for (int i = 0; i < n_dims; i++)
       {
         n *= rep[i];
@@ -353,14 +371,19 @@
         if (idx_max <= 0)
           throw std::bad_alloc ();
       }
+
     return n;
   }
 
   bool any_neg (void) const
   {
-    int n_dims = length (), i;
+    int n_dims = length ();
+    int i;
+
     for (i = 0; i < n_dims; i++)
-      if (elem (i) < 0) break;
+      if (elem (i) < 0)
+        break;
+
     return i < n_dims;
   }
 
@@ -374,45 +397,45 @@
 
     for (int i = 0; i < length (); i++)
       {
-	if (elem (i) == 1)
-	  dims_changed = true;
-	else
-	  new_dims(k++) = elem (i);
+        if (elem (i) == 1)
+          dims_changed = true;
+        else
+          new_dims(k++) = elem (i);
       }
 
     if (dims_changed)
       {
-	if (k == 0)
-	  new_dims = dim_vector (1, 1);
-	else if (k == 1)
-	  {
-	    // There is one non-singleton dimension, so we need
-	    // to decide the correct orientation.
+        if (k == 0)
+          new_dims = dim_vector (1, 1);
+        else if (k == 1)
+          {
+            // There is one non-singleton dimension, so we need
+            // to decide the correct orientation.
 
-	    if (elem (0) == 1)
-	      {
-		// The original dimension vector had a leading
-		// singleton dimension.
+            if (elem (0) == 1)
+              {
+                // The original dimension vector had a leading
+                // singleton dimension.
 
-		octave_idx_type tmp = new_dims(0);
-	
-		new_dims.resize (2);
+                octave_idx_type tmp = new_dims(0);
+        
+                new_dims.resize (2);
 
- 		new_dims(0) = 1;
-		new_dims(1) = tmp;
-	      }
-	    else
-	      {
-		// The first element of the original dimension vector
-		// was not a singleton dimension.
+                new_dims(0) = 1;
+                new_dims(1) = tmp;
+              }
+            else
+              {
+                // The first element of the original dimension vector
+                // was not a singleton dimension.
 
-		new_dims.resize (2);
+                new_dims.resize (2);
 
-		new_dims(1) = 1;
-	      }
-	  }
-	else
-	  new_dims.resize(k);
+                new_dims(1) = 1;
+              }
+          }
+        else
+          new_dims.resize(k);
       }
  
     return new_dims;
@@ -422,8 +445,8 @@
   {
     if (all_zero ())
       {
-	*this = dvb;
-	return true;
+        *this = dvb;
+        return true;
       }
 
     if (dvb.all_zero ())
@@ -442,23 +465,23 @@
 
     for (int i = 0; i < n_min; i++)
       {
-	if (elem(i) != dvb(i) && dim != i)
-	    return false;
+        if (elem(i) != dvb(i) && dim != i)
+            return false;
       }
   
     // Ditto.
     for (int i = n_min; i < n_max; i++)
       {
-	if (na > n_min)
-	  {
-	    if (elem(i) != 1 && dim != i)
-	      return false;
-	  }
-	else 
-	  {
-	    if (dvb(i) != 1 && dim != i)
-	      return false;
-	  }
+        if (na > n_min)
+          {
+            if (elem(i) != 1 && dim != i)
+              return false;
+          }
+        else 
+          {
+            if (dvb(i) != 1 && dim != i)
+              return false;
+          }
       }
     
     // If we want to add the dimension vectors at a dimension
@@ -482,13 +505,16 @@
     return true;
   }
 
-  // Forces certain dimensionality, preserving numel (). Missing dimensions are
-  // set to 1, redundant are folded into the trailing one. If n = 1, the result
-  // is 2d and the second dim is 1 (dim_vectors are always at least 2D).
-  // If the original dimensions were all zero, the padding value is zero.
+  // Force certain dimensionality, preserving numel ().  Missing
+  // dimensions are set to 1, redundant are folded into the trailing
+  // one.  If n = 1, the result is 2d and the second dim is 1
+  // (dim_vectors are always at least 2D).  If the original dimensions
+  // were all zero, the padding value is zero.
+
   dim_vector redim (int n) const
     {
       int n_dims = length ();
+
       if (n_dims == n)
         return *this;
       else if (n_dims < n)
@@ -545,7 +571,8 @@
       return def;      
     }
 
-  // Computes a linear index from an index tuple.
+  // Compute a linear index from an index tuple.
+
   octave_idx_type compute_index (const octave_idx_type *idx)
     {
       octave_idx_type k = 0;
@@ -555,9 +582,10 @@
       return k;
     }
 
-  // Increments a multi-dimensional index tuple, optionally starting
-  // from an offset position. Returns the index of the last index
+  // Increment a multi-dimensional index tuple, optionally starting
+  // from an offset position and return the index of the last index
   // position that was changed, or length () if just cycled over.
+
   int increment_index (octave_idx_type *idx, int start = 0)
     {
       int i;
@@ -571,7 +599,8 @@
       return i;
     }
 
-  // Returns cumulative dimensions.
+  // Return cumulative dimensions.
+
   dim_vector cumulative (void) const
     {
       int nd = length ();
@@ -584,8 +613,9 @@
       return retval;
     }
 
-  // Computes a linear index from an index tuple. Assumes that the dimensions
-  // are cumulative.
+  // Compute a linear index from an index tuple.  Dimensions are
+  // required to be cumulative.
+
   octave_idx_type cum_compute_index (const octave_idx_type *idx)
     {
       octave_idx_type k = idx[0];
@@ -617,13 +647,13 @@
   else
     {
       for (int i = 0; i < a_len; i++)
-	{
-	  if (a(i) != b(i))
-	    {
-	      retval = false;
-	      break;
-	    }
-	}
+        {
+          if (a(i) != b(i))
+            {
+              retval = false;
+              break;
+            }
+        }
     }
 
   return retval;
@@ -636,9 +666,3 @@
 }
 
 #endif
-
-/*
-;;; Local Variables: ***
-;;; mode: C++ ***
-;;; End: ***
-*/