diff libinterp/octave-value/ov-class.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 5357423bca0a
children 77f5591878bf
line wrap: on
line diff
--- a/libinterp/octave-value/ov-class.cc	Fri Dec 18 16:22:53 2015 -0500
+++ b/libinterp/octave-value/ov-class.cc	Fri Dec 18 15:37:22 2015 -0800
@@ -1739,57 +1739,50 @@
 @seealso{typeinfo, isa}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   int nargin = args.length ();
 
   if (nargin == 0)
     print_usage ();
 
+  octave_value retval;
+
   if (nargin == 1)
     // Called for class of object
     retval = args(0).class_name ();
   else
     {
       // Called as class constructor
-      octave_function *fcn = octave_call_stack::caller ();
-
       std::string id = args(1).xstring_value ("class: ID (class name) must be a string");
 
-      if (fcn)
-        {
-          if (fcn->is_class_constructor (id) || fcn->is_class_method (id))
-            {
-              octave_map m = args(0).xmap_value ("class: S must be a valid structure");
+      octave_function *fcn = octave_call_stack::caller ();
+
+      if (! fcn)
+        error ("class: invalid call from outside class constructor or method");
 
-              if (nargin == 2)
-                retval
-                  = octave_value (new octave_class
-                                  (m, id, std::list<std::string> ()));
-              else
-                {
-                  octave_value_list parents = args.slice (2, nargin-2);
+      if (! fcn->is_class_constructor (id) && ! fcn->is_class_method (id))
+        error ("class: '%s' is invalid as a class name in this context",
+               id.c_str ());
+
+      octave_map m = args(0).xmap_value ("class: S must be a valid structure");
 
-                  retval
-                    = octave_value (new octave_class (m, id, parents));
-                }
-
-              octave_class::exemplar_const_iterator it
-                = octave_class::exemplar_map.find (id);
+      if (nargin == 2)
+        retval
+          = octave_value (new octave_class (m, id, std::list<std::string> ()));
+      else
+        {
+          octave_value_list parents = args.slice (2, nargin-2);
 
-              if (it == octave_class::exemplar_map.end ())
-                octave_class::exemplar_map[id]
-                  = octave_class::exemplar_info (retval);
-              else if (! it->second.compare (retval))
-                error ("class: object of class '%s' does not match previously constructed objects",
-                       id.c_str ());
-            }
-          else
-            error ("class: '%s' is invalid as a class name in this context",
-                   id.c_str ());
+          retval = octave_value (new octave_class (m, id, parents));
         }
-      else
-        error ("class: invalid call from outside class constructor or method");
+
+      octave_class::exemplar_const_iterator it
+        = octave_class::exemplar_map.find (id);
+
+      if (it == octave_class::exemplar_map.end ())
+        octave_class::exemplar_map[id] = octave_class::exemplar_info (retval);
+      else if (! it->second.compare (retval))
+        error ("class: object of class '%s' does not match previously constructed objects",
+               id.c_str ());
     }
 
   return retval;
@@ -1833,8 +1826,6 @@
 @seealso{class, typeinfo}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   if (args.length () != 2)
     print_usage ();
 
@@ -1843,6 +1834,7 @@
   Array<std::string> clsnames = args(1).xcellstr_value ("isa: CLASSNAME must be a string or cell array of strings");
 
   boolNDArray matches (clsnames.dims (), false);
+
   for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++)
     {
       std::string cls = clsnames(idx);
@@ -1853,7 +1845,8 @@
           || obj.is_instance_of (cls))
         matches(idx) = true;
     }
-  return octave_value (matches);
+
+  return ovl (matches);
 }
 
 /*
@@ -1922,17 +1915,15 @@
 Undocumented internal function.\n\
 @end deftypefn")
 {
-  octave_value retval = Cell ();
-
   if (args.length () != 1)
     print_usage ();
 
   octave_value arg = args(0);
 
   if (arg.is_object ())
-    retval = Cell (arg.parent_class_names ());
-
-  return retval;
+    return ovl (Cell (arg.parent_class_names ()));
+  else
+    return ovl (Cell ());
 }
 
 DEFUN (isobject, args, ,
@@ -1945,7 +1936,7 @@
   if (args.length () != 1)
     print_usage ();
 
-  return octave_value (args(0).is_object ());
+  return ovl (args(0).is_object ());
 }
 
 DEFUN (ismethod, args, ,
@@ -1957,8 +1948,6 @@
 @seealso{isprop, isobject}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   if (args.length () != 2)
     print_usage ();
 
@@ -1976,11 +1965,9 @@
   std::string method = args(1).string_value ();
 
   if (load_path::find_method (class_name, method) != std::string ())
-    retval = true;
+    return ovl (true);
   else
-    retval = false;
-
-  return retval;
+    return ovl (false);
 }
 
 DEFUN (__methods__, args, ,
@@ -1993,8 +1980,6 @@
 @seealso{methods}\n\
 @end deftypefn")
 {
-  octave_value retval;
-
   // Input validation has already been done in methods.m.
   octave_value arg = args(0);
 
@@ -2006,9 +1991,8 @@
     class_name = arg.string_value ();
 
   string_vector sv = load_path::methods (class_name);
-  retval = Cell (sv);
 
-  return retval;
+  return ovl (Cell (sv));
 }
 
 static bool
@@ -2050,7 +2034,7 @@
 @end deftypefn")
 {
   octave_function *fcn = octave_call_stack::caller ();
-  if ((! fcn) || (! fcn->is_class_constructor ()))
+  if (! fcn || ! fcn->is_class_constructor ())
     error ("superiorto: invalid call from outside class constructor");
 
   for (int i = 0; i < args.length (); i++)
@@ -2083,7 +2067,7 @@
 @end deftypefn")
 {
   octave_function *fcn = octave_call_stack::caller ();
-  if ((! fcn) || (! fcn->is_class_constructor ()))
+  if (! fcn || ! fcn->is_class_constructor ())
     error ("inferiorto: invalid call from outside class constructor");
 
   for (int i = 0; i < args.length (); i++)