diff libinterp/octave-value/ov-usr-fcn.cc @ 20939:b17fda023ca6

maint: Use new C++ archetype in more files. Place input validation first in files. Move declaration of retval down in function to be closer to point of usage. Eliminate else clause after if () error. Use "return ovl()" where it makes sense. * find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, graphics.cc, help.cc, hess.cc, hex2num.cc, input.cc, kron.cc, load-path.cc, load-save.cc, lookup.cc, mappers.cc, matrix_type.cc, mgorth.cc, nproc.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, profiler.cc, psi.cc, quad.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __eigs__.cc, __glpk__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, chol.cc, colamd.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc, ov-java.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-usr-fcn.cc, ov.cc, octave.cc: Use new C++ archetype in more files.
author Rik <rik@octave.org>
date Fri, 18 Dec 2015 15:37:22 -0800
parents 4d3daf7e43f3
children 48b2ad5ee801
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.cc	Fri Dec 18 16:22:53 2015 -0500
+++ b/libinterp/octave-value/ov-usr-fcn.cc	Fri Dec 18 15:37:22 2015 -0800
@@ -818,13 +818,13 @@
 @seealso{nargout, narginchk, varargin, inputname}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   int nargin = args.length ();
 
   if (nargin > 1)
     print_usage ();
 
+  octave_value retval;
+
   if (nargin == 1)
     {
       octave_value func = args(0);
@@ -838,27 +838,25 @@
         }
 
       octave_function *fcn_val = func.function_value ();
-      if (fcn_val)
-        {
-          octave_user_function *fcn = fcn_val->user_function_value (true);
+      if (! fcn_val)
+        error ("nargin: FCN must be a string or function handle");
 
-          if (fcn)
-            {
-              tree_parameter_list *param_list = fcn->parameter_list ();
+      octave_user_function *fcn = fcn_val->user_function_value (true);
 
-              retval = param_list ? param_list->length () : 0;
-              if (fcn->takes_varargs ())
-                retval = -1 - retval;
-            }
-          else
-            {
-              // Matlab gives up for histc,
-              // so maybe it's ok that that we give up somtimes too?
-              error ("nargin: nargin information not available for built-in functions");
-            }
+      if (fcn)
+        {
+          tree_parameter_list *param_list = fcn->parameter_list ();
+
+          retval = param_list ? param_list->length () : 0;
+          if (fcn->takes_varargs ())
+            retval = -1 - retval;
         }
       else
-        error ("nargin: FCN must be a string or function handle");
+        {
+          // Matlab gives up for histc,
+          // so maybe it's ok that that we give up somtimes too?
+          error ("nargin: nargin information not available for built-in functions");
+        }
     }
   else
     {
@@ -926,13 +924,13 @@
 @seealso{nargin, varargout, isargout, nthargout}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   int nargin = args.length ();
 
   if (nargin > 1)
     print_usage ();
 
+  octave_value retval;
+
   if (nargin == 1)
     {
       octave_value func = args(0);
@@ -946,10 +944,7 @@
         }
 
       if (func.is_inline_function ())
-        {
-          retval = 1;
-          return retval;
-        }
+        return ovl (1);
 
       if (func.is_function_handle ())
         {
@@ -957,37 +952,32 @@
           std::string fh_nm = fh->fcn_name ();
 
           if (fh_nm == octave_fcn_handle::anonymous)
-            {
-              retval = -1;
-              return retval;
-            }
+            return ovl (-1);
         }
 
       octave_function *fcn_val = func.function_value ();
-      if (fcn_val)
-        {
-          octave_user_function *fcn = fcn_val->user_function_value (true);
+      if (! fcn_val)
+        error ("nargout: FCN must be a string or function handle");
 
-          if (fcn)
-            {
-              tree_parameter_list *ret_list = fcn->return_list ();
-
-              retval = ret_list ? ret_list->length () : 0;
+      octave_user_function *fcn = fcn_val->user_function_value (true);
 
-              if (fcn->takes_var_return ())
-                retval = -1 - retval;
-            }
-          else
-            {
-              // JWE said this information is not available (2011-03-10)
-              // without making intrusive changes to Octave.
-              // Matlab gives up for histc,
-              // so maybe it's ok that we give up somtimes too?
-              error ("nargout: nargout information not available for built-in functions.");
-            }
+      if (fcn)
+        {
+          tree_parameter_list *ret_list = fcn->return_list ();
+
+          retval = ret_list ? ret_list->length () : 0;
+
+          if (fcn->takes_var_return ())
+            retval = -1 - retval;
         }
       else
-        error ("nargout: FCN must be a string or function handle");
+        {
+          // JWE said this information is not available (2011-03-10)
+          // without making intrusive changes to Octave.
+          // Matlab gives up for histc,
+          // so maybe it's ok that we give up somtimes too?
+          error ("nargout: nargout information not available for built-in functions.");
+        }
     }
   else
     {
@@ -1058,43 +1048,39 @@
 @seealso{nargout, varargout, nthargout}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   if (args.length () != 1)
     print_usage ();
 
-  if (! symbol_table::at_top_level ())
-    {
-      int nargout1 = symbol_table::varval (".nargout.").int_value ();
+  if (symbol_table::at_top_level ())
+    error ("isargout: invalid call at top level");
+
+  int nargout1 = symbol_table::varval (".nargout.").int_value ();
 
-      Matrix ignored;
-      octave_value tmp = symbol_table::varval (".ignored.");
-      if (tmp.is_defined ())
-        ignored = tmp.matrix_value ();
-
-      if (args(0).is_scalar_type ())
-        {
-          double k = args(0).double_value ();
+  Matrix ignored;
+  octave_value tmp = symbol_table::varval (".ignored.");
+  if (tmp.is_defined ())
+    ignored = tmp.matrix_value ();
 
-          retval = isargout1 (nargout1, ignored, k);
-        }
-      else if (args(0).is_numeric_type ())
-        {
-          const NDArray ka = args(0).array_value ();
+  if (args(0).is_scalar_type ())
+    {
+      double k = args(0).double_value ();
 
-          boolNDArray r (ka.dims ());
-          for (octave_idx_type i = 0; i < ka.numel (); i++)
-            r(i) = isargout1 (nargout1, ignored, ka(i));
+      return ovl (isargout1 (nargout1, ignored, k));
+    }
+  else if (args(0).is_numeric_type ())
+    {
+      const NDArray ka = args(0).array_value ();
 
-          retval = r;
-        }
-      else
-        gripe_wrong_type_arg ("isargout", args(0));
+      boolNDArray r (ka.dims ());
+      for (octave_idx_type i = 0; i < ka.numel (); i++)
+        r(i) = isargout1 (nargout1, ignored, ka(i));
+
+      return ovl (r);
     }
   else
-    error ("isargout: invalid call at top level");
+    gripe_wrong_type_arg ("isargout", args(0));
 
-  return retval;
+  return octave_value_list ();
 }
 
 /*