changeset 29937:da7210e30f3e

move some utility functions inside octave namespace * lo-utils.h, lo-utils.cc (is_one_or_zero): Rename from xis_one_or_zero and move inside octave namespace. Change all uses. (is_zero): Rename from xis_zero and move inside octave namespace. Change all uses. (is_int_or_inf_or_nan): Rename from xis_int_or_inf_or_nan and move inside octave namespace. Change all uses. (too_large_for_float): Rename from xtoo_large_for_float and move inside octave namespace. Change all uses. (too_large_for_float): Rename from xtoo_large_for_float and move inside octave namespace. Change all uses. (is_int_or_inf_or_nan): Rename from xis_int_or_inf_or_nan and move inside octave namespace. Change all uses. (fgets): Rename from octave_fgets and move inside octave namespace. Change all uses. (fgetl): Rename from octave_fgetl and move inside octave namespace. Change all uses. (any_all_test, strsave): Move inside octave namespace. Tag uses with octave:: prefix as needed. * lo-utils.h: Provide deprecated templates and inline functions to preserve old names in global namespace.
author John W. Eaton <jwe@octave.org>
date Tue, 03 Aug 2021 12:34:52 -0400
parents 79c6a29dd384
children 4b25d83d152d
files libinterp/corefcn/input.cc libinterp/corefcn/load-path.cc libinterp/octave-value/ov-range.cc liboctave/array/Array.h liboctave/array/CNDArray.cc liboctave/array/CSparse.cc liboctave/array/Sparse.h liboctave/array/dNDArray.cc liboctave/array/dSparse.cc liboctave/array/fNDArray.cc liboctave/util/cmd-edit.cc liboctave/util/lo-utils.cc liboctave/util/lo-utils.h liboctave/util/str-vec.cc
diffstat 14 files changed, 289 insertions(+), 208 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/input.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/libinterp/corefcn/input.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -1045,7 +1045,7 @@
 
     eof = false;
 
-    std::string src_str = octave_fgets (m_file, eof);
+    std::string src_str = fgets (m_file, eof);
 
     std::string mfile_encoding;
 
--- a/libinterp/corefcn/load-path.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/libinterp/corefcn/load-path.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -1166,7 +1166,7 @@
     const std::string enc_prop = "encoding";
     while (! eof)
       {
-        std::string conf_str = octave_fgets (cfile, eof);
+        std::string conf_str = fgets (cfile, eof);
 
         // delete any preceeding whitespace
         auto it = std::find_if_not (conf_str.begin (), conf_str.end (),
--- a/libinterp/octave-value/ov-range.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/libinterp/octave-value/ov-range.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -376,7 +376,7 @@
 {
   Array<T> matrix = raw_array_value ();
 
-  if (warn && ! matrix.test_all (xis_one_or_zero<T>))
+  if (warn && ! matrix.test_all (octave::is_one_or_zero<T>))
     warn_logical_conversion ();
 
   return boolNDArray (matrix);
--- a/liboctave/array/Array.h	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/array/Array.h	Tue Aug 03 12:34:52 2021 -0400
@@ -805,7 +805,7 @@
   template <typename F, bool zero>
   bool test (F fcn) const
   {
-    return any_all_test<F, T, zero> (fcn, data (), numel ());
+    return octave::any_all_test<F, T, zero> (fcn, data (), numel ());
   }
 
   //@{
--- a/liboctave/array/CNDArray.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/array/CNDArray.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -339,7 +339,7 @@
 bool
 ComplexNDArray::too_large_for_float (void) const
 {
-  return test_any (xtoo_large_for_float);
+  return test_any (octave::too_large_for_float);
 }
 
 boolNDArray
--- a/liboctave/array/CSparse.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/array/CSparse.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -7352,7 +7352,7 @@
 bool
 SparseComplexMatrix::too_large_for_float (void) const
 {
-  return test_any (xtoo_large_for_float);
+  return test_any (octave::too_large_for_float);
 }
 
 // FIXME: Do these really belong here?  Maybe they should be in a base class?
--- a/liboctave/array/Sparse.h	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/array/Sparse.h	Tue Aug 03 12:34:52 2021 -0400
@@ -590,7 +590,7 @@
   template <typename F, bool zero>
   bool test (F fcn) const
   {
-    return any_all_test<F, T, zero> (fcn, data (), nnz ());
+    return octave::any_all_test<F, T, zero> (fcn, data (), nnz ());
   }
 
   // Simpler calls.
--- a/liboctave/array/dNDArray.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/array/dNDArray.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -329,19 +329,19 @@
 bool
 NDArray::any_element_not_one_or_zero (void) const
 {
-  return ! test_all (xis_one_or_zero);
+  return ! test_all (octave::is_one_or_zero);
 }
 
 bool
 NDArray::all_elements_are_zero (void) const
 {
-  return test_all (xis_zero);
+  return test_all (octave::is_zero);
 }
 
 bool
 NDArray::all_elements_are_int_or_inf_or_nan (void) const
 {
-  return test_all (xis_int_or_inf_or_nan);
+  return test_all (octave::is_int_or_inf_or_nan);
 }
 
 // Return nonzero if any element of M is not an integer.  Also extract
@@ -386,7 +386,7 @@
 bool
 NDArray::too_large_for_float (void) const
 {
-  return test_any (xtoo_large_for_float);
+  return test_any (octave::too_large_for_float);
 }
 
 // FIXME: this is not quite the right thing.
--- a/liboctave/array/dSparse.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/array/dSparse.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -7323,7 +7323,7 @@
 bool
 SparseMatrix::too_large_for_float (void) const
 {
-  return test_any (xtoo_large_for_float);
+  return test_any (octave::too_large_for_float);
 }
 
 SparseBoolMatrix
--- a/liboctave/array/fNDArray.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/array/fNDArray.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -286,19 +286,19 @@
 bool
 FloatNDArray::any_element_not_one_or_zero (void) const
 {
-  return ! test_all (xis_one_or_zero);
+  return ! test_all (octave::is_one_or_zero);
 }
 
 bool
 FloatNDArray::all_elements_are_zero (void) const
 {
-  return test_all (xis_zero);
+  return test_all (octave::is_zero);
 }
 
 bool
 FloatNDArray::all_elements_are_int_or_inf_or_nan (void) const
 {
-  return test_all (xis_int_or_inf_or_nan);
+  return test_all (octave::is_int_or_inf_or_nan);
 }
 
 // Return nonzero if any element of M is not an integer.  Also extract
--- a/liboctave/util/cmd-edit.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/util/cmd-edit.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -976,7 +976,7 @@
     std::fputs (prompt.c_str (), output_stream);
     std::fflush (output_stream);
 
-    return octave_fgetl (input_stream, eof);
+    return fgetl (input_stream, eof);
   }
 
   void
--- a/liboctave/util/lo-utils.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/util/lo-utils.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -45,140 +45,139 @@
 #include "lo-utils.h"
 #include "oct-inttypes.h"
 
-bool xis_int_or_inf_or_nan (double x)
-{ return octave::math::isnan (x) || octave::math::x_nint (x) == x; }
-
-bool xtoo_large_for_float (double x)
-{
-  return (octave::math::isfinite (x)
-          && fabs (x) > std::numeric_limits<float>::max ());
-}
-
-bool xtoo_large_for_float (const Complex& x)
-{
-  return (xtoo_large_for_float (x.real ())
-          || xtoo_large_for_float (x.imag ()));
-}
-
-bool xis_int_or_inf_or_nan (float x)
-{ return octave::math::isnan (x) || octave::math::x_nint (x) == x; }
-
-// Save a string.
-
-char *
-strsave (const char *s)
-{
-  if (! s)
-    return nullptr;
-
-  int len = strlen (s);
-  char *tmp = new char [len+1];
-  tmp = strcpy (tmp, s);
-  return tmp;
-}
-
-std::string
-octave_fgets (FILE *f)
-{
-  bool eof;
-  return octave_fgets (f, eof);
-}
-
-std::string
-octave_fgets (FILE *f, bool& eof)
-{
-  eof = false;
-
-  std::string retval;
-
-  int grow_size = 1024;
-  int max_size = grow_size;
-
-  char *buf = static_cast<char *> (std::malloc (max_size));
-  if (! buf)
-    (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size);
-
-  char *bufptr = buf;
-  int len = 0;
-
-  do
-    {
-      if (std::fgets (bufptr, grow_size, f))
-        {
-          len = strlen (bufptr);
-
-          if (len == grow_size - 1)
-            {
-              int tmp = bufptr - buf + grow_size - 1;
-              grow_size *= 2;
-              max_size += grow_size;
-              auto tmpbuf = static_cast<char *> (std::realloc (buf, max_size));
-              if (! tmpbuf)
-                {
-                  free (buf);
-                  (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size);
-                }
-              buf = tmpbuf;
-              bufptr = buf + tmp;
-
-              if (*(bufptr-1) == '\n')
-                {
-                  *bufptr = '\0';
-                  retval = buf;
-                }
-            }
-          else if (bufptr[len-1] != '\n')
-            {
-              bufptr[len++] = '\n';
-              bufptr[len] = '\0';
-              retval = buf;
-            }
-          else
-            retval = buf;
-        }
-      else
-        {
-          if (len == 0)
-            {
-              eof = true;
-
-              free (buf);
-
-              buf = nullptr;
-            }
-
-          break;
-        }
-    }
-  while (retval.empty ());
-
-  free (buf);
-
-  octave_quit ();
-
-  return retval;
-}
-
-std::string
-octave_fgetl (FILE *f)
-{
-  bool eof;
-  return octave_fgetl (f, eof);
-}
-
-std::string
-octave_fgetl (FILE *f, bool& eof)
-{
-  std::string retval = octave_fgets (f, eof);
-
-  if (! retval.empty () && retval.back () == '\n')
-    retval.pop_back ();
-
-  return retval;
-}
-
 namespace octave
 {
+  bool is_int_or_inf_or_nan (double x)
+  {
+    return math::isnan (x) || math::x_nint (x) == x;
+  }
+
+  bool too_large_for_float (double x)
+  {
+    return (math::isfinite (x)
+            && fabs (x) > std::numeric_limits<float>::max ());
+  }
+
+  bool too_large_for_float (const Complex& x)
+  {
+    return (too_large_for_float (x.real ())
+            || too_large_for_float (x.imag ()));
+  }
+
+  bool is_int_or_inf_or_nan (float x)
+  {
+    return math::isnan (x) || math::x_nint (x) == x;
+  }
+
+  // Save a string.
+
+  char * strsave (const char *s)
+  {
+    if (! s)
+      return nullptr;
+
+    int len = strlen (s);
+    char *tmp = new char [len+1];
+    tmp = strcpy (tmp, s);
+    return tmp;
+  }
+
+  std::string fgets (FILE *f)
+  {
+    bool eof;
+    return fgets (f, eof);
+  }
+
+  std::string fgets (FILE *f, bool& eof)
+  {
+    eof = false;
+
+    std::string retval;
+
+    int grow_size = 1024;
+    int max_size = grow_size;
+
+    char *buf = static_cast<char *> (std::malloc (max_size));
+    if (! buf)
+      (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size);
+
+    char *bufptr = buf;
+    int len = 0;
+
+    do
+      {
+        if (std::fgets (bufptr, grow_size, f))
+          {
+            len = strlen (bufptr);
+
+            if (len == grow_size - 1)
+              {
+                int tmp = bufptr - buf + grow_size - 1;
+                grow_size *= 2;
+                max_size += grow_size;
+                auto tmpbuf = static_cast<char *> (std::realloc (buf, max_size));
+                if (! tmpbuf)
+                  {
+                    free (buf);
+                    (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size);
+                  }
+                buf = tmpbuf;
+                bufptr = buf + tmp;
+
+                if (*(bufptr-1) == '\n')
+                  {
+                    *bufptr = '\0';
+                    retval = buf;
+                  }
+              }
+            else if (bufptr[len-1] != '\n')
+              {
+                bufptr[len++] = '\n';
+                bufptr[len] = '\0';
+                retval = buf;
+              }
+            else
+              retval = buf;
+          }
+        else
+          {
+            if (len == 0)
+              {
+                eof = true;
+
+                free (buf);
+
+                buf = nullptr;
+              }
+
+            break;
+          }
+      }
+    while (retval.empty ());
+
+    free (buf);
+
+    octave_quit ();
+
+    return retval;
+  }
+
+  std::string fgetl (FILE *f)
+  {
+    bool eof;
+    return fgetl (f, eof);
+  }
+
+  std::string fgetl (FILE *f, bool& eof)
+  {
+    std::string retval = fgets (f, eof);
+
+    if (! retval.empty () && retval.back () == '\n')
+      retval.pop_back ();
+
+    return retval;
+  }
+
   template <typename T>
   T
   read_value (std::istream& is)
--- a/liboctave/util/lo-utils.h	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/util/lo-utils.h	Tue Aug 03 12:34:52 2021 -0400
@@ -37,67 +37,65 @@
 #include "oct-cmplx.h"
 #include "quit.h"
 
-// Generic any/all test functionality with arbitrary predicate.
-
-template <typename F, typename T, bool zero>
-bool
-any_all_test (F fcn, const T *m, octave_idx_type len)
-{
-  octave_idx_type i;
-
-  for (i = 0; i < len - 3; i += 4)
-    {
-      octave_quit ();
-
-      if (fcn (m[i]) != zero
-          || fcn (m[i+1]) != zero
-          || fcn (m[i+2]) != zero
-          || fcn (m[i+3]) != zero)
-        return ! zero;
-    }
-
-  octave_quit ();
-
-  for (; i < len; i++)
-    if (fcn (m[i]) != zero)
-      return ! zero;
-
-  return zero;
-}
-
-extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
-
-template <typename T>
-bool
-xis_one_or_zero (const T& x)
-{
-  return x == T (0) || x == T (1);
-}
-
-template <typename T>
-bool
-xis_zero (const T& x)
-{
-  return x == T (0);
-}
-
-extern OCTAVE_API bool xtoo_large_for_float (double x);
-
-extern OCTAVE_API bool xtoo_large_for_float (const Complex&  x);
-
-extern OCTAVE_API bool xis_int_or_inf_or_nan (float x);
-extern OCTAVE_API bool xtoo_large_for_float (float x);
-
-extern OCTAVE_API char * strsave (const char *);
-
-extern OCTAVE_API std::string octave_fgets (std::FILE *);
-extern OCTAVE_API std::string octave_fgetl (std::FILE *);
-
-extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof);
-extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof);
-
 namespace octave
 {
+  // Generic any/all test functionality with arbitrary predicate.
+
+  template <typename F, typename T, bool zero>
+  bool
+  any_all_test (F fcn, const T *m, octave_idx_type len)
+  {
+    octave_idx_type i;
+
+    for (i = 0; i < len - 3; i += 4)
+      {
+        octave_quit ();
+
+        if (fcn (m[i]) != zero
+            || fcn (m[i+1]) != zero
+            || fcn (m[i+2]) != zero
+            || fcn (m[i+3]) != zero)
+          return ! zero;
+      }
+
+    octave_quit ();
+
+    for (; i < len; i++)
+      if (fcn (m[i]) != zero)
+        return ! zero;
+
+    return zero;
+  }
+
+  extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
+
+  template <typename T>
+  bool is_one_or_zero (const T& x)
+  {
+    return x == T (0) || x == T (1);
+  }
+
+  template <typename T>
+  bool is_zero (const T& x)
+  {
+    return x == T (0);
+  }
+
+  extern OCTAVE_API bool too_large_for_float (double x);
+
+  extern OCTAVE_API bool too_large_for_float (const Complex&  x);
+
+  extern OCTAVE_API bool is_int_or_inf_or_nan (float x);
+  extern OCTAVE_API bool too_large_for_float (float x);
+
+  extern OCTAVE_API char * strsave (const char *);
+
+  extern OCTAVE_API std::string fgets (std::FILE *);
+  extern OCTAVE_API std::string fgetl (std::FILE *);
+
+  extern OCTAVE_API std::string fgets (std::FILE *, bool& eof);
+  extern OCTAVE_API std::string fgetl (std::FILE *, bool& eof);
+
   template <typename T> OCTAVE_API T read_value (std::istream& is);
 
   template <> OCTAVE_API double read_value (std::istream& is);
@@ -139,6 +137,90 @@
   }
 }
 
+template <typename F, typename T, bool zero>
+OCTAVE_DEPRECATED (7, "use 'octave::any_all_test' instead")
+bool
+any_all_test (F fcn, const T *m, octave_idx_type len)
+{
+  return octave::any_all_test<F, T, zero> (fcn, m, len);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::is_int_or_inf_or_nan' instead")
+inline bool xis_int_or_inf_or_nan (double x)
+{
+  return octave::is_int_or_inf_or_nan (x);
+}
+
+template <typename T>
+OCTAVE_DEPRECATED (7, "use 'octave::is_one_or_zero' instead")
+bool
+xis_one_or_zero (const T& x)
+{
+  return octave::is_one_or_zero (x);
+}
+
+template <typename T>
+OCTAVE_DEPRECATED (7, "use 'octave::is_zero' instead")
+bool
+xis_zero (const T& x)
+{
+  return octave::is_zero (x);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::' instead")
+inline bool xtoo_large_for_float (double x)
+{
+  return octave::too_large_for_float (x);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::' instead")
+inline bool xtoo_large_for_float (const Complex&  x)
+{
+  return octave::too_large_for_float (x);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::' instead")
+inline bool xis_int_or_inf_or_nan (float x)
+{
+  return octave::is_int_or_inf_or_nan (x);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::' instead")
+inline bool xtoo_large_for_float (float x)
+{
+  return octave::too_large_for_float (x);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::strsave' instead")
+inline char * strsave (const char *s)
+{
+  return octave::strsave (s);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead")
+inline std::string octave_fgets (std::FILE *f)
+{
+  return octave::fgets (f);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead")
+inline std::string octave_fgetl (std::FILE *f)
+{
+  return octave::fgetl (f);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead")
+inline std::string octave_fgets (std::FILE *f, bool& eof)
+{
+  return octave::fgets (f, eof);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead")
+inline std::string octave_fgetl (std::FILE *f, bool& eof)
+{
+  return octave::fgetl (f, eof);
+}
+
 OCTAVE_DEPRECATED (7, "use 'octave::read_value<T>' instead")
 inline double
 octave_read_double (std::istream& is)
--- a/liboctave/util/str-vec.cc	Thu Mar 17 10:50:22 2016 +0530
+++ b/liboctave/util/str-vec.cc	Tue Aug 03 12:34:52 2021 -0400
@@ -163,7 +163,7 @@
   retval[len] = nullptr;
 
   for (octave_idx_type i = 0; i < len; i++)
-    retval[i] = strsave (elem (i).c_str ());
+    retval[i] = octave::strsave (elem (i).c_str ());
 
   return retval;
 }