changeset 23748:6e86d3b5a063

move base64 encode and decode functions inside octave namespace * oct-base64.h, oct-base64.cc (base64_encode, base64_decode): Move functions inside octave namespace and rename from octave_base64_encode and octave_base64_decode. Change all uses.
author John W. Eaton <jwe@octave.org>
date Fri, 07 Jul 2017 18:06:34 -0400
parents 0b4d1575a2e2
children 6921d8458203
files libinterp/corefcn/data.cc liboctave/util/oct-base64.cc liboctave/util/oct-base64.h
diffstat 3 files changed, 88 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/data.cc	Fri Jul 07 15:42:57 2017 -0400
+++ b/libinterp/corefcn/data.cc	Fri Jul 07 18:06:34 2017 -0400
@@ -7767,7 +7767,7 @@
           size_t inlen = in.numel () * sizeof (X## _t) / sizeof (char);  \
           const char *inc = reinterpret_cast<const char *> (in.data ()); \
           char *out;                                                     \
-          if (octave_base64_encode (inc, inlen, &out))                   \
+          if (octave::base64_encode (inc, inlen, &out))                  \
             {                                                            \
               retval(0) = octave_value (out);                            \
               ::free (out);                                              \
@@ -7796,7 +7796,7 @@
       const char*  inc;
       inc = reinterpret_cast<const char *> (in.data ());
       char *out;
-      if (octave_base64_encode (inc, inlen, &out))
+      if (octave::base64_encode (inc, inlen, &out))
         {
           retval(0) = octave_value (out);
           ::free (out);
@@ -7810,7 +7810,7 @@
       const char*  inc;
       inc = reinterpret_cast<const char *> (in.data ());
       char *out;
-      if (octave_base64_encode (inc, inlen, &out))
+      if (octave::base64_encode (inc, inlen, &out))
         {
           retval(0) = octave_value (out);
           ::free (out);
@@ -7862,7 +7862,7 @@
 
   std::string str = args(0).string_value ();
 
-  Array<double> retval = octave_base64_decode (str);
+  Array<double> retval = octave::base64_decode (str);
 
   if (nargin == 2)
     {
--- a/liboctave/util/oct-base64.cc	Fri Jul 07 15:42:57 2017 -0400
+++ b/liboctave/util/oct-base64.cc	Fri Jul 07 18:06:34 2017 -0400
@@ -30,60 +30,79 @@
 #include "base64-wrappers.h"
 #include "oct-base64.h"
 
+namespace octave
+{
+  bool
+  base64_encode (const char *inc, const size_t inlen, char **out)
+  {
+    bool ret = false;
+
+    size_t outlen = octave_base64_encode_alloc_wrapper (inc, inlen, out);
+
+    if (! out)
+      {
+        if (outlen == 0 && inlen != 0)
+          (*current_liboctave_error_handler)
+            ("base64_encode: input array too large");
+        else
+          (*current_liboctave_error_handler)
+            ("base64_encode: memory allocation error");
+      }
+    else
+      ret = true;
+
+    return ret;
+  }
+
+  Array<double>
+  base64_decode (const std::string& str)
+  {
+    Array<double> retval;
+
+    char *out;
+    size_t outlen;
+
+    bool ok = octave_base64_decode_alloc_wrapper (str.data (), str.length (),
+                                                  &out, &outlen);
+
+    if (! ok)
+      (*current_liboctave_error_handler)
+        ("base64_decode: input was not valid base64");
+    if (! out)
+      (*current_liboctave_error_handler)
+        ("base64_decode: memory allocation error");
+
+    if ((outlen % (sizeof (double) / sizeof (char))) != 0)
+      {
+        ::free (out);
+        (*current_liboctave_error_handler)
+          ("base64_decode: incorrect input size");
+      }
+    else
+      {
+        octave_idx_type len = (outlen * sizeof (char)) / sizeof (double);
+        retval.resize (dim_vector (1, len));
+        double *dout = reinterpret_cast<double *> (out);
+        std::copy (dout, dout + len, retval.fortran_vec ());
+        ::free (out);
+      }
+
+    return retval;
+  }
+}
+
+#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
+
 bool
 octave_base64_encode (const char *inc, const size_t inlen, char **out)
 {
-  bool ret = false;
-
-  size_t outlen = octave_base64_encode_alloc_wrapper (inc, inlen, out);
-
-  if (! out)
-    {
-      if (outlen == 0 && inlen != 0)
-        (*current_liboctave_error_handler)
-          ("base64_encode: input array too large");
-      else
-        (*current_liboctave_error_handler)
-          ("base64_encode: memory allocation error");
-    }
-  else
-    ret = true;
-
-  return ret;
+  return octave::base64_encode (inc, inlen, out);
 }
 
 Array<double>
 octave_base64_decode (const std::string& str)
 {
-  Array<double> retval;
-
-  char *out;
-  size_t outlen;
-
-  bool ok = octave_base64_decode_alloc_wrapper (str.data (), str.length (),
-                                                &out, &outlen);
-
-  if (! ok)
-    (*current_liboctave_error_handler)
-      ("base64_decode: input was not valid base64");
-  if (! out)
-    (*current_liboctave_error_handler)
-      ("base64_decode: memory allocation error");
+  return octave::base64_decode (str);
+}
 
-  if ((outlen % (sizeof (double) / sizeof (char))) != 0)
-    {
-      ::free (out);
-      (*current_liboctave_error_handler)
-        ("base64_decode: incorrect input size");
-    }
-  else
-    {
-      octave_idx_type len = (outlen * sizeof (char)) / sizeof (double);
-      retval.resize (dim_vector (1, len));
-      double *dout = reinterpret_cast<double *> (out);
-      std::copy (dout, dout + len, retval.fortran_vec ());
-      ::free (out);
-    }
-
-  return retval;
-}
+#endif
--- a/liboctave/util/oct-base64.h	Fri Jul 07 15:42:57 2017 -0400
+++ b/liboctave/util/oct-base64.h	Fri Jul 07 18:06:34 2017 -0400
@@ -29,10 +29,25 @@
 
 template <typename T> class Array;
 
-extern OCTAVE_API bool
+namespace octave
+{
+  extern OCTAVE_API bool
+  base64_encode (const char *inc, const size_t inlen, char **out);
+
+  extern OCTAVE_API Array<double>
+  base64_decode (const std::string& str);
+}
+
+#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
+
+OCTAVE_DEPRECATED (4.4, "use 'octave::base_64_encode' instead")
+extern bool
 octave_base64_encode (const char *inc, const size_t inlen, char **out);
 
-extern OCTAVE_API Array<double>
+OCTAVE_DEPRECATED (4.4, "use 'octave::base_64_decode' instead")
+extern Array<double>
 octave_base64_decode (const std::string& str);
 
 #endif
+
+#endif