diff libinterp/octave-value/ov-cell.cc @ 20979:0963ed389012

maint: invert if/else/error instances. * ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-cx-mat.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-perm.cc, ov-re-mat.cc, ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.cc: Invert if/else/error instances.
author John W. Eaton <jwe@octave.org>
date Thu, 24 Dec 2015 12:50:28 -0500
parents 3aa293be0e8d
children fc9cca99b2de
line wrap: on
line diff
--- a/libinterp/octave-value/ov-cell.cc	Thu Dec 24 12:06:27 2015 -0500
+++ b/libinterp/octave-value/ov-cell.cc	Thu Dec 24 12:50:28 2015 -0500
@@ -310,15 +310,13 @@
 
         case '.':
           {
-            if (is_empty ())
-              {
-                // Do nothing; the next branch will handle it.
-              }
-            else
+            if (! is_empty ())
               {
                 std::string nm = type_name ();
                 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
               }
+
+            // Do nothing; the next branch will handle it.
           }
           break;
 
@@ -380,22 +378,20 @@
 
     case '.':
       {
-        if (is_empty ())
-          {
-            // Allow conversion of empty cell array to some other
-            // type in cases like
-            //
-            //  x = {}; x.f = rhs
-
-            octave_value tmp = octave_value::empty_conv (type, rhs);
-
-            return tmp.subsasgn (type, idx, rhs);
-          }
-        else
+        if (! is_empty ())
           {
             std::string nm = type_name ();
             error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
           }
+
+        // Allow conversion of empty cell array to some other
+        // type in cases like
+        //
+        //  x = {}; x.f = rhs
+
+        octave_value tmp = octave_value::empty_conv (type, rhs);
+
+        return tmp.subsasgn (type, idx, rhs);
       }
       break;
 
@@ -781,86 +777,78 @@
     {
       int mdims = static_cast<int> (val);
 
-      if (mdims >= 0)
-        {
-          dim_vector dv;
-          dv.resize (mdims);
+      if (mdims < 0)
+        error ("load: failed to extract number of rows and columns");
 
-          for (int i = 0; i < mdims; i++)
-            is >> dv(i);
+      dim_vector dv;
+      dv.resize (mdims);
 
-          Cell tmp(dv);
+      for (int i = 0; i < mdims; i++)
+        is >> dv(i);
+
+      Cell tmp(dv);
 
-          for (octave_idx_type i = 0; i < dv.numel (); i++)
-            {
-              octave_value t2;
-              bool dummy;
-
-              // recurse to read cell elements
-              std::string nm = read_text_data (is, std::string (),
-                                                dummy, t2, i);
+      for (octave_idx_type i = 0; i < dv.numel (); i++)
+        {
+          octave_value t2;
+          bool dummy;
 
-              if (nm == CELL_ELT_TAG)
-                {
-                  if (is)
-                    tmp.elem (i) = t2;
-                }
-              else
-                error ("load: cell array element had unexpected name");
-            }
+          // recurse to read cell elements
+          std::string nm = read_text_data (is, std::string (),
+                                           dummy, t2, i);
+
+          if (nm != CELL_ELT_TAG)
+            error ("load: cell array element had unexpected name");
 
           if (is)
-            matrix = tmp;
-          else
-            error ("load: failed to load matrix constant");
+            tmp.elem (i) = t2;
         }
-      else
-        error ("load: failed to extract number of rows and columns");
+
+      if (! is)
+        error ("load: failed to load matrix constant");
+
+      matrix = tmp;
     }
   else if (kw == "rows")
     {
       octave_idx_type nr = val;
       octave_idx_type nc = 0;
 
-      if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0)
+      if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0)
+        error ("load: failed to extract number of rows and columns for cell array");
+
+      if (nr > 0 && nc > 0)
         {
-          if (nr > 0 && nc > 0)
+          Cell tmp (nr, nc);
+
+          for (octave_idx_type j = 0; j < nc; j++)
             {
-              Cell tmp (nr, nc);
-
-              for (octave_idx_type j = 0; j < nc; j++)
+              for (octave_idx_type i = 0; i < nr; i++)
                 {
-                  for (octave_idx_type i = 0; i < nr; i++)
-                    {
-                      octave_value t2;
-                      bool dummy;
+                  octave_value t2;
+                  bool dummy;
 
-                      // recurse to read cell elements
-                      std::string nm = read_text_data (is, std::string (),
-                                                        dummy, t2, i);
+                  // recurse to read cell elements
+                  std::string nm = read_text_data (is, std::string (),
+                                                   dummy, t2, i);
 
-                      if (nm == CELL_ELT_TAG)
-                        {
-                          if (is)
-                            tmp.elem (i, j) = t2;
-                        }
-                      else
-                        error ("load: cell array element had unexpected name");
-                    }
+                  if (nm != CELL_ELT_TAG)
+                    error ("load: cell array element had unexpected name");
+
+                  if (is)
+                    tmp.elem (i, j) = t2;
                 }
+            }
 
-              if (is)
-                matrix = tmp;
-              else
-                error ("load: failed to load cell element");
-            }
-          else if (nr == 0 || nc == 0)
-            matrix = Cell (nr, nc);
-          else
-            panic_impossible ();
+          if (! is)
+            error ("load: failed to load cell element");
+
+          matrix = tmp;
         }
+      else if (nr == 0 || nc == 0)
+        matrix = Cell (nr, nc);
       else
-        error ("load: failed to extract number of rows and columns for cell array");
+        panic_impossible ();
     }
   else
     panic_impossible ();
@@ -954,20 +942,18 @@
       std::string nm = read_binary_data (is, swap, fmt, std::string (),
                                          dummy, t2, doc);
 
-      if (nm == CELL_ELT_TAG)
-        {
-          if (is)
-            tmp.elem (i) = t2;
-        }
-      else
+      if (nm != CELL_ELT_TAG)
         error ("load: cell array element had unexpected name");
+
+      if (is)
+        tmp.elem (i) = t2;
     }
 
-  if (is)
-    matrix = tmp;
-  else
+  if (! is)
     error ("load: failed to load matrix constant");
 
+  matrix = tmp;
+
   return true;
 }