diff src/ov-bool-mat.cc @ 5099:f7e39f977fe8

[project @ 2004-12-24 19:06:01 by jwe]
author jwe
date Fri, 24 Dec 2004 19:06:01 +0000
parents 44046bbaa52c
children e35b034d3523
line wrap: on
line diff
--- a/src/ov-bool-mat.cc	Sat Dec 18 15:04:20 2004 +0000
+++ b/src/ov-bool-mat.cc	Fri Dec 24 19:06:01 2004 +0000
@@ -187,80 +187,93 @@
 bool 
 octave_bool_matrix::load_ascii (std::istream& is)
 {
-  int mdims = 0;
   bool success = true;
-  std::streampos pos = is.tellg ();
 
-  if (extract_keyword (is, "ndims", mdims, true))
-    {
-      if (mdims >= 0)
-	{
-	  dim_vector dv;
-	  dv.resize (mdims);
+  string_vector keywords (2);
 
-	  for (int i = 0; i < mdims; i++)
-	    is >> dv(i);
-
-	  NDArray tmp(dv);
-	  is >> tmp;
+  keywords[0] = "ndims";
+  keywords[1] = "rows";
 
-	  if (!is) 
-	    {
-	      error ("load: failed to load matrix constant");
-	      success = false;
-	    }
+  std::string kw;
+  int val = 0;
 
-	  boolNDArray btmp (dv);
-	  for (int i = 0; i < btmp.nelem (); i++)
-	      btmp.elem (i) = (tmp.elem (i) != 0.);
-	  
-	  matrix = btmp;
-	}
-      else
-	{
-	  error ("load: failed to extract number of rows and columns");
-	  success = false;
-	}
-    }
-  else
+  if (extract_keyword (is, keywords, kw, val, true))
     {
-      int nr = 0;
-      int nc = 0;
-
-      // re-read the same line again
-      is.clear ();
-      is.seekg (pos);
+      if (kw == "ndims")
+	{
+	  int mdims = val;
 
-      if (extract_keyword (is, "rows", nr) && nr >= 0
-	  && extract_keyword (is, "columns", nc) && nc >= 0)
-	{
-	  if (nr > 0 && nc > 0)
+	  if (mdims >= 0)
 	    {
-	      Matrix tmp (nr, nc);
+	      dim_vector dv;
+	      dv.resize (mdims);
+
+	      for (int i = 0; i < mdims; i++)
+		is >> dv(i);
+
+	      NDArray tmp(dv);
 	      is >> tmp;
-	      if (!is) 
+
+	      if (!is)
 		{
 		  error ("load: failed to load matrix constant");
 		  success = false;
 		}
 
-	      boolMatrix btmp (nr,nc);
-	      for (int j = 0; j < nc; j++)
-		for (int i = 0; i < nr; i++)
-		  btmp.elem (i,j) = (tmp.elem (i, j) != 0.);
-	      
+	      boolNDArray btmp (dv);
+	      for (int i = 0; i < btmp.nelem (); i++)
+		btmp.elem (i) = (tmp.elem (i) != 0.);
+
 	      matrix = btmp;
 	    }
-	  else if (nr == 0 || nc == 0)
-	    matrix = boolMatrix (nr, nc);
 	  else
-	    panic_impossible ();
+	    {
+	      error ("load: failed to extract number of rows and columns");
+	      success = false;
+	    }
 	}
-      else 
+      else if (kw == "rows")
 	{
-	  error ("load: failed to extract number of rows and columns");
-	  success = false;
+	  int nr = val;
+	  int nc = 0;
+
+	  if (nr >= 0 && extract_keyword (is, "columns", nc) && nc >= 0)
+	    {
+	      if (nr > 0 && nc > 0)
+		{
+		  Matrix tmp (nr, nc);
+		  is >> tmp;
+		  if (!is) 
+		    {
+		      error ("load: failed to load matrix constant");
+		      success = false;
+		    }
+
+		  boolMatrix btmp (nr,nc);
+		  for (int j = 0; j < nc; j++)
+		    for (int i = 0; i < nr; i++)
+		      btmp.elem (i,j) = (tmp.elem (i, j) != 0.);
+
+		  matrix = btmp;
+		}
+	      else if (nr == 0 || nc == 0)
+		matrix = boolMatrix (nr, nc);
+	      else
+		panic_impossible ();
+	    }
+	  else
+	    {
+	      error ("load: failed to extract number of rows and columns");
+	      success = false;
+	    }
 	}
+      else
+	panic_impossible ();
+    }
+  else
+    {
+      error ("load: failed to extract number of rows and columns");
+      success = false;
     }
 
   return success;