changeset 28402:09a3c0e91e6e

style update for Range class * Range.h, Range.cc (class Range): Use m_ prefix for data members.
author John W. Eaton <jwe@octave.org>
date Mon, 01 Jun 2020 14:07:20 -0400
parents 80f873d55bff
children 2aa43d1c8c0d
files liboctave/array/Range.cc liboctave/array/Range.h
diffstat 2 files changed, 120 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/Range.cc	Thu Jun 04 14:25:52 2020 +0200
+++ b/liboctave/array/Range.cc	Mon Jun 01 14:07:20 2020 -0400
@@ -46,9 +46,9 @@
   // be an integer, even if the limit is not.  If there is one or fewer
   // elements only the base needs to be an integer.
 
-  return (! (octave::math::isnan (rng_base) || octave::math::isnan (rng_inc))
-          && (octave::math::nint_big (rng_base) == rng_base || rng_numel < 1)
-          && (octave::math::nint_big (rng_inc) == rng_inc || rng_numel <= 1));
+  return (! (octave::math::isnan (m_base) || octave::math::isnan (m_inc))
+          && (octave::math::nint_big (m_base) == m_base || m_numel < 1)
+          && (octave::math::nint_big (m_inc) == m_inc || m_numel <= 1));
 }
 
 octave_idx_type
@@ -58,27 +58,26 @@
 
   if (! isempty ())
     {
-      if ((rng_base > 0.0 && rng_limit > 0.0)
-          || (rng_base < 0.0 && rng_limit < 0.0))
+      if ((m_base > 0.0 && m_limit > 0.0) || (m_base < 0.0 && m_limit < 0.0))
         {
           // All elements have the same sign, hence there are no zeros.
-          retval = rng_numel;
+          retval = m_numel;
         }
-      else if (rng_inc != 0.0)
+      else if (m_inc != 0.0)
         {
-          if (rng_base == 0.0 || rng_limit == 0.0)
+          if (m_base == 0.0 || m_limit == 0.0)
             // Exactly one zero at beginning or end of range.
-            retval = rng_numel - 1;
-          else if ((rng_base / rng_inc) != std::floor (rng_base / rng_inc))
+            retval = m_numel - 1;
+          else if ((m_base / m_inc) != std::floor (m_base / m_inc))
             // Range crosses negative/positive without hitting zero.
-            retval = rng_numel;
+            retval = m_numel;
           else
             // Range crosses negative/positive and hits zero.
-            retval = rng_numel - 1;
+            retval = m_numel - 1;
         }
       else
         {
-          // All elements are equal (rng_inc = 0) but not positive or negative,
+          // All elements are equal (m_inc = 0) but not positive or negative,
           // therefore all elements are zero.
           retval = 0;
         }
@@ -90,37 +89,37 @@
 Matrix
 Range::matrix_value (void) const
 {
-  if (rng_numel > 0 && cache.isempty ())
+  if (m_numel > 0 && m_cache.isempty ())
     {
-      cache.resize (1, rng_numel);
+      m_cache.resize (1, m_numel);
 
       // The first element must always be *exactly* the base.
       // E.g, -0 would otherwise become +0 in the loop (-0 + 0*increment).
-      cache(0) = rng_base;
+      m_cache(0) = m_base;
 
-      double b = rng_base;
-      double increment = rng_inc;
-      for (octave_idx_type i = 1; i < rng_numel - 1; i++)
-        cache.xelem (i) = b + i * increment;
+      double b = m_base;
+      double increment = m_inc;
+      for (octave_idx_type i = 1; i < m_numel - 1; i++)
+        m_cache.xelem (i) = b + i * increment;
 
-      cache.xelem (rng_numel - 1) = rng_limit;
+      m_cache.xelem (m_numel - 1) = m_limit;
     }
 
-  return cache;
+  return m_cache;
 }
 
 double
 Range::checkelem (octave_idx_type i) const
 {
-  if (i < 0 || i >= rng_numel)
-    octave::err_index_out_of_range (2, 2, i+1, rng_numel, dims ());
+  if (i < 0 || i >= m_numel)
+    octave::err_index_out_of_range (2, 2, i+1, m_numel, dims ());
 
   if (i == 0)
-    return rng_base;
-  else if (i < rng_numel - 1)
-    return rng_base + i * rng_inc;
+    return m_base;
+  else if (i < m_numel - 1)
+    return m_base + i * m_inc;
   else
-    return rng_limit;
+    return m_limit;
 }
 
 double
@@ -128,7 +127,7 @@
 {
   // Ranges are *always* row vectors.
   if (i != 0)
-    octave::err_index_out_of_range (1, 1, i+1, rng_numel, dims ());
+    octave::err_index_out_of_range (1, 1, i+1, m_numel, dims ());
 
   return checkelem (j);
 }
@@ -137,11 +136,11 @@
 Range::elem (octave_idx_type i) const
 {
   if (i == 0)
-    return rng_base;
-  else if (i < rng_numel - 1)
-    return rng_base + i * rng_inc;
+    return m_base;
+  else if (i < m_numel - 1)
+    return m_base + i * m_inc;
   else
-    return rng_limit;
+    return m_limit;
 }
 
 // Helper class used solely for idx_vector.loop () function call
@@ -173,11 +172,11 @@
 {
   Array<double> retval;
 
-  octave_idx_type n = rng_numel;
+  octave_idx_type n = m_numel;
 
   if (i.is_colon ())
     {
-      retval = matrix_value ().reshape (dim_vector (rng_numel, 1));
+      retval = matrix_value ().reshape (dim_vector (m_numel, 1));
     }
   else
     {
@@ -196,7 +195,7 @@
       // idx_vector loop across all values in i,
       // executing __rangeidx_helper (i) for each i
       i.loop (n, __rangeidx_helper (retval.fortran_vec (),
-                                    rng_base, rng_inc, rng_limit, rng_numel));
+                                    m_base, m_inc, m_limit, m_numel));
     }
 
   return retval;
@@ -209,17 +208,17 @@
 Range::min (void) const
 {
   double retval = 0.0;
-  if (rng_numel > 0)
+  if (m_numel > 0)
     {
-      if (rng_inc > 0)
-        retval = rng_base;
+      if (m_inc > 0)
+        retval = m_base;
       else
         {
-          retval = rng_base + (rng_numel - 1) * rng_inc;
+          retval = m_base + (m_numel - 1) * m_inc;
 
           // Require '<=' test.  See note in max ().
-          if (retval <= rng_limit)
-            retval = rng_limit;
+          if (retval <= m_limit)
+            retval = m_limit;
         }
 
     }
@@ -230,24 +229,24 @@
 Range::max (void) const
 {
   double retval = 0.0;
-  if (rng_numel > 0)
+  if (m_numel > 0)
     {
-      if (rng_inc > 0)
+      if (m_inc > 0)
         {
-          retval = rng_base + (rng_numel - 1) * rng_inc;
+          retval = m_base + (m_numel - 1) * m_inc;
 
           // On some machines (x86 with extended precision floating point
           // arithmetic, for example) it is possible that we can overshoot the
           // limit by approximately the machine precision even though we were
           // very careful in our calculation of the number of elements.
           // Therefore, we clip the result to the limit if it overshoots.
-          // The test also includes equality (>= rng_limit) to have expressions
+          // The test also includes equality (>= m_limit) to have expressions
           // such as -5:1:-0 result in a -0 endpoint.
-          if (retval >= rng_limit)
-            retval = rng_limit;
+          if (retval >= m_limit)
+            retval = m_limit;
         }
       else
-        retval = rng_base;
+        retval = m_base;
     }
   return retval;
 }
@@ -255,11 +254,11 @@
 void
 Range::sort_internal (bool ascending)
 {
-  if ((ascending && rng_base > rng_limit && rng_inc < 0.0)
-      || (! ascending && rng_base < rng_limit && rng_inc > 0.0))
+  if ((ascending && m_base > m_limit && m_inc < 0.0)
+      || (! ascending && m_base < m_limit && m_inc > 0.0))
     {
-      std::swap (rng_base, rng_limit);
-      rng_inc = -rng_inc;
+      std::swap (m_base, m_limit);
+      m_inc = -m_inc;
       clear_cache ();
     }
 }
@@ -275,11 +274,11 @@
 
   bool reverse = false;
 
-  if ((ascending && rng_base > rng_limit && rng_inc < 0.0)
-      || (! ascending && rng_base < rng_limit && rng_inc > 0.0))
+  if ((ascending && m_base > m_limit && m_inc < 0.0)
+      || (! ascending && m_base < m_limit && m_inc > 0.0))
     {
-      std::swap (rng_base, rng_limit);
-      rng_inc = -rng_inc;
+      std::swap (m_base, m_limit);
+      m_inc = -m_inc;
       clear_cache ();
       reverse = true;
     }
@@ -337,9 +336,9 @@
 sortmode
 Range::issorted (sortmode mode) const
 {
-  if (rng_numel > 1 && rng_inc > 0)
+  if (m_numel > 1 && m_inc > 0)
     mode = (mode == DESCENDING) ? UNSORTED : ASCENDING;
-  else if (rng_numel > 1 && rng_inc < 0)
+  else if (m_numel > 1 && m_inc < 0)
     mode = (mode == ASCENDING) ? UNSORTED : DESCENDING;
   else
     mode = (mode == UNSORTED) ? ASCENDING : mode;
@@ -350,9 +349,9 @@
 void
 Range::set_base (double b)
 {
-  if (rng_base != b)
+  if (m_base != b)
     {
-      rng_base = b;
+      m_base = b;
 
       init ();
     }
@@ -361,9 +360,9 @@
 void
 Range::set_limit (double l)
 {
-  if (rng_limit != l)
+  if (m_limit != l)
     {
-      rng_limit = l;
+      m_limit = l;
 
       init ();
     }
@@ -372,9 +371,9 @@
 void
 Range::set_inc (double i)
 {
-  if (rng_inc != i)
+  if (m_inc != i)
     {
-      rng_inc = i;
+      m_inc = i;
 
       init ();
     }
@@ -396,7 +395,7 @@
     }
 
   // Print out the last element exactly, rather than a calculated last element.
-  os << a.rng_limit << "\n";
+  os << a.m_limit << "\n";
 
   return os;
 }
@@ -404,17 +403,17 @@
 std::istream&
 operator >> (std::istream& is, Range& a)
 {
-  is >> a.rng_base;
+  is >> a.m_base;
   if (is)
     {
-      double tmp_rng_limit;
-      is >> tmp_rng_limit;
+      double tmp_limit;
+      is >> tmp_limit;
 
       if (is)
-        is >> a.rng_inc;
+        is >> a.m_inc;
 
-      // Clip the rng_limit to the true limit, rebuild numel, clear cache
-      a.set_limit (tmp_rng_limit);
+      // Clip the m_limit to the true limit, rebuild numel, clear cache
+      a.set_limit (tmp_limit);
     }
 
   return is;
@@ -432,8 +431,8 @@
   // Check whether new range was constructed properly.  A non-finite
   // value (Inf or NaN) requires that the output be of the same size
   // as the original range with all values set to the non-finite value.
-  if (result.rng_numel < 0)
-    result.cache = x + r.matrix_value ();
+  if (result.m_numel < 0)
+    result.m_cache = x + r.matrix_value ();
 
   return result;
 }
@@ -441,8 +440,8 @@
 Range operator + (const Range& r, double x)
 {
   Range result (r.base () + x, r.limit () + x, r.inc (), r.numel ());
-  if (result.rng_numel < 0)
-    result.cache = r.matrix_value () + x;
+  if (result.m_numel < 0)
+    result.m_cache = r.matrix_value () + x;
 
   return result;
 }
@@ -450,8 +449,8 @@
 Range operator - (double x, const Range& r)
 {
   Range result (x - r.base (), x - r.limit (), -r.inc (), r.numel ());
-  if (result.rng_numel < 0)
-    result.cache = x - r.matrix_value ();
+  if (result.m_numel < 0)
+    result.m_cache = x - r.matrix_value ();
 
   return result;
 }
@@ -459,8 +458,8 @@
 Range operator - (const Range& r, double x)
 {
   Range result (r.base () - x, r.limit () - x, r.inc (), r.numel ());
-  if (result.rng_numel < 0)
-    result.cache = r.matrix_value () - x;
+  if (result.m_numel < 0)
+    result.m_cache = r.matrix_value () - x;
 
   return result;
 }
@@ -468,8 +467,8 @@
 Range operator * (double x, const Range& r)
 {
   Range result (x * r.base (), x * r.limit (), x * r.inc (), r.numel ());
-  if (result.rng_numel < 0)
-    result.cache = x * r.matrix_value ();
+  if (result.m_numel < 0)
+    result.m_cache = x * r.matrix_value ();
 
   return result;
 }
@@ -477,8 +476,8 @@
 Range operator * (const Range& r, double x)
 {
   Range result (r.base () * x, r.limit () * x, r.inc () * x, r.numel ());
-  if (result.rng_numel < 0)
-    result.cache = r.matrix_value () * x;
+  if (result.m_numel < 0)
+    result.m_cache = r.matrix_value () * x;
 
   return result;
 }
@@ -560,9 +559,9 @@
 {
   octave_idx_type retval = -1;
 
-  if (rng_inc == 0
-      || (rng_limit > rng_base && rng_inc < 0)
-      || (rng_limit < rng_base && rng_inc > 0))
+  if (m_inc == 0
+      || (m_limit > m_base && m_inc < 0)
+      || (m_limit < m_base && m_inc > 0))
     {
       retval = 0;
     }
@@ -570,7 +569,7 @@
     {
       double ct = 3.0 * std::numeric_limits<double>::epsilon ();
 
-      double tmp = tfloor ((rng_limit - rng_base + rng_inc) / rng_inc, ct);
+      double tmp = tfloor ((m_limit - m_base + m_inc) / m_inc, ct);
 
       octave_idx_type n_elt = (tmp > 0.0 ? static_cast<octave_idx_type> (tmp)
                                          : 0);
@@ -584,11 +583,11 @@
       // using tfloor as above.  For example, without it, the expression
       // 1.8:0.05:1.9 fails to produce the expected result of [1.8, 1.85, 1.9].
 
-      if (! teq (rng_base + (n_elt - 1) * rng_inc, rng_limit))
+      if (! teq (m_base + (n_elt - 1) * m_inc, m_limit))
         {
-          if (teq (rng_base + (n_elt - 2) * rng_inc, rng_limit))
+          if (teq (m_base + (n_elt - 2) * m_inc, m_limit))
             n_elt--;
-          else if (teq (rng_base + n_elt * rng_inc, rng_limit))
+          else if (teq (m_base + n_elt * m_inc, m_limit))
             n_elt++;
         }
 
@@ -604,7 +603,7 @@
 {
   double new_limit;
 
-  if (rng_inc > 0)
+  if (m_inc > 0)
     new_limit = max ();
   else
     new_limit = min ();
@@ -619,8 +618,8 @@
 void
 Range::init (void)
 {
-  rng_numel = numel_internal ();
-  rng_limit = limit_internal ();
+  m_numel = numel_internal ();
+  m_limit = limit_internal ();
 
   clear_cache ();
 }
--- a/liboctave/array/Range.h	Thu Jun 04 14:25:52 2020 +0200
+++ b/liboctave/array/Range.h	Mon Jun 01 14:07:20 2020 -0400
@@ -41,7 +41,8 @@
 public:
 
   Range (void)
-    : rng_base (0), rng_limit (0), rng_inc (0), rng_numel (0), cache (1, 0) { }
+    : m_base (0), m_limit (0), m_inc (0), m_numel (0), m_cache (1, 0)
+  { }
 
   Range (const Range& r) = default;
 
@@ -50,43 +51,43 @@
   ~Range (void) = default;
 
   Range (double b, double l)
-    : rng_base (b), rng_limit (l), rng_inc (1),
-      rng_numel (numel_internal ()), cache ()
+    : m_base (b), m_limit (l), m_inc (1), m_numel (numel_internal ()),
+      m_cache ()
   {
-    rng_limit = limit_internal ();
+    m_limit = limit_internal ();
   }
 
   Range (double b, double l, double i)
-    : rng_base (b), rng_limit (l), rng_inc (i),
-      rng_numel (numel_internal ()), cache ()
+    : m_base (b), m_limit (l), m_inc (i), m_numel (numel_internal ()),
+      m_cache ()
   {
-    rng_limit = limit_internal ();
+    m_limit = limit_internal ();
   }
 
   // For operators' usage (to preserve element count).
   Range (double b, double i, octave_idx_type n)
-    : rng_base (b), rng_limit (b + (n-1) * i), rng_inc (i),
-      rng_numel (n), cache ()
+    : m_base (b), m_limit (b + (n-1) * i), m_inc (i),
+      m_numel (n), m_cache ()
   {
     if (! octave::math::isfinite (b) || ! octave::math::isfinite (i)
-        || ! octave::math::isfinite (rng_limit))
-      rng_numel = -2;
+        || ! octave::math::isfinite (m_limit))
+      m_numel = -2;
     else
       {
         // Code below is only needed if the resulting range must be 100%
         // correctly constructed.  If the Range object created is only
         // a temporary one used by operators this may be unnecessary.
-        rng_limit = limit_internal ();
+        m_limit = limit_internal ();
       }
   }
 
-  double base (void) const { return rng_base; }
-  double limit (void) const { return rng_limit; }
-  double inc (void) const { return rng_inc; }
+  double base (void) const { return m_base; }
+  double limit (void) const { return m_limit; }
+  double inc (void) const { return m_inc; }
 
-  octave_idx_type numel (void) const { return rng_numel; }
+  octave_idx_type numel (void) const { return m_numel; }
 
-  dim_vector dims (void) const { return dim_vector (1, rng_numel); }
+  dim_vector dims (void) const { return dim_vector (1, m_numel); }
 
   octave_idx_type rows (void) const { return 1; }
 
@@ -150,13 +151,13 @@
 
 private:
 
-  double rng_base;
-  double rng_limit;
-  double rng_inc;
+  double m_base;
+  double m_limit;
+  double m_inc;
 
-  octave_idx_type rng_numel;
+  octave_idx_type m_numel;
 
-  mutable Matrix cache;
+  mutable Matrix m_cache;
 
   octave_idx_type numel_internal (void) const;
 
@@ -164,18 +165,18 @@
 
   void init (void);
 
-  void clear_cache (void) const { cache.resize (0, 0); }
+  void clear_cache (void) const { m_cache.resize (0, 0); }
 
 protected:
 
   // For operators' usage (to allow all values to be set directly).
   Range (double b, double l, double i, octave_idx_type n)
-    : rng_base (b), rng_limit (l), rng_inc (i),
-      rng_numel (n), cache ()
+    : m_base (b), m_limit (l), m_inc (i),
+      m_numel (n), m_cache ()
   {
     if (! octave::math::isfinite (b) || ! octave::math::isfinite (i)
         || ! octave::math::isfinite (l))
-      rng_numel = -2;
+      m_numel = -2;
   }
 };